aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-stat.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index dde9e17c018b..1ca767d906ef 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -175,22 +175,19 @@ static struct perf_event_attr very_very_detailed_attrs[] = {
175 175
176static struct perf_evlist *evsel_list; 176static struct perf_evlist *evsel_list;
177 177
178static bool system_wide = false; 178static struct perf_target target;
179static int run_idx = 0;
180 179
180static int run_idx = 0;
181static int run_count = 1; 181static int run_count = 1;
182static bool no_inherit = false; 182static bool no_inherit = false;
183static bool scale = true; 183static bool scale = true;
184static bool no_aggr = false; 184static bool no_aggr = false;
185static const char *target_pid;
186static const char *target_tid;
187static pid_t child_pid = -1; 185static pid_t child_pid = -1;
188static bool null_run = false; 186static bool null_run = false;
189static int detailed_run = 0; 187static int detailed_run = 0;
190static bool sync_run = false; 188static bool sync_run = false;
191static bool big_num = true; 189static bool big_num = true;
192static int big_num_opt = -1; 190static int big_num_opt = -1;
193static const char *cpu_list;
194static const char *csv_sep = NULL; 191static const char *csv_sep = NULL;
195static bool csv_output = false; 192static bool csv_output = false;
196static bool group = false; 193static bool group = false;
@@ -293,10 +290,10 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
293 290
294 attr->inherit = !no_inherit; 291 attr->inherit = !no_inherit;
295 292
296 if (system_wide) 293 if (target.system_wide)
297 return perf_evsel__open_per_cpu(evsel, evsel_list->cpus, 294 return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
298 group, group_fd); 295 group, group_fd);
299 if (!target_pid && !target_tid && (!group || evsel == first)) { 296 if (!target.pid && !target.tid && (!group || evsel == first)) {
300 attr->disabled = 1; 297 attr->disabled = 1;
301 attr->enable_on_exec = 1; 298 attr->enable_on_exec = 1;
302 } 299 }
@@ -446,7 +443,7 @@ static int run_perf_stat(int argc __used, const char **argv)
446 exit(-1); 443 exit(-1);
447 } 444 }
448 445
449 if (!target_tid && !target_pid && !system_wide) 446 if (!target.tid && !target.pid && !target.system_wide)
450 evsel_list->threads->map[0] = child_pid; 447 evsel_list->threads->map[0] = child_pid;
451 448
452 /* 449 /*
@@ -476,7 +473,7 @@ static int run_perf_stat(int argc __used, const char **argv)
476 error("You may not have permission to collect %sstats.\n" 473 error("You may not have permission to collect %sstats.\n"
477 "\t Consider tweaking" 474 "\t Consider tweaking"
478 " /proc/sys/kernel/perf_event_paranoid or running as root.", 475 " /proc/sys/kernel/perf_event_paranoid or running as root.",
479 system_wide ? "system-wide " : ""); 476 target.system_wide ? "system-wide " : "");
480 } else { 477 } else {
481 error("open_counter returned with %d (%s). " 478 error("open_counter returned with %d (%s). "
482 "/bin/dmesg may provide additional information.\n", 479 "/bin/dmesg may provide additional information.\n",
@@ -968,14 +965,14 @@ static void print_stat(int argc, const char **argv)
968 if (!csv_output) { 965 if (!csv_output) {
969 fprintf(output, "\n"); 966 fprintf(output, "\n");
970 fprintf(output, " Performance counter stats for "); 967 fprintf(output, " Performance counter stats for ");
971 if (!target_pid && !target_tid) { 968 if (!target.pid && !target.tid) {
972 fprintf(output, "\'%s", argv[0]); 969 fprintf(output, "\'%s", argv[0]);
973 for (i = 1; i < argc; i++) 970 for (i = 1; i < argc; i++)
974 fprintf(output, " %s", argv[i]); 971 fprintf(output, " %s", argv[i]);
975 } else if (target_pid) 972 } else if (target.pid)
976 fprintf(output, "process id \'%s", target_pid); 973 fprintf(output, "process id \'%s", target.pid);
977 else 974 else
978 fprintf(output, "thread id \'%s", target_tid); 975 fprintf(output, "thread id \'%s", target.tid);
979 976
980 fprintf(output, "\'"); 977 fprintf(output, "\'");
981 if (run_count > 1) 978 if (run_count > 1)
@@ -1049,11 +1046,11 @@ static const struct option options[] = {
1049 "event filter", parse_filter), 1046 "event filter", parse_filter),
1050 OPT_BOOLEAN('i', "no-inherit", &no_inherit, 1047 OPT_BOOLEAN('i', "no-inherit", &no_inherit,
1051 "child tasks do not inherit counters"), 1048 "child tasks do not inherit counters"),
1052 OPT_STRING('p', "pid", &target_pid, "pid", 1049 OPT_STRING('p', "pid", &target.pid, "pid",
1053 "stat events on existing process id"), 1050 "stat events on existing process id"),
1054 OPT_STRING('t', "tid", &target_tid, "tid", 1051 OPT_STRING('t', "tid", &target.tid, "tid",
1055 "stat events on existing thread id"), 1052 "stat events on existing thread id"),
1056 OPT_BOOLEAN('a', "all-cpus", &system_wide, 1053 OPT_BOOLEAN('a', "all-cpus", &target.system_wide,
1057 "system-wide collection from all CPUs"), 1054 "system-wide collection from all CPUs"),
1058 OPT_BOOLEAN('g', "group", &group, 1055 OPT_BOOLEAN('g', "group", &group,
1059 "put the counters into a counter group"), 1056 "put the counters into a counter group"),
@@ -1072,7 +1069,7 @@ static const struct option options[] = {
1072 OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, 1069 OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL,
1073 "print large numbers with thousands\' separators", 1070 "print large numbers with thousands\' separators",
1074 stat__set_big_num), 1071 stat__set_big_num),
1075 OPT_STRING('C', "cpu", &cpu_list, "cpu", 1072 OPT_STRING('C', "cpu", &target.cpu_list, "cpu",
1076 "list of cpus to monitor in system-wide"), 1073 "list of cpus to monitor in system-wide"),
1077 OPT_BOOLEAN('A', "no-aggr", &no_aggr, 1074 OPT_BOOLEAN('A', "no-aggr", &no_aggr,
1078 "disable CPU count aggregation"), 1075 "disable CPU count aggregation"),
@@ -1190,13 +1187,13 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
1190 } else if (big_num_opt == 0) /* User passed --no-big-num */ 1187 } else if (big_num_opt == 0) /* User passed --no-big-num */
1191 big_num = false; 1188 big_num = false;
1192 1189
1193 if (!argc && !target_pid && !target_tid) 1190 if (!argc && !target.pid && !target.tid)
1194 usage_with_options(stat_usage, options); 1191 usage_with_options(stat_usage, options);
1195 if (run_count <= 0) 1192 if (run_count <= 0)
1196 usage_with_options(stat_usage, options); 1193 usage_with_options(stat_usage, options);
1197 1194
1198 /* no_aggr, cgroup are for system-wide only */ 1195 /* no_aggr, cgroup are for system-wide only */
1199 if ((no_aggr || nr_cgroups) && !system_wide) { 1196 if ((no_aggr || nr_cgroups) && !target.system_wide) {
1200 fprintf(stderr, "both cgroup and no-aggregation " 1197 fprintf(stderr, "both cgroup and no-aggregation "
1201 "modes only available in system-wide mode\n"); 1198 "modes only available in system-wide mode\n");
1202 1199
@@ -1206,18 +1203,18 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
1206 if (add_default_attributes()) 1203 if (add_default_attributes())
1207 goto out; 1204 goto out;
1208 1205
1209 if (target_pid) 1206 if (target.pid)
1210 target_tid = target_pid; 1207 target.tid = target.pid;
1211 1208
1212 evsel_list->threads = thread_map__new_str(target_pid, 1209 evsel_list->threads = thread_map__new_str(target.pid,
1213 target_tid, UINT_MAX); 1210 target.tid, UINT_MAX);
1214 if (evsel_list->threads == NULL) { 1211 if (evsel_list->threads == NULL) {
1215 pr_err("Problems finding threads of monitor\n"); 1212 pr_err("Problems finding threads of monitor\n");
1216 usage_with_options(stat_usage, options); 1213 usage_with_options(stat_usage, options);
1217 } 1214 }
1218 1215
1219 if (system_wide) 1216 if (target.system_wide)
1220 evsel_list->cpus = cpu_map__new(cpu_list); 1217 evsel_list->cpus = cpu_map__new(target.cpu_list);
1221 else 1218 else
1222 evsel_list->cpus = cpu_map__dummy_new(); 1219 evsel_list->cpus = cpu_map__dummy_new();
1223 1220