Re: [PATCH] tools/power: intel_pstate_tracer: avoid optional imports for help

From: Rafael J. Wysocki (Intel)

Date: Wed Jul 22 2026 - 12:37:20 EST


On Thu, Jul 9, 2026 at 1:33 AM srinivas pandruvada
<srinivas.pandruvada@xxxxxxxxxxxxxxx> wrote:
>
> On Wed, 2026-06-24 at 14:27 +0200, Yousef Alhouseen wrote:
> > 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@xxxxxxxxx>
>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>

Applied as 7.3 material, thanks!

> > ---
> > .../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=","inter
> > val=","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 :