aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Smythies <doug.smythies@gmail.com>2017-04-17 20:12:13 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-04-18 20:47:28 -0400
commit010a522cf2d9a01612b8a95abd787e70ae123ea6 (patch)
tree8a97fd6c13b6febb983e7a97635a83dde3b672b4
parent4f7d029b9bf009fbee76bb10c0c4351a1870d2f3 (diff)
tools/power/x86/intel_pstate_tracer: Adjust directory ownership
The intel_pstate_tracer.py script only needs to be run as root when it is also used to actually acquire the trace data that it will post process. Otherwise it is generally preferable that it be run as a regular user. If run the first time as root the results directory will be incorrect for any subsequent run as a regular user. For any run as root the specific testname subdirectory will not allow any subsequent file saves by a regular user. Typically, and for example, the regular user might be attempting to save a .csv file converted to a spreadsheet with added calculations or graphs. Set the directories and files owner and groups IDs to be the regular user, if required. Signed-off-by: Doug Smythies <dsmythies@telus.net> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rwxr-xr-xtools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
index fd706ac0f347..0b24dd9d01ff 100755
--- a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
+++ b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
@@ -353,6 +353,14 @@ def split_csv():
353 os.system('grep -m 1 common_cpu cpu.csv > cpu{:0>3}.csv'.format(index)) 353 os.system('grep -m 1 common_cpu cpu.csv > cpu{:0>3}.csv'.format(index))
354 os.system('grep CPU_{:0>3} cpu.csv >> cpu{:0>3}.csv'.format(index, index)) 354 os.system('grep CPU_{:0>3} cpu.csv >> cpu{:0>3}.csv'.format(index, index))
355 355
356def fix_ownership(path):
357 """Change the owner of the file to SUDO_UID, if required"""
358
359 uid = os.environ.get('SUDO_UID')
360 gid = os.environ.get('SUDO_GID')
361 if uid is not None:
362 os.chown(path, int(uid), int(gid))
363
356def cleanup_data_files(): 364def cleanup_data_files():
357 """ clean up existing data files """ 365 """ clean up existing data files """
358 366
@@ -518,12 +526,16 @@ else:
518 526
519if not os.path.exists('results'): 527if not os.path.exists('results'):
520 os.mkdir('results') 528 os.mkdir('results')
529 # The regular user needs to own the directory, not root.
530 fix_ownership('results')
521 531
522os.chdir('results') 532os.chdir('results')
523if os.path.exists(testname): 533if os.path.exists(testname):
524 print('The test name directory already exists. Please provide a unique test name. Test re-run not supported, yet.') 534 print('The test name directory already exists. Please provide a unique test name. Test re-run not supported, yet.')
525 sys.exit() 535 sys.exit()
526os.mkdir(testname) 536os.mkdir(testname)
537# The regular user needs to own the directory, not root.
538fix_ownership(testname)
527os.chdir(testname) 539os.chdir(testname)
528 540
529# Temporary (or perhaps not) 541# Temporary (or perhaps not)
@@ -566,4 +578,9 @@ plot_scaled_cpu()
566plot_boost_cpu() 578plot_boost_cpu()
567plot_ghz_cpu() 579plot_ghz_cpu()
568 580
581# It is preferrable, but not necessary, that the regular user owns the files, not root.
582for root, dirs, files in os.walk('.'):
583 for f in files:
584 fix_ownership(f)
585
569os.chdir('../../') 586os.chdir('../../')