perf tool: Add a global variable "const char *input_name"
RFC PATCH 1/1 perf tool: Add a global variable "const char *input_name"
Currently many perf ommands annotate/evlist/report/script/lock etc all support "-i" option to chose a specific perf data, and all of them create a local "input_name" to save the file name for that perf data.
So adding a global variable could unify all those local ones, and it will also be useful for other codes which need to know the file name.
--- tools/perf/builtin-annotate.c | 5 ++--- tools/perf/builtin-buildid-list.c | 1 - tools/perf/builtin-evlist.c | 5 ++--- tools/perf/builtin-inject.c | 3 +-- tools/perf/builtin-kmem.c | 2 -- tools/perf/builtin-lock.c | 2 -- tools/perf/builtin-report.c | 13 ++++++------- tools/perf/builtin-sched.c | 5 ++--- tools/perf/builtin-script.c | 2 -- tools/perf/builtin-timechart.c | 2 -- tools/perf/perf.c | 1 + tools/perf/perf.h | 1 + 12 files changed, 15 insertions(+), 27 deletions(-)
tools/perf/builtin-annotate.c +2 -3
@@ -33,7 +33,6 @@struct perf_annotate {struct perf_tool tool; -char const *input_name;bool force, use_tui, use_stdio;bool full_paths;bool print_line;
@@ -174,7 +173,7 @@ static int __cmd_annotate(struct perf_annotate *ann)struct perf_evsel *pos;u64 total_nr_samples; - session =perf_session__new (ann->input_name,O_RDONLY , + session =perf_session__new (input_name,O_RDONLY , ann->force, false, &ann->tool);if (session ==NULL )return -ENOMEM ;
@@ -252,7 +251,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) }, };const struct option options[] = { -OPT_STRING ('i' ,"input" , &annotate.input_name,"file" , +OPT_STRING ('i' ,"input" , &input_name,"file" ,"input file name" ),OPT_STRING ('d' ,"dsos" , &symbol_conf.dso_list_str,"dso[,dso...]" ,"only consider symbols in these dsos" ),
tools/perf/builtin-buildid-list.c +0 -1
@@ -16,7 +16,6 @@#include "util/session.h" #include "util/symbol.h" -static const char *input_name;static bool force;static bool show_kernel;static bool with_hits;
tools/perf/builtin-evlist.c +2 -3
@@ -48,12 +48,12 @@ static int __if_print(bool *first, const char *field, u64 value)#define if_print (field) __if_print(&first, #field, pos->attr.field) -static int __cmd_evlist (const char *input_name,struct perf_attr_details *details) +static int __cmd_evlist (const char *file_name,struct perf_attr_details *details) {struct perf_session *session;struct perf_evsel *pos; - session =perf_session__new (input_name,O_RDONLY ,0 , false,NULL ); + session =perf_session__new (file_name,O_RDONLY ,0 , false,NULL );if (session ==NULL )return -ENOMEM ;
@@ -116,7 +116,6 @@ static const char * const evlist_usage[] = {int cmd_evlist (int argc,const char **argv,const char *prefix__maybe_unused ) {struct perf_attr_details details = { .verbose = false, }; -const char *input_name =NULL ;const struct option options[] = {OPT_STRING ('i' ,"input" , &input_name,"file" ,"Input file name" ),
tools/perf/builtin-inject.c +1 -2
@@ -14,7 +14,6 @@#include "util/parse-options.h" -static char const *input_name ="-" ;static bool inject_build_ids; static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused,
@@ -245,7 +244,7 @@ static int __cmd_inject(void) perf_inject.tracing_data = perf_event__repipe_tracing_data; } - session =perf_session__new (input_name,O_RDONLY , false, true, &perf_inject); + session =perf_session__new ("-" ,O_RDONLY , false, true, &perf_inject);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-kmem.c +0 -2
@@ -20,8 +20,6 @@struct alloc_stat ;typedef int (*sort_fn_t )(struct alloc_stat *,struct alloc_stat *); -static const char *input_name; -static int alloc_flag;static int caller_flag;
tools/perf/builtin-lock.c +0 -2
@@ -334,8 +334,6 @@ alloc_failed:return NULL ; } -static const char *input_name; -struct raw_event_sample {u32 size;char data[0 ];
tools/perf/builtin-report.c +6 -7
@@ -39,7 +39,6 @@struct perf_report {struct perf_tool tool;struct perf_session *session; -char const *input_name;bool force, use_tui, use_gtk, use_stdio;bool hide_unresolved;bool dont_use_callchains;
@@ -570,7 +569,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) .pretty_printing_style = "normal", };const struct option options[] = { -OPT_STRING ('i' ,"input" , &report.input_name,"file" , +OPT_STRING ('i' ,"input" , &input_name,"file" ,"input file name" ),OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ),
@@ -656,13 +655,13 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)if (report.inverted_callchain) callchain_param.order =ORDER_CALLER ; -if (!report.input_name || !strlen (report.input_name)) { +if (!input_name || !strlen (input_name)) {if (!fstat (STDIN_FILENO , &st) &&S_ISFIFO (st.st_mode)) - report.input_name ="-" ; + input_name ="-" ;else - report.input_name ="perf.data" ; + input_name ="perf.data" ; } - session =perf_session__new (report.input_name,O_RDONLY , + session =perf_session__new (input_name,O_RDONLY , report.force, false, &report.tool);if (session ==NULL )return -ENOMEM ;
@@ -687,7 +686,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) } -if (strcmp (report.input_name,"-" ) !=0 ) +if (strcmp (input_name,"-" ) !=0 )setup_browser (true);else { use_browser =0 ;
tools/perf/builtin-sched.c +2 -3
@@ -120,7 +120,6 @@ struct trace_sched_handler {struct perf_sched {struct perf_tool tool; -const char *input_name;const char *sort_order;unsigned long nr_tasks;struct task_desc *pid_to_task[MAX_PID ];
@@ -1460,7 +1459,7 @@ static int perf_sched__read_events(struct perf_sched *sched, bool destroy, };struct perf_session *session; - session =perf_session__new (sched->input_name,O_RDONLY ,0 , false, &sched->tool); + session =perf_session__new (input_name,O_RDONLY ,0 , false, &sched->tool);if (session ==NULL ) {pr_debug ("No Memory for session\n" );return -1 ;
@@ -1707,7 +1706,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)OPT_END () };const struct option sched_options[] = { -OPT_STRING ('i' ,"input" , &sched.input_name,"file" , +OPT_STRING ('i' ,"input" , &input_name,"file" ,"input file name" ),OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ),
tools/perf/builtin-script.c +0 -2
@@ -473,8 +473,6 @@ static int cleanup_scripting(void)return scripting_ops->stop_script (); } -static const char *input_name; - static int process_sample_event(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample,
tools/perf/builtin-timechart.c +0 -2
@@ -37,8 +37,6 @@#define SUPPORT_OLD_POWER_EVENTS 1#define PWR_EVENT_EXIT -1 - -static const char *input_name;static const char *output_name ="output.svg" ;static unsigned int numcpus;
tools/perf/perf.c +1 -0
@@ -24,6 +24,7 @@ const char perf_more_info_string[] =int use_browser =-1 ;static int use_pager =-1 ; +const char *input_name;struct cmd_struct {const char *cmd;
tools/perf/perf.h +1 -0
@@ -202,6 +202,7 @@ struct branch_stack {struct branch_entry entries[0 ]; }; +extern const char *input_name;extern bool perf_host, perf_guest;extern const char perf_version_string[];
Signature · 1 line
1.7.1
Em Thu, Sep 20, 2012 at 10:19:39PM +0800, Feng Tang escreveu:
Quoted 7 lines
Currently many perf ommands annotate/evlist/report/script/lock etc all support "-i" option to chose a specific perf data, and all of them create a local "
input_name" to save the file name for that perf data.So adding a global variable could unify all those local ones, and it will also be useful for other codes which need to know the file name.
But I think the input_name should be passed as a parameter to whoever needs it. Think about 'perf diff', for instance, it deals with two perf.data files.
In general I think we should _remove_ more globals :-)
- Arnaldo
Quoted 6 lines · On Thu, 20 Sep 2012 12:05:51 -0300 Arnaldo Carvalho de Melo <[email protected]>…
Em Thu, Sep 20, 2012 at 10:19:39PM +0800, Feng Tang escreveu:
Quoted 5 lines
Currently many perf ommands annotate/evlist/report/script/lock etc all support "-i" option to chose a specific perf data, and all of them create a local "
input_name" to save the file name for that perf data.
Quoted 6 lines
Quoted 2 lines
So adding a global variable could unify all those local ones, and it will also be useful for other codes which need to know the file name.
But I think the
input_nameshould be passed as a parameter to whoever needs it. Think about 'perf diff', for instance, it deals with two perf.data files.
Yes, when I wrote the patch, I checked all "perf_session__new()" calls, and found "perf diff" uses the "input_new" and "input_old", so I thought it should be immune to this change :)
The reason I came up with this patch is, when I rewrote the script browser patch, I need to know this "input_name" to run script's report func on, but IIUC currently this info is only saved in struct perf_session, and in the browser stage (report/annotate), the perf_session is already phased out and I don't know how to get a reference for the perf_session to get the "input_name"
Quoted 2 lines
In general I think we should _remove_ more globals :-)
Understood.
Thanks,
Feng