diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-11-05 09:40:45 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-11-05 15:54:34 -0500 |
commit | e0547311133159bf95f7998726e4e4932d78d8ce (patch) | |
tree | c3a3d2767024656e44e97a835080725b2c694779 | |
parent | 0014de172d228e450377d1fd079d94e67128d27f (diff) |
perf stat: Make stat options global
So they can be used in perf stat record command in following patch.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Kan Liang <kan.liang@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1446734469-11352-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-stat.c | 163 |
1 files changed, 82 insertions, 81 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b74ee0f2e714..e77880b5094d 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -122,6 +122,9 @@ static bool forever = false; | |||
122 | static struct timespec ref_time; | 122 | static struct timespec ref_time; |
123 | static struct cpu_map *aggr_map; | 123 | static struct cpu_map *aggr_map; |
124 | static aggr_get_id_t aggr_get_id; | 124 | static aggr_get_id_t aggr_get_id; |
125 | static bool append_file; | ||
126 | static const char *output_name; | ||
127 | static int output_fd; | ||
125 | 128 | ||
126 | static volatile int done = 0; | 129 | static volatile int done = 0; |
127 | 130 | ||
@@ -927,6 +930,67 @@ static int stat__set_big_num(const struct option *opt __maybe_unused, | |||
927 | return 0; | 930 | return 0; |
928 | } | 931 | } |
929 | 932 | ||
933 | static const struct option stat_options[] = { | ||
934 | OPT_BOOLEAN('T', "transaction", &transaction_run, | ||
935 | "hardware transaction statistics"), | ||
936 | OPT_CALLBACK('e', "event", &evsel_list, "event", | ||
937 | "event selector. use 'perf list' to list available events", | ||
938 | parse_events_option), | ||
939 | OPT_CALLBACK(0, "filter", &evsel_list, "filter", | ||
940 | "event filter", parse_filter), | ||
941 | OPT_BOOLEAN('i', "no-inherit", &no_inherit, | ||
942 | "child tasks do not inherit counters"), | ||
943 | OPT_STRING('p', "pid", &target.pid, "pid", | ||
944 | "stat events on existing process id"), | ||
945 | OPT_STRING('t', "tid", &target.tid, "tid", | ||
946 | "stat events on existing thread id"), | ||
947 | OPT_BOOLEAN('a', "all-cpus", &target.system_wide, | ||
948 | "system-wide collection from all CPUs"), | ||
949 | OPT_BOOLEAN('g', "group", &group, | ||
950 | "put the counters into a counter group"), | ||
951 | OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), | ||
952 | OPT_INCR('v', "verbose", &verbose, | ||
953 | "be more verbose (show counter open errors, etc)"), | ||
954 | OPT_INTEGER('r', "repeat", &run_count, | ||
955 | "repeat command and print average + stddev (max: 100, forever: 0)"), | ||
956 | OPT_BOOLEAN('n', "null", &null_run, | ||
957 | "null run - dont start any counters"), | ||
958 | OPT_INCR('d', "detailed", &detailed_run, | ||
959 | "detailed run - start a lot of events"), | ||
960 | OPT_BOOLEAN('S', "sync", &sync_run, | ||
961 | "call sync() before starting a run"), | ||
962 | OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, | ||
963 | "print large numbers with thousands\' separators", | ||
964 | stat__set_big_num), | ||
965 | OPT_STRING('C', "cpu", &target.cpu_list, "cpu", | ||
966 | "list of cpus to monitor in system-wide"), | ||
967 | OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, | ||
968 | "disable CPU count aggregation", AGGR_NONE), | ||
969 | OPT_STRING('x', "field-separator", &csv_sep, "separator", | ||
970 | "print counts with custom separator"), | ||
971 | OPT_CALLBACK('G', "cgroup", &evsel_list, "name", | ||
972 | "monitor event in cgroup name only", parse_cgroups), | ||
973 | OPT_STRING('o', "output", &output_name, "file", "output file name"), | ||
974 | OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), | ||
975 | OPT_INTEGER(0, "log-fd", &output_fd, | ||
976 | "log output to fd, instead of stderr"), | ||
977 | OPT_STRING(0, "pre", &pre_cmd, "command", | ||
978 | "command to run prior to the measured command"), | ||
979 | OPT_STRING(0, "post", &post_cmd, "command", | ||
980 | "command to run after to the measured command"), | ||
981 | OPT_UINTEGER('I', "interval-print", &stat_config.interval, | ||
982 | "print counts at regular interval in ms (>= 10)"), | ||
983 | OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, | ||
984 | "aggregate counts per processor socket", AGGR_SOCKET), | ||
985 | OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, | ||
986 | "aggregate counts per physical processor core", AGGR_CORE), | ||
987 | OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, | ||
988 | "aggregate counts per thread", AGGR_THREAD), | ||
989 | OPT_UINTEGER('D', "delay", &initial_delay, | ||
990 | "ms to wait before starting measurement after program start"), | ||
991 | OPT_END() | ||
992 | }; | ||
993 | |||
930 | static int perf_stat__get_socket(struct cpu_map *map, int cpu) | 994 | static int perf_stat__get_socket(struct cpu_map *map, int cpu) |
931 | { | 995 | { |
932 | return cpu_map__get_socket(map, cpu, NULL); | 996 | return cpu_map__get_socket(map, cpu, NULL); |
@@ -1174,69 +1238,6 @@ static int add_default_attributes(void) | |||
1174 | 1238 | ||
1175 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | 1239 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) |
1176 | { | 1240 | { |
1177 | bool append_file = false; | ||
1178 | int output_fd = 0; | ||
1179 | const char *output_name = NULL; | ||
1180 | const struct option options[] = { | ||
1181 | OPT_BOOLEAN('T', "transaction", &transaction_run, | ||
1182 | "hardware transaction statistics"), | ||
1183 | OPT_CALLBACK('e', "event", &evsel_list, "event", | ||
1184 | "event selector. use 'perf list' to list available events", | ||
1185 | parse_events_option), | ||
1186 | OPT_CALLBACK(0, "filter", &evsel_list, "filter", | ||
1187 | "event filter", parse_filter), | ||
1188 | OPT_BOOLEAN('i', "no-inherit", &no_inherit, | ||
1189 | "child tasks do not inherit counters"), | ||
1190 | OPT_STRING('p', "pid", &target.pid, "pid", | ||
1191 | "stat events on existing process id"), | ||
1192 | OPT_STRING('t', "tid", &target.tid, "tid", | ||
1193 | "stat events on existing thread id"), | ||
1194 | OPT_BOOLEAN('a', "all-cpus", &target.system_wide, | ||
1195 | "system-wide collection from all CPUs"), | ||
1196 | OPT_BOOLEAN('g', "group", &group, | ||
1197 | "put the counters into a counter group"), | ||
1198 | OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), | ||
1199 | OPT_INCR('v', "verbose", &verbose, | ||
1200 | "be more verbose (show counter open errors, etc)"), | ||
1201 | OPT_INTEGER('r', "repeat", &run_count, | ||
1202 | "repeat command and print average + stddev (max: 100, forever: 0)"), | ||
1203 | OPT_BOOLEAN('n', "null", &null_run, | ||
1204 | "null run - dont start any counters"), | ||
1205 | OPT_INCR('d', "detailed", &detailed_run, | ||
1206 | "detailed run - start a lot of events"), | ||
1207 | OPT_BOOLEAN('S', "sync", &sync_run, | ||
1208 | "call sync() before starting a run"), | ||
1209 | OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, | ||
1210 | "print large numbers with thousands\' separators", | ||
1211 | stat__set_big_num), | ||
1212 | OPT_STRING('C', "cpu", &target.cpu_list, "cpu", | ||
1213 | "list of cpus to monitor in system-wide"), | ||
1214 | OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, | ||
1215 | "disable CPU count aggregation", AGGR_NONE), | ||
1216 | OPT_STRING('x', "field-separator", &csv_sep, "separator", | ||
1217 | "print counts with custom separator"), | ||
1218 | OPT_CALLBACK('G', "cgroup", &evsel_list, "name", | ||
1219 | "monitor event in cgroup name only", parse_cgroups), | ||
1220 | OPT_STRING('o', "output", &output_name, "file", "output file name"), | ||
1221 | OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), | ||
1222 | OPT_INTEGER(0, "log-fd", &output_fd, | ||
1223 | "log output to fd, instead of stderr"), | ||
1224 | OPT_STRING(0, "pre", &pre_cmd, "command", | ||
1225 | "command to run prior to the measured command"), | ||
1226 | OPT_STRING(0, "post", &post_cmd, "command", | ||
1227 | "command to run after to the measured command"), | ||
1228 | OPT_UINTEGER('I', "interval-print", &stat_config.interval, | ||
1229 | "print counts at regular interval in ms (>= 10)"), | ||
1230 | OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, | ||
1231 | "aggregate counts per processor socket", AGGR_SOCKET), | ||
1232 | OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, | ||
1233 | "aggregate counts per physical processor core", AGGR_CORE), | ||
1234 | OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, | ||
1235 | "aggregate counts per thread", AGGR_THREAD), | ||
1236 | OPT_UINTEGER('D', "delay", &initial_delay, | ||
1237 | "ms to wait before starting measurement after program start"), | ||
1238 | OPT_END() | ||
1239 | }; | ||
1240 | const char * const stat_usage[] = { | 1241 | const char * const stat_usage[] = { |
1241 | "perf stat [<options>] [<command>]", | 1242 | "perf stat [<options>] [<command>]", |
1242 | NULL | 1243 | NULL |
@@ -1252,7 +1253,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1252 | if (evsel_list == NULL) | 1253 | if (evsel_list == NULL) |
1253 | return -ENOMEM; | 1254 | return -ENOMEM; |
1254 | 1255 | ||
1255 | argc = parse_options(argc, argv, options, stat_usage, | 1256 | argc = parse_options(argc, argv, stat_options, stat_usage, |
1256 | PARSE_OPT_STOP_AT_NON_OPTION); | 1257 | PARSE_OPT_STOP_AT_NON_OPTION); |
1257 | 1258 | ||
1258 | interval = stat_config.interval; | 1259 | interval = stat_config.interval; |
@@ -1262,14 +1263,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1262 | 1263 | ||
1263 | if (output_name && output_fd) { | 1264 | if (output_name && output_fd) { |
1264 | fprintf(stderr, "cannot use both --output and --log-fd\n"); | 1265 | fprintf(stderr, "cannot use both --output and --log-fd\n"); |
1265 | parse_options_usage(stat_usage, options, "o", 1); | 1266 | parse_options_usage(stat_usage, stat_options, "o", 1); |
1266 | parse_options_usage(NULL, options, "log-fd", 0); | 1267 | parse_options_usage(NULL, stat_options, "log-fd", 0); |
1267 | goto out; | 1268 | goto out; |
1268 | } | 1269 | } |
1269 | 1270 | ||
1270 | if (output_fd < 0) { | 1271 | if (output_fd < 0) { |
1271 | fprintf(stderr, "argument to --log-fd must be a > 0\n"); | 1272 | fprintf(stderr, "argument to --log-fd must be a > 0\n"); |
1272 | parse_options_usage(stat_usage, options, "log-fd", 0); | 1273 | parse_options_usage(stat_usage, stat_options, "log-fd", 0); |
1273 | goto out; | 1274 | goto out; |
1274 | } | 1275 | } |
1275 | 1276 | ||
@@ -1309,8 +1310,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1309 | /* User explicitly passed -B? */ | 1310 | /* User explicitly passed -B? */ |
1310 | if (big_num_opt == 1) { | 1311 | if (big_num_opt == 1) { |
1311 | fprintf(stderr, "-B option not supported with -x\n"); | 1312 | fprintf(stderr, "-B option not supported with -x\n"); |
1312 | parse_options_usage(stat_usage, options, "B", 1); | 1313 | parse_options_usage(stat_usage, stat_options, "B", 1); |
1313 | parse_options_usage(NULL, options, "x", 1); | 1314 | parse_options_usage(NULL, stat_options, "x", 1); |
1314 | goto out; | 1315 | goto out; |
1315 | } else /* Nope, so disable big number formatting */ | 1316 | } else /* Nope, so disable big number formatting */ |
1316 | big_num = false; | 1317 | big_num = false; |
@@ -1318,11 +1319,11 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1318 | big_num = false; | 1319 | big_num = false; |
1319 | 1320 | ||
1320 | if (!argc && target__none(&target)) | 1321 | if (!argc && target__none(&target)) |
1321 | usage_with_options(stat_usage, options); | 1322 | usage_with_options(stat_usage, stat_options); |
1322 | 1323 | ||
1323 | if (run_count < 0) { | 1324 | if (run_count < 0) { |
1324 | pr_err("Run count must be a positive number\n"); | 1325 | pr_err("Run count must be a positive number\n"); |
1325 | parse_options_usage(stat_usage, options, "r", 1); | 1326 | parse_options_usage(stat_usage, stat_options, "r", 1); |
1326 | goto out; | 1327 | goto out; |
1327 | } else if (run_count == 0) { | 1328 | } else if (run_count == 0) { |
1328 | forever = true; | 1329 | forever = true; |
@@ -1332,8 +1333,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1332 | if ((stat_config.aggr_mode == AGGR_THREAD) && !target__has_task(&target)) { | 1333 | if ((stat_config.aggr_mode == AGGR_THREAD) && !target__has_task(&target)) { |
1333 | fprintf(stderr, "The --per-thread option is only available " | 1334 | fprintf(stderr, "The --per-thread option is only available " |
1334 | "when monitoring via -p -t options.\n"); | 1335 | "when monitoring via -p -t options.\n"); |
1335 | parse_options_usage(NULL, options, "p", 1); | 1336 | parse_options_usage(NULL, stat_options, "p", 1); |
1336 | parse_options_usage(NULL, options, "t", 1); | 1337 | parse_options_usage(NULL, stat_options, "t", 1); |
1337 | goto out; | 1338 | goto out; |
1338 | } | 1339 | } |
1339 | 1340 | ||
@@ -1347,9 +1348,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1347 | fprintf(stderr, "both cgroup and no-aggregation " | 1348 | fprintf(stderr, "both cgroup and no-aggregation " |
1348 | "modes only available in system-wide mode\n"); | 1349 | "modes only available in system-wide mode\n"); |
1349 | 1350 | ||
1350 | parse_options_usage(stat_usage, options, "G", 1); | 1351 | parse_options_usage(stat_usage, stat_options, "G", 1); |
1351 | parse_options_usage(NULL, options, "A", 1); | 1352 | parse_options_usage(NULL, stat_options, "A", 1); |
1352 | parse_options_usage(NULL, options, "a", 1); | 1353 | parse_options_usage(NULL, stat_options, "a", 1); |
1353 | goto out; | 1354 | goto out; |
1354 | } | 1355 | } |
1355 | 1356 | ||
@@ -1361,12 +1362,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1361 | if (perf_evlist__create_maps(evsel_list, &target) < 0) { | 1362 | if (perf_evlist__create_maps(evsel_list, &target) < 0) { |
1362 | if (target__has_task(&target)) { | 1363 | if (target__has_task(&target)) { |
1363 | pr_err("Problems finding threads of monitor\n"); | 1364 | pr_err("Problems finding threads of monitor\n"); |
1364 | parse_options_usage(stat_usage, options, "p", 1); | 1365 | parse_options_usage(stat_usage, stat_options, "p", 1); |
1365 | parse_options_usage(NULL, options, "t", 1); | 1366 | parse_options_usage(NULL, stat_options, "t", 1); |
1366 | } else if (target__has_cpu(&target)) { | 1367 | } else if (target__has_cpu(&target)) { |
1367 | perror("failed to parse CPUs map"); | 1368 | perror("failed to parse CPUs map"); |
1368 | parse_options_usage(stat_usage, options, "C", 1); | 1369 | parse_options_usage(stat_usage, stat_options, "C", 1); |
1369 | parse_options_usage(NULL, options, "a", 1); | 1370 | parse_options_usage(NULL, stat_options, "a", 1); |
1370 | } | 1371 | } |
1371 | goto out; | 1372 | goto out; |
1372 | } | 1373 | } |
@@ -1381,7 +1382,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1381 | if (interval && interval < 100) { | 1382 | if (interval && interval < 100) { |
1382 | if (interval < 10) { | 1383 | if (interval < 10) { |
1383 | pr_err("print interval must be >= 10ms\n"); | 1384 | pr_err("print interval must be >= 10ms\n"); |
1384 | parse_options_usage(stat_usage, options, "I", 1); | 1385 | parse_options_usage(stat_usage, stat_options, "I", 1); |
1385 | goto out; | 1386 | goto out; |
1386 | } else | 1387 | } else |
1387 | pr_warning("print interval < 100ms. " | 1388 | pr_warning("print interval < 100ms. " |