diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-01 14:20:58 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-02 17:36:30 -0400 |
commit | 69b6470e9ef3f6ea72b7e46e140d85970d8e1bc8 (patch) | |
tree | 906e8ca89e818cfdaf1194fedc01266c9cd08f3f /tools/perf | |
parent | b070a547fda009bdb840b90aab7274be9e41de4d (diff) |
perf script: Don't use globals where not needed to
Some variables were global but used in just one function, so move it to
where it belongs.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-eukt8bzp4t2n2z3s8ue5ofwb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-script.c | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 1be843aa1546..fb9625083a2e 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -24,7 +24,6 @@ static u64 last_timestamp; | |||
24 | static u64 nr_unordered; | 24 | static u64 nr_unordered; |
25 | extern const struct option record_options[]; | 25 | extern const struct option record_options[]; |
26 | static bool no_callchain; | 26 | static bool no_callchain; |
27 | static bool show_full_info; | ||
28 | static bool system_wide; | 27 | static bool system_wide; |
29 | static const char *cpu_list; | 28 | static const char *cpu_list; |
30 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); | 29 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
@@ -473,8 +472,6 @@ static int cleanup_scripting(void) | |||
473 | return scripting_ops->stop_script(); | 472 | return scripting_ops->stop_script(); |
474 | } | 473 | } |
475 | 474 | ||
476 | static const char *input_name; | ||
477 | |||
478 | static int process_sample_event(struct perf_tool *tool __maybe_unused, | 475 | static int process_sample_event(struct perf_tool *tool __maybe_unused, |
479 | union perf_event *event, | 476 | union perf_event *event, |
480 | struct perf_sample *sample, | 477 | struct perf_sample *sample, |
@@ -1156,20 +1153,40 @@ out: | |||
1156 | return n_args; | 1153 | return n_args; |
1157 | } | 1154 | } |
1158 | 1155 | ||
1159 | static const char * const script_usage[] = { | 1156 | static int have_cmd(int argc, const char **argv) |
1160 | "perf script [<options>]", | 1157 | { |
1161 | "perf script [<options>] record <script> [<record-options>] <command>", | 1158 | char **__argv = malloc(sizeof(const char *) * argc); |
1162 | "perf script [<options>] report <script> [script-args]", | 1159 | |
1163 | "perf script [<options>] <script> [<record-options>] <command>", | 1160 | if (!__argv) { |
1164 | "perf script [<options>] <top-script> [script-args]", | 1161 | pr_err("malloc failed\n"); |
1165 | NULL | 1162 | return -1; |
1166 | }; | 1163 | } |
1164 | |||
1165 | memcpy(__argv, argv, sizeof(const char *) * argc); | ||
1166 | argc = parse_options(argc, (const char **)__argv, record_options, | ||
1167 | NULL, PARSE_OPT_STOP_AT_NON_OPTION); | ||
1168 | free(__argv); | ||
1167 | 1169 | ||
1168 | static const struct option options[] = { | 1170 | system_wide = (argc == 0); |
1171 | |||
1172 | return 0; | ||
1173 | } | ||
1174 | |||
1175 | int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | ||
1176 | { | ||
1177 | bool show_full_info = false; | ||
1178 | const char *input_name = NULL; | ||
1179 | char *rec_script_path = NULL; | ||
1180 | char *rep_script_path = NULL; | ||
1181 | struct perf_session *session; | ||
1182 | char *script_path = NULL; | ||
1183 | const char **__argv; | ||
1184 | int i, j, err; | ||
1185 | const struct option options[] = { | ||
1169 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 1186 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1170 | "dump raw trace in ASCII"), | 1187 | "dump raw trace in ASCII"), |
1171 | OPT_INCR('v', "verbose", &verbose, | 1188 | OPT_INCR('v', "verbose", &verbose, |
1172 | "be more verbose (show symbol address, etc)"), | 1189 | "be more verbose (show symbol address, etc)"), |
1173 | OPT_BOOLEAN('L', "Latency", &latency_format, | 1190 | OPT_BOOLEAN('L', "Latency", &latency_format, |
1174 | "show latency attributes (irqs/preemption disabled, etc)"), | 1191 | "show latency attributes (irqs/preemption disabled, etc)"), |
1175 | OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts", | 1192 | OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts", |
@@ -1179,8 +1196,7 @@ static const struct option options[] = { | |||
1179 | parse_scriptname), | 1196 | parse_scriptname), |
1180 | OPT_STRING('g', "gen-script", &generate_script_lang, "lang", | 1197 | OPT_STRING('g', "gen-script", &generate_script_lang, "lang", |
1181 | "generate perf-script.xx script in specified language"), | 1198 | "generate perf-script.xx script in specified language"), |
1182 | OPT_STRING('i', "input", &input_name, "file", | 1199 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
1183 | "input file name"), | ||
1184 | OPT_BOOLEAN('d', "debug-mode", &debug_mode, | 1200 | OPT_BOOLEAN('d', "debug-mode", &debug_mode, |
1185 | "do various checks like samples ordering and lost events"), | 1201 | "do various checks like samples ordering and lost events"), |
1186 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | 1202 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
@@ -1195,10 +1211,9 @@ static const struct option options[] = { | |||
1195 | "comma separated output fields prepend with 'type:'. " | 1211 | "comma separated output fields prepend with 'type:'. " |
1196 | "Valid types: hw,sw,trace,raw. " | 1212 | "Valid types: hw,sw,trace,raw. " |
1197 | "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," | 1213 | "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," |
1198 | "addr,symoff", | 1214 | "addr,symoff", parse_output_fields), |
1199 | parse_output_fields), | ||
1200 | OPT_BOOLEAN('a', "all-cpus", &system_wide, | 1215 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
1201 | "system-wide collection from all CPUs"), | 1216 | "system-wide collection from all CPUs"), |
1202 | OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", | 1217 | OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", |
1203 | "only consider these symbols"), | 1218 | "only consider these symbols"), |
1204 | OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), | 1219 | OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), |
@@ -1208,37 +1223,16 @@ static const struct option options[] = { | |||
1208 | "display extended information from perf.data file"), | 1223 | "display extended information from perf.data file"), |
1209 | OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, | 1224 | OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, |
1210 | "Show the path of [kernel.kallsyms]"), | 1225 | "Show the path of [kernel.kallsyms]"), |
1211 | |||
1212 | OPT_END() | 1226 | OPT_END() |
1213 | }; | 1227 | }; |
1214 | 1228 | const char * const script_usage[] = { | |
1215 | static int have_cmd(int argc, const char **argv) | 1229 | "perf script [<options>]", |
1216 | { | 1230 | "perf script [<options>] record <script> [<record-options>] <command>", |
1217 | char **__argv = malloc(sizeof(const char *) * argc); | 1231 | "perf script [<options>] report <script> [script-args]", |
1218 | 1232 | "perf script [<options>] <script> [<record-options>] <command>", | |
1219 | if (!__argv) { | 1233 | "perf script [<options>] <top-script> [script-args]", |
1220 | pr_err("malloc failed\n"); | 1234 | NULL |
1221 | return -1; | 1235 | }; |
1222 | } | ||
1223 | |||
1224 | memcpy(__argv, argv, sizeof(const char *) * argc); | ||
1225 | argc = parse_options(argc, (const char **)__argv, record_options, | ||
1226 | NULL, PARSE_OPT_STOP_AT_NON_OPTION); | ||
1227 | free(__argv); | ||
1228 | |||
1229 | system_wide = (argc == 0); | ||
1230 | |||
1231 | return 0; | ||
1232 | } | ||
1233 | |||
1234 | int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | ||
1235 | { | ||
1236 | char *rec_script_path = NULL; | ||
1237 | char *rep_script_path = NULL; | ||
1238 | struct perf_session *session; | ||
1239 | char *script_path = NULL; | ||
1240 | const char **__argv; | ||
1241 | int i, j, err; | ||
1242 | 1236 | ||
1243 | setup_scripting(); | 1237 | setup_scripting(); |
1244 | 1238 | ||