Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] tools/power: intel_pstate_tracer: avoid optional imports for help
@ 2026-06-24 12:27 Yousef Alhouseen
  2026-07-08 23:33 ` srinivas pandruvada
  0 siblings, 1 reply; 2+ messages in thread
From: Yousef Alhouseen @ 2026-06-24 12:27 UTC (permalink / raw)
  To: Srinivas Pandruvada, Len Brown
  Cc: Rafael J . Wysocki, linux-pm, linux-kernel, Yousef Alhouseen

intel_pstate_tracer imports Gnuplot and numpy before parsing command-line
options. As a result, even "-h" fails if those optional runtime modules are
not installed.

Move the imports to the paths that need them. This lets the help and
invalid-argument paths describe usage without requiring plotting/data
dependencies. While there, fix a typo in the help text and matching
comments.

Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
---
 .../intel_pstate_tracer/intel_pstate_tracer.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 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 38cfbdcde..64001bc80 100755
--- a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
+++ b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
@@ -32,8 +32,6 @@ import re
 import signal
 import sys
 import getopt
-import Gnuplot
-from numpy import *
 from decimal import *
 
 __author__ = "Srinivas Pandruvada"
@@ -88,8 +86,8 @@ def print_help(driver_name):
     print('      kbytes: Kilo bytes of memory per CPU to allocate to the trace buffer. Default: 10240')
     print('  Output:')
     print('    If not already present, creates a "results/test_name" folder in the current working directory with:')
-    print('      cpu.csv - comma seperated values file with trace contents and some additional calculations.')
-    print('      cpu???.csv - comma seperated values file for CPU number ???.')
+    print('      cpu.csv - comma separated values file with trace contents and some additional calculations.')
+    print('      cpu???.csv - comma separated values file for CPU number ???.')
     print('      *.png - a variety of PNG format plot files created from the trace contents and the additional calculations.')
     print('  Notes:')
     print('    Avoid the use of _ (underscore) in test names, because in gnuplot it is a subscript directive.')
@@ -295,6 +293,8 @@ def common_all_gnuplot_settings(output_png):
 def common_gnuplot_settings():
     """ common gnuplot settings. """
 
+    import Gnuplot
+
     g_plot = Gnuplot.Gnuplot(persist=1)
 #   The following line is for rigor only. It seems to be assumed for .csv files
     g_plot('set datafile separator \",\"')
@@ -343,7 +343,7 @@ def store_csv(cpu_int, time_pre_dec, time_post_dec, core_busy, scaled, _from, _t
     graph_data_present = True;
 
 def split_csv(current_max_cpu, cpu_mask):
-    """ seperate the all csv file into per CPU csv files. """
+    """ separate the main csv file into per CPU csv files. """
 
     if os.path.exists('cpu.csv'):
         for index in range(0, current_max_cpu + 1):
@@ -482,7 +482,7 @@ def read_trace_data(filename, cpu_mask):
             if cpu_int > current_max_cpu:
                 current_max_cpu = cpu_int
 # End of for each trace line loop
-# Now seperate the main overall csv file into per CPU csv files.
+# Now separate the main overall csv file into per CPU csv files.
     split_csv(current_max_cpu, cpu_mask)
 
 def signal_handler(signal, frame):
@@ -508,8 +508,6 @@ if __name__ == "__main__":
     valid1 = False
     valid2 = False
 
-    cpu_mask = zeros((MAX_CPUS,), dtype=int)
-
     try:
         opts, args = getopt.getopt(sys.argv[1:],"ht:i:c:n:m:",["help","trace_file=","interval=","cpu=","name=","memory="])
     except getopt.GetoptError:
@@ -538,6 +536,10 @@ if __name__ == "__main__":
         print_help('intel_pstate')
         sys.exit()
 
+    from numpy import zeros
+
+    cpu_mask = zeros((MAX_CPUS,), dtype=int)
+
     if cpu_list:
         for p in re.split("[,]", cpu_list):
             if int(p) < MAX_CPUS :
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-08 23:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 12:27 [PATCH] tools/power: intel_pstate_tracer: avoid optional imports for help Yousef Alhouseen
2026-07-08 23:33 ` srinivas pandruvada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox