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

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
e0547311 0014de17

+82 -81
+82 -81
tools/perf/builtin-stat.c
··· 122 122 static struct timespec ref_time; 123 123 static struct cpu_map *aggr_map; 124 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 129 static volatile int done = 0; 127 130 ··· 930 927 return 0; 931 928 } 932 929 930 + static const struct option stat_options[] = { 931 + OPT_BOOLEAN('T', "transaction", &transaction_run, 932 + "hardware transaction statistics"), 933 + OPT_CALLBACK('e', "event", &evsel_list, "event", 934 + "event selector. use 'perf list' to list available events", 935 + parse_events_option), 936 + OPT_CALLBACK(0, "filter", &evsel_list, "filter", 937 + "event filter", parse_filter), 938 + OPT_BOOLEAN('i', "no-inherit", &no_inherit, 939 + "child tasks do not inherit counters"), 940 + OPT_STRING('p', "pid", &target.pid, "pid", 941 + "stat events on existing process id"), 942 + OPT_STRING('t', "tid", &target.tid, "tid", 943 + "stat events on existing thread id"), 944 + OPT_BOOLEAN('a', "all-cpus", &target.system_wide, 945 + "system-wide collection from all CPUs"), 946 + OPT_BOOLEAN('g', "group", &group, 947 + "put the counters into a counter group"), 948 + OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), 949 + OPT_INCR('v', "verbose", &verbose, 950 + "be more verbose (show counter open errors, etc)"), 951 + OPT_INTEGER('r', "repeat", &run_count, 952 + "repeat command and print average + stddev (max: 100, forever: 0)"), 953 + OPT_BOOLEAN('n', "null", &null_run, 954 + "null run - dont start any counters"), 955 + OPT_INCR('d', "detailed", &detailed_run, 956 + "detailed run - start a lot of events"), 957 + OPT_BOOLEAN('S', "sync", &sync_run, 958 + "call sync() before starting a run"), 959 + OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, 960 + "print large numbers with thousands\' separators", 961 + stat__set_big_num), 962 + OPT_STRING('C', "cpu", &target.cpu_list, "cpu", 963 + "list of cpus to monitor in system-wide"), 964 + OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, 965 + "disable CPU count aggregation", AGGR_NONE), 966 + OPT_STRING('x', "field-separator", &csv_sep, "separator", 967 + "print counts with custom separator"), 968 + OPT_CALLBACK('G', "cgroup", &evsel_list, "name", 969 + "monitor event in cgroup name only", parse_cgroups), 970 + OPT_STRING('o', "output", &output_name, "file", "output file name"), 971 + OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), 972 + OPT_INTEGER(0, "log-fd", &output_fd, 973 + "log output to fd, instead of stderr"), 974 + OPT_STRING(0, "pre", &pre_cmd, "command", 975 + "command to run prior to the measured command"), 976 + OPT_STRING(0, "post", &post_cmd, "command", 977 + "command to run after to the measured command"), 978 + OPT_UINTEGER('I', "interval-print", &stat_config.interval, 979 + "print counts at regular interval in ms (>= 10)"), 980 + OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, 981 + "aggregate counts per processor socket", AGGR_SOCKET), 982 + OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, 983 + "aggregate counts per physical processor core", AGGR_CORE), 984 + OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, 985 + "aggregate counts per thread", AGGR_THREAD), 986 + OPT_UINTEGER('D', "delay", &initial_delay, 987 + "ms to wait before starting measurement after program start"), 988 + OPT_END() 989 + }; 990 + 933 991 static int perf_stat__get_socket(struct cpu_map *map, int cpu) 934 992 { 935 993 return cpu_map__get_socket(map, cpu, NULL); ··· 1238 1174 1239 1175 int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) 1240 1176 { 1241 - bool append_file = false; 1242 - int output_fd = 0; 1243 - const char *output_name = NULL; 1244 - const struct option options[] = { 1245 - OPT_BOOLEAN('T', "transaction", &transaction_run, 1246 - "hardware transaction statistics"), 1247 - OPT_CALLBACK('e', "event", &evsel_list, "event", 1248 - "event selector. use 'perf list' to list available events", 1249 - parse_events_option), 1250 - OPT_CALLBACK(0, "filter", &evsel_list, "filter", 1251 - "event filter", parse_filter), 1252 - OPT_BOOLEAN('i', "no-inherit", &no_inherit, 1253 - "child tasks do not inherit counters"), 1254 - OPT_STRING('p', "pid", &target.pid, "pid", 1255 - "stat events on existing process id"), 1256 - OPT_STRING('t', "tid", &target.tid, "tid", 1257 - "stat events on existing thread id"), 1258 - OPT_BOOLEAN('a', "all-cpus", &target.system_wide, 1259 - "system-wide collection from all CPUs"), 1260 - OPT_BOOLEAN('g', "group", &group, 1261 - "put the counters into a counter group"), 1262 - OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), 1263 - OPT_INCR('v', "verbose", &verbose, 1264 - "be more verbose (show counter open errors, etc)"), 1265 - OPT_INTEGER('r', "repeat", &run_count, 1266 - "repeat command and print average + stddev (max: 100, forever: 0)"), 1267 - OPT_BOOLEAN('n', "null", &null_run, 1268 - "null run - dont start any counters"), 1269 - OPT_INCR('d', "detailed", &detailed_run, 1270 - "detailed run - start a lot of events"), 1271 - OPT_BOOLEAN('S', "sync", &sync_run, 1272 - "call sync() before starting a run"), 1273 - OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, 1274 - "print large numbers with thousands\' separators", 1275 - stat__set_big_num), 1276 - OPT_STRING('C', "cpu", &target.cpu_list, "cpu", 1277 - "list of cpus to monitor in system-wide"), 1278 - OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, 1279 - "disable CPU count aggregation", AGGR_NONE), 1280 - OPT_STRING('x', "field-separator", &csv_sep, "separator", 1281 - "print counts with custom separator"), 1282 - OPT_CALLBACK('G', "cgroup", &evsel_list, "name", 1283 - "monitor event in cgroup name only", parse_cgroups), 1284 - OPT_STRING('o', "output", &output_name, "file", "output file name"), 1285 - OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), 1286 - OPT_INTEGER(0, "log-fd", &output_fd, 1287 - "log output to fd, instead of stderr"), 1288 - OPT_STRING(0, "pre", &pre_cmd, "command", 1289 - "command to run prior to the measured command"), 1290 - OPT_STRING(0, "post", &post_cmd, "command", 1291 - "command to run after to the measured command"), 1292 - OPT_UINTEGER('I', "interval-print", &stat_config.interval, 1293 - "print counts at regular interval in ms (>= 10)"), 1294 - OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, 1295 - "aggregate counts per processor socket", AGGR_SOCKET), 1296 - OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, 1297 - "aggregate counts per physical processor core", AGGR_CORE), 1298 - OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, 1299 - "aggregate counts per thread", AGGR_THREAD), 1300 - OPT_UINTEGER('D', "delay", &initial_delay, 1301 - "ms to wait before starting measurement after program start"), 1302 - OPT_END() 1303 - }; 1304 1177 const char * const stat_usage[] = { 1305 1178 "perf stat [<options>] [<command>]", 1306 1179 NULL ··· 1253 1252 if (evsel_list == NULL) 1254 1253 return -ENOMEM; 1255 1254 1256 - argc = parse_options(argc, argv, options, stat_usage, 1255 + argc = parse_options(argc, argv, stat_options, stat_usage, 1257 1256 PARSE_OPT_STOP_AT_NON_OPTION); 1258 1257 1259 1258 interval = stat_config.interval; ··· 1263 1262 1264 1263 if (output_name && output_fd) { 1265 1264 fprintf(stderr, "cannot use both --output and --log-fd\n"); 1266 - parse_options_usage(stat_usage, options, "o", 1); 1267 - parse_options_usage(NULL, options, "log-fd", 0); 1265 + parse_options_usage(stat_usage, stat_options, "o", 1); 1266 + parse_options_usage(NULL, stat_options, "log-fd", 0); 1268 1267 goto out; 1269 1268 } 1270 1269 1271 1270 if (output_fd < 0) { 1272 1271 fprintf(stderr, "argument to --log-fd must be a > 0\n"); 1273 - parse_options_usage(stat_usage, options, "log-fd", 0); 1272 + parse_options_usage(stat_usage, stat_options, "log-fd", 0); 1274 1273 goto out; 1275 1274 } 1276 1275 ··· 1310 1309 /* User explicitly passed -B? */ 1311 1310 if (big_num_opt == 1) { 1312 1311 fprintf(stderr, "-B option not supported with -x\n"); 1313 - parse_options_usage(stat_usage, options, "B", 1); 1314 - parse_options_usage(NULL, options, "x", 1); 1312 + parse_options_usage(stat_usage, stat_options, "B", 1); 1313 + parse_options_usage(NULL, stat_options, "x", 1); 1315 1314 goto out; 1316 1315 } else /* Nope, so disable big number formatting */ 1317 1316 big_num = false; ··· 1319 1318 big_num = false; 1320 1319 1321 1320 if (!argc && target__none(&target)) 1322 - usage_with_options(stat_usage, options); 1321 + usage_with_options(stat_usage, stat_options); 1323 1322 1324 1323 if (run_count < 0) { 1325 1324 pr_err("Run count must be a positive number\n"); 1326 - parse_options_usage(stat_usage, options, "r", 1); 1325 + parse_options_usage(stat_usage, stat_options, "r", 1); 1327 1326 goto out; 1328 1327 } else if (run_count == 0) { 1329 1328 forever = true; ··· 1333 1332 if ((stat_config.aggr_mode == AGGR_THREAD) && !target__has_task(&target)) { 1334 1333 fprintf(stderr, "The --per-thread option is only available " 1335 1334 "when monitoring via -p -t options.\n"); 1336 - parse_options_usage(NULL, options, "p", 1); 1337 - parse_options_usage(NULL, options, "t", 1); 1335 + parse_options_usage(NULL, stat_options, "p", 1); 1336 + parse_options_usage(NULL, stat_options, "t", 1); 1338 1337 goto out; 1339 1338 } 1340 1339 ··· 1348 1347 fprintf(stderr, "both cgroup and no-aggregation " 1349 1348 "modes only available in system-wide mode\n"); 1350 1349 1351 - parse_options_usage(stat_usage, options, "G", 1); 1352 - parse_options_usage(NULL, options, "A", 1); 1353 - parse_options_usage(NULL, options, "a", 1); 1350 + parse_options_usage(stat_usage, stat_options, "G", 1); 1351 + parse_options_usage(NULL, stat_options, "A", 1); 1352 + parse_options_usage(NULL, stat_options, "a", 1); 1354 1353 goto out; 1355 1354 } 1356 1355 ··· 1362 1361 if (perf_evlist__create_maps(evsel_list, &target) < 0) { 1363 1362 if (target__has_task(&target)) { 1364 1363 pr_err("Problems finding threads of monitor\n"); 1365 - parse_options_usage(stat_usage, options, "p", 1); 1366 - parse_options_usage(NULL, options, "t", 1); 1364 + parse_options_usage(stat_usage, stat_options, "p", 1); 1365 + parse_options_usage(NULL, stat_options, "t", 1); 1367 1366 } else if (target__has_cpu(&target)) { 1368 1367 perror("failed to parse CPUs map"); 1369 - parse_options_usage(stat_usage, options, "C", 1); 1370 - parse_options_usage(NULL, options, "a", 1); 1368 + parse_options_usage(stat_usage, stat_options, "C", 1); 1369 + parse_options_usage(NULL, stat_options, "a", 1); 1371 1370 } 1372 1371 goto out; 1373 1372 } ··· 1382 1381 if (interval && interval < 100) { 1383 1382 if (interval < 10) { 1384 1383 pr_err("print interval must be >= 10ms\n"); 1385 - parse_options_usage(stat_usage, options, "I", 1); 1384 + parse_options_usage(stat_usage, stat_options, "I", 1); 1386 1385 goto out; 1387 1386 } else 1388 1387 pr_warning("print interval < 100ms. "