Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf script: Implement option for system-wide profiling

The option is documented in man perf-script but was not yet implemented:

-a
Force system-wide collection. Scripts run without a
<command> normally use -a by default, while scripts run
with a <command> normally don't - this option allows the
latter to be run in system-wide mode.

As with perf record you now can profile in system-wide mode for the
runtime of a given command, e.g.:

# perf script -a syscall-counts sleep 2

Cc: Ingo Molnar <mingo@elte.hu>
Link: http://lkml.kernel.org/r/1322229925-10075-1-git-send-email-robert.richter@amd.com
Signed-off-by: Robert Richter <robert.richter@amd.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Robert Richter and committed by
Arnaldo Carvalho de Melo
317df650 38efb539

+10 -5
+10 -5
tools/perf/builtin-script.c
··· 24 24 extern const struct option record_options[]; 25 25 static bool no_callchain; 26 26 static bool show_full_info; 27 + static bool system_wide; 27 28 static const char *cpu_list; 28 29 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 29 30 ··· 1106 1105 OPT_CALLBACK('f', "fields", NULL, "str", 1107 1106 "comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr", 1108 1107 parse_output_fields), 1108 + OPT_BOOLEAN('a', "all-cpus", &system_wide, 1109 + "system-wide collection from all CPUs"), 1109 1110 OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), 1110 1111 OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", 1111 1112 "only display events for these comms"), ··· 1137 1134 struct perf_session *session; 1138 1135 char *script_path = NULL; 1139 1136 const char **__argv; 1140 - bool system_wide; 1141 1137 int i, j, err; 1142 1138 1143 1139 setup_scripting(); ··· 1204 1202 } 1205 1203 1206 1204 if (!pid) { 1207 - system_wide = true; 1208 1205 j = 0; 1209 1206 1210 1207 dup2(live_pipe[1], 1); 1211 1208 close(live_pipe[0]); 1212 1209 1213 - if (!is_top_script(argv[0])) 1210 + if (is_top_script(argv[0])) { 1211 + system_wide = true; 1212 + } else if (!system_wide) { 1214 1213 system_wide = !have_cmd(argc - rep_args, 1215 1214 &argv[rep_args]); 1215 + } 1216 1216 1217 1217 __argv = malloc((argc + 6) * sizeof(const char *)); 1218 1218 if (!__argv) ··· 1262 1258 script_path = rep_script_path; 1263 1259 1264 1260 if (script_path) { 1265 - system_wide = false; 1266 1261 j = 0; 1267 1262 1268 - if (rec_script_path) 1263 + if (!rec_script_path) 1264 + system_wide = false; 1265 + else if (!system_wide) 1269 1266 system_wide = !have_cmd(argc - 1, &argv[1]); 1270 1267 1271 1268 __argv = malloc((argc + 2) * sizeof(const char *));