Lines Matching +full:scaled +full:- +full:output +full:- +full:hz
2 * builtin-stat.c
7 * Sample output:
15 1708.761321 task-clock # 11.037 CPUs utilized
16 41,190 context-switches # 0.024 M/sec
17 6,735 CPU-migrations # 0.004 M/sec
18 17,318 page-faults # 0.010 M/sec
20 3,856,436,920 stalled-cycles-frontend # 74.09% frontend cycles idle
21 1,600,790,871 stalled-cycles-backend # 30.75% backend cycles idle
25 6,388,934 branch-misses # 1.32% of all branches
30 * Copyright (C) 2008-2011, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
48 #include <subcmd/parse-options.h>
49 #include "util/parse-events.h"
97 /* Default events used for perf stat -T */
99 "task-clock,"
103 "cpu/cycles-t/,"
104 "cpu/tx-start/,"
105 "cpu/el-start/,"
106 "cpu/cycles-ct/"
112 "task-clock,"
116 "cpu/cycles-t/,"
117 "cpu/tx-start/"
122 "topdown-total-slots",
123 "topdown-slots-retired",
124 "topdown-recovery-bubbles",
125 "topdown-fetch-bubbles",
126 "topdown-slots-issued",
152 static volatile pid_t child_pid = -1;
160 static int big_num_opt = -1;
213 return !strcmp(evsel->name, "duration_time"); in is_duration_time()
219 r->tv_sec = a->tv_sec - b->tv_sec; in diff_timespec()
220 if (a->tv_nsec < b->tv_nsec) { in diff_timespec()
221 r->tv_nsec = a->tv_nsec + NSEC_PER_SEC - b->tv_nsec; in diff_timespec()
222 r->tv_sec--; in diff_timespec()
224 r->tv_nsec = a->tv_nsec - b->tv_nsec ; in diff_timespec()
241 struct perf_event_attr *attr = &evsel->attr; in create_perf_stat_counter()
242 struct perf_evsel *leader = evsel->leader; in create_perf_stat_counter()
245 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | in create_perf_stat_counter()
254 if (leader->nr_members > 1) in create_perf_stat_counter()
255 attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; in create_perf_stat_counter()
257 attr->inherit = !no_inherit; in create_perf_stat_counter()
263 attr->sample_period = 0; in create_perf_stat_counter()
271 * by attr->sample_type != 0, and we can't run it on in create_perf_stat_counter()
275 attr->sample_type = PERF_SAMPLE_IDENTIFIER; in create_perf_stat_counter()
283 attr->disabled = 1; in create_perf_stat_counter()
290 attr->enable_on_exec = 1; in create_perf_stat_counter()
296 return perf_evsel__open_per_thread(evsel, evsel_list->threads); in create_perf_stat_counter()
304 if (perf_data__write(&perf_stat.data, event, event->header.size) < 0) { in process_synthesized_event()
306 return -1; in process_synthesized_event()
309 perf_stat.bytes_written += event->header.size; in process_synthesized_event()
323 #define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
331 return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, in perf_evsel__write_stat_event()
337 * do not aggregate counts across CPUs in system-wide mode
341 int nthreads = thread_map__nr(evsel_list->threads); in read_counter()
349 if (!counter->supported) in read_counter()
350 return -ENOENT; in read_counter()
352 if (counter->system_wide) in read_counter()
359 count = perf_counts(counter->counts, cpu, thread); in read_counter()
363 * (via perf_evsel__read_counter) and sets threir count->loaded. in read_counter()
365 if (!count->loaded && in read_counter()
367 counter->counts->scaled = -1; in read_counter()
368 perf_counts(counter->counts, cpu, thread)->ena = 0; in read_counter()
369 perf_counts(counter->counts, cpu, thread)->run = 0; in read_counter()
370 return -1; in read_counter()
373 count->loaded = false; in read_counter()
378 return -1; in read_counter()
383 fprintf(stat_config.output, in read_counter()
387 count->val, count->ena, count->run); in read_counter()
403 pr_debug("failed to read counter %s\n", counter->name); in read_counters()
406 pr_warning("failed to process counter %s\n", counter->name); in read_counters()
436 * - we don't have tracee (attaching to task or cpu) in enable_counters()
437 * - we have initial delay configured in enable_counters()
464 workload_exec_errno = info->si_value.sival_int; in workload_exec_failed_signal()
485 err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads, in perf_stat_synthesize_config()
493 err = perf_event__synthesize_cpu_map(NULL, evsel_list->cpus, in perf_stat_synthesize_config()
510 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
516 for (cpu = 0; cpu < xyarray__max_x(counter->fd); cpu++) { in __store_counter_ids()
517 for (thread = 0; thread < xyarray__max_y(counter->fd); in __store_counter_ids()
523 return -1; in __store_counter_ids()
532 struct cpu_map *cpus = counter->cpus; in store_counter_ids()
533 struct thread_map *threads = counter->threads; in store_counter_ids()
535 if (perf_evsel__alloc_id(counter, cpus->nr, threads->nr)) in store_counter_ids()
536 return -ENOMEM; in store_counter_ids()
543 return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID; in perf_evsel__should_store_id()
551 leader = evsel->leader; in perf_evsel__reset_weak_group()
553 leader->name, leader->nr_members); in perf_evsel__reset_weak_group()
562 if (c2->leader == leader) { in perf_evsel__reset_weak_group()
565 c2->leader = c2; in perf_evsel__reset_weak_group()
566 c2->nr_members = 0; in perf_evsel__reset_weak_group()
602 return -1; in __run_perf_stat()
604 child_pid = evsel_list->workload.pid; in __run_perf_stat()
616 counter->leader != counter && in __run_perf_stat()
617 counter->weak_group) { in __run_perf_stat()
632 counter->supported = false; in __run_perf_stat()
634 if ((counter->leader != counter) || in __run_perf_stat()
635 !(counter->leader->nr_members > 1)) in __run_perf_stat()
642 evsel_list->threads && in __run_perf_stat()
643 evsel_list->threads->err_thread != -1) { in __run_perf_stat()
645 * For global --per-thread case, skip current in __run_perf_stat()
648 if (!thread_map__remove(evsel_list->threads, in __run_perf_stat()
649 evsel_list->threads->err_thread)) { in __run_perf_stat()
650 evsel_list->threads->err_thread = -1; in __run_perf_stat()
659 if (child_pid != -1) in __run_perf_stat()
662 return -1; in __run_perf_stat()
664 counter->supported = true; in __run_perf_stat()
666 l = strlen(counter->unit); in __run_perf_stat()
672 return -1; in __run_perf_stat()
677 counter->filter, perf_evsel__name(counter), errno, in __run_perf_stat()
679 return -1; in __run_perf_stat()
684 err_term->val.drv_cfg, perf_evsel__name(counter), errno, in __run_perf_stat()
686 return -1; in __run_perf_stat()
723 if (interval_count && !(--times)) in __run_perf_stat()
732 return -1; in __run_perf_stat()
745 if (interval_count && !(--times)) in __run_perf_stat()
756 walltime_run[run_idx] = t1 - t0; in __run_perf_stat()
758 update_stats(&walltime_nsecs_stats, t1 - t0); in __run_perf_stat()
801 fprintf(stat_config.output, "%s%" PRIu64 "%s%.2f", in print_running()
807 fprintf(stat_config.output, " (%.2f%%)", 100.0 * run / ena); in print_running()
816 fprintf(stat_config.output, "%s%.2f%%", csv_sep, pct); in print_noise_pct()
818 fprintf(stat_config.output, " ( +-%6.2f%% )", pct); in print_noise_pct()
828 ps = evsel->stats; in print_noise()
829 print_noise_pct(stddev_stats(&ps->res_stats[0]), avg); in print_noise()
836 fprintf(stat_config.output, "S%d-C%*d%s%*d%s", in aggr_printout()
838 csv_output ? 0 : -8, in aggr_printout()
846 fprintf(stat_config.output, "S%*d%s%*d%s", in aggr_printout()
847 csv_output ? 0 : -5, in aggr_printout()
855 fprintf(stat_config.output, "CPU%*d%s", in aggr_printout()
856 csv_output ? 0 : -4, in aggr_printout()
857 perf_evsel__cpus(evsel)->map[id], csv_sep); in aggr_printout()
860 fprintf(stat_config.output, "%*s-%*d%s", in aggr_printout()
862 thread_map__comm(evsel->threads, id), in aggr_printout()
863 csv_output ? 0 : -8, in aggr_printout()
864 thread_map__pid(evsel->threads, id), in aggr_printout()
889 os->newline = true; in new_line_std()
894 fputc('\n', os->fh); in do_new_line_std()
895 fputs(os->prefix, os->fh); in do_new_line_std()
896 aggr_printout(os->evsel, os->id, os->nr); in do_new_line_std()
898 fprintf(os->fh, " "); in do_new_line_std()
899 fprintf(os->fh, " "); in do_new_line_std()
906 FILE *out = os->fh; in print_metric_std()
908 bool newline = os->newline; in print_metric_std()
910 os->newline = false; in print_metric_std()
913 fprintf(out, "%-*s", METRIC_LEN, ""); in print_metric_std()
925 fprintf(out, " %-*s", METRIC_LEN - n - 1, unit); in print_metric_std()
933 fputc('\n', os->fh); in new_line_csv()
934 if (os->prefix) in new_line_csv()
935 fprintf(os->fh, "%s%s", os->prefix, csv_sep); in new_line_csv()
936 aggr_printout(os->evsel, os->id, os->nr); in new_line_csv()
937 for (i = 0; i < os->nfields; i++) in new_line_csv()
938 fputs(csv_sep, os->fh); in new_line_csv()
946 FILE *out = os->fh; in print_metric_csv()
970 strstr(unit, "hz") || in valid_only_metric()
971 strstr(unit, "Hz") || in valid_only_metric()
992 FILE *out = os->fh; in print_metric_only()
998 unit = fixunit(buf, os->evsel, unit); in print_metric_only()
1003 mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1; in print_metric_only()
1014 FILE *out = os->fh; in print_metric_only_csv()
1020 unit = fixunit(tbuf, os->evsel, unit); in print_metric_only_csv()
1042 unit = fixunit(tbuf, os->evsel, unit); in print_metric_header()
1044 fprintf(os->fh, "%s%s", unit, csv_sep); in print_metric_header()
1046 fprintf(os->fh, "%*s ", metric_only_len, unit); in print_metric_header()
1063 int cpu2 = perf_evsel__cpus(evsel)->map[i]; in first_shadow_cpu()
1065 if (aggr_get_id(evsel_list->cpus, cpu2) == id) in first_shadow_cpu()
1073 FILE *output = stat_config.output; in abs_printout() local
1074 double sc = evsel->scale; in abs_printout()
1088 fprintf(output, fmt, avg, csv_sep); in abs_printout()
1090 if (evsel->unit) in abs_printout()
1091 fprintf(output, "%-*s%s", in abs_printout()
1093 evsel->unit, csv_sep); in abs_printout()
1095 fprintf(output, "%-*s", csv_output ? 0 : 25, perf_evsel__name(evsel)); in abs_printout()
1097 if (evsel->cgrp) in abs_printout()
1098 fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); in abs_printout()
1103 struct perf_evlist *evlist = counter->evlist; in is_mixed_hw_group()
1104 u32 pmu_type = counter->attr.type; in is_mixed_hw_group()
1107 if (counter->nr_members < 2) in is_mixed_hw_group()
1112 if (pos->attr.type == PERF_TYPE_SOFTWARE) in is_mixed_hw_group()
1115 pmu_type = pos->attr.type; in is_mixed_hw_group()
1118 if (pmu_type != pos->attr.type) in is_mixed_hw_group()
1131 .fh = stat_config.output, in printout()
1162 if (counter->cgrp) in printout()
1165 if (run == 0 || ena == 0 || counter->counts->scaled == -1) { in printout()
1172 fprintf(stat_config.output, "%*s%s", in printout()
1174 counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, in printout()
1177 if (counter->supported) { in printout()
1183 fprintf(stat_config.output, "%-*s%s", in printout()
1185 counter->unit, csv_sep); in printout()
1187 fprintf(stat_config.output, "%*s", in printout()
1188 csv_output ? 0 : -25, in printout()
1191 if (counter->cgrp) in printout()
1192 fprintf(stat_config.output, "%s%s", in printout()
1193 csv_sep, counter->cgrp->name); in printout()
1232 for (s = 0; s < aggr_map->nr; s++) { in aggr_update_shadow()
1233 id = aggr_map->map[s]; in aggr_update_shadow()
1237 s2 = aggr_get_id(evsel_list->cpus, cpu); in aggr_update_shadow()
1240 val += perf_counts(counter->counts, cpu, 0)->val; in aggr_update_shadow()
1254 if (counter->uniquified_name || in uniquify_event_name()
1255 !counter->pmu_name || !strncmp(counter->name, counter->pmu_name, in uniquify_event_name()
1256 strlen(counter->pmu_name))) in uniquify_event_name()
1259 config = strchr(counter->name, '/'); in uniquify_event_name()
1262 "%s%s", counter->pmu_name, config) > 0) { in uniquify_event_name()
1263 free(counter->name); in uniquify_event_name()
1264 counter->name = new_name; in uniquify_event_name()
1268 "%s [%s]", counter->name, counter->pmu_name) > 0) { in uniquify_event_name()
1269 free(counter->name); in uniquify_event_name()
1270 counter->name = new_name; in uniquify_event_name()
1274 counter->uniquified_name = true; in uniquify_event_name()
1284 alias = list_prepare_entry(counter, &(evsel_list->entries), node); in collect_all_aliases()
1285 list_for_each_entry_continue (alias, &evsel_list->entries, node) { in collect_all_aliases()
1287 alias->scale != counter->scale || in collect_all_aliases()
1288 alias->cgrp != counter->cgrp || in collect_all_aliases()
1289 strcmp(alias->unit, counter->unit) || in collect_all_aliases()
1292 alias->merged_stat = true; in collect_all_aliases()
1302 if (counter->merged_stat) in collect_data()
1307 else if (counter->auto_merge_stats) in collect_data()
1328 if (s2 != ad->id) in aggr_cb()
1331 ad->nr++; in aggr_cb()
1332 counts = perf_counts(counter->counts, cpu, 0); in aggr_cb()
1335 * consistent output in interval mode. in aggr_cb()
1337 if (counts->ena == 0 || counts->run == 0 || in aggr_cb()
1338 counter->counts->scaled == -1) { in aggr_cb()
1339 ad->ena = 0; in aggr_cb()
1340 ad->run = 0; in aggr_cb()
1343 ad->val += counts->val; in aggr_cb()
1344 ad->ena += counts->ena; in aggr_cb()
1345 ad->run += counts->run; in aggr_cb()
1351 FILE *output = stat_config.output; in print_aggr() local
1367 for (s = 0; s < aggr_map->nr; s++) { in print_aggr()
1370 fprintf(output, "%s", prefix); in print_aggr()
1372 ad.id = id = aggr_map->map[s]; in print_aggr()
1391 fprintf(output, "%s", prefix); in print_aggr()
1393 uval = val * counter->scale; in print_aggr()
1397 fputc('\n', output); in print_aggr()
1400 fputc('\n', output); in print_aggr()
1406 return ((struct perf_aggr_thread_value *)b)->val - in cmp_val()
1407 ((struct perf_aggr_thread_value *)a)->val; in cmp_val()
1427 val += perf_counts(counter->counts, cpu, thread)->val; in sort_aggr_thread()
1428 ena += perf_counts(counter->counts, cpu, thread)->ena; in sort_aggr_thread()
1429 run += perf_counts(counter->counts, cpu, thread)->run; in sort_aggr_thread()
1432 uval = val * counter->scale; in sort_aggr_thread()
1435 * Skip value 0 when enabling --per-thread globally, in sort_aggr_thread()
1436 * otherwise too many 0 output. in sort_aggr_thread()
1460 FILE *output = stat_config.output; in print_aggr_thread() local
1461 int nthreads = thread_map__nr(counter->threads); in print_aggr_thread()
1462 int ncpus = cpu_map__nr(counter->cpus); in print_aggr_thread()
1474 fprintf(output, "%s", prefix); in print_aggr_thread()
1485 fputc('\n', output); in print_aggr_thread()
1499 struct perf_stat_evsel *ps = counter->stats; in counter_aggr_cb()
1501 cd->avg += avg_stats(&ps->res_stats[0]); in counter_aggr_cb()
1502 cd->avg_enabled += avg_stats(&ps->res_stats[1]); in counter_aggr_cb()
1503 cd->avg_running += avg_stats(&ps->res_stats[2]); in counter_aggr_cb()
1508 * aggregated counts in system-wide mode
1512 FILE *output = stat_config.output; in print_counter_aggr() local
1520 fprintf(output, "%s", prefix); in print_counter_aggr()
1522 uval = cd.avg * counter->scale; in print_counter_aggr()
1523 printout(-1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled, in print_counter_aggr()
1526 fprintf(output, "\n"); in print_counter_aggr()
1534 ad->val += perf_counts(counter->counts, ad->cpu, 0)->val; in counter_cb()
1535 ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena; in counter_cb()
1536 ad->run += perf_counts(counter->counts, ad->cpu, 0)->run; in counter_cb()
1541 * does not use aggregated count in system-wide
1545 FILE *output = stat_config.output; in print_counter() local
1560 fprintf(output, "%s", prefix); in print_counter()
1562 uval = val * counter->scale; in print_counter()
1566 fputc('\n', output); in print_counter()
1578 nrcpus = evsel_list->cpus->nr; in print_no_aggr_metric()
1583 fputs(prefix, stat_config.output); in print_no_aggr_metric()
1591 val = perf_counts(counter->counts, cpu, 0)->val; in print_no_aggr_metric()
1592 ena = perf_counts(counter->counts, cpu, 0)->ena; in print_no_aggr_metric()
1593 run = perf_counts(counter->counts, cpu, 0)->run; in print_no_aggr_metric()
1595 uval = val * counter->scale; in print_no_aggr_metric()
1599 fputc('\n', stat_config.output); in print_no_aggr_metric()
1615 [AGGR_THREAD] = "comm-pid,",
1624 .fh = stat_config.output in print_metric_headers()
1628 fprintf(stat_config.output, "%s", prefix); in print_metric_headers()
1631 fprintf(stat_config.output, "%*s", in print_metric_headers()
1635 fputs("time,", stat_config.output); in print_metric_headers()
1637 stat_config.output); in print_metric_headers()
1656 fputc('\n', stat_config.output); in print_metric_headers()
1661 FILE *output = stat_config.output; in print_interval() local
1667 sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep); in print_interval()
1672 fprintf(output, "# time socket cpus"); in print_interval()
1674 fprintf(output, " counts %*s events\n", unit_width, "unit"); in print_interval()
1677 fprintf(output, "# time core cpus"); in print_interval()
1679 fprintf(output, " counts %*s events\n", unit_width, "unit"); in print_interval()
1682 fprintf(output, "# time CPU "); in print_interval()
1684 fprintf(output, " counts %*s events\n", unit_width, "unit"); in print_interval()
1687 fprintf(output, "# time comm-pid"); in print_interval()
1689 fprintf(output, " counts %*s events\n", unit_width, "unit"); in print_interval()
1693 fprintf(output, "# time"); in print_interval()
1695 fprintf(output, " counts %*s events\n", unit_width, "unit"); in print_interval()
1709 FILE *output = stat_config.output; in print_header() local
1715 fprintf(output, "\n"); in print_header()
1716 fprintf(output, " Performance counter stats for "); in print_header()
1718 fprintf(output, "\'system wide"); in print_header()
1720 fprintf(output, "\'CPU(s) %s", target.cpu_list); in print_header()
1722 fprintf(output, "\'%s", argv ? argv[0] : "pipe"); in print_header()
1724 fprintf(output, " %s", argv[i]); in print_header()
1726 fprintf(output, "process id \'%s", target.pid); in print_header()
1728 fprintf(output, "thread id \'%s", target.tid); in print_header()
1730 fprintf(output, "\'"); in print_header()
1732 fprintf(output, " (%d runs)", run_count); in print_header()
1733 fprintf(output, ":\n\n"); in print_header()
1742 return lround(ceil(-log10(num))); in get_precision()
1745 static void print_table(FILE *output, int precision, double avg) in print_table() argument
1754 fprintf(output, "%*s# Table of individual measurements:\n", indent, ""); in print_table()
1758 int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5); in print_table()
1760 fprintf(output, " %17.*f (%+.*f) ", in print_table()
1761 precision, run, precision, run - avg); in print_table()
1764 fprintf(output, "#"); in print_table()
1766 fprintf(output, "\n"); in print_table()
1769 fprintf(output, "\n%*s# Final result:\n", indent, ""); in print_table()
1774 return t->tv_sec + (double) t->tv_usec/USEC_PER_SEC; in timeval2double()
1780 FILE *output = stat_config.output; in print_footer() local
1784 fprintf(output, "\n"); in print_footer()
1787 fprintf(output, " %17.9f seconds time elapsed", avg); in print_footer()
1793 fprintf(output, "\n\n"); in print_footer()
1794 fprintf(output, " %17.9f seconds user\n", ru_utime); in print_footer()
1795 fprintf(output, " %17.9f seconds sys\n", ru_stime); in print_footer()
1806 print_table(output, precision, avg); in print_footer()
1808 fprintf(output, " %17.*f +- %.*f seconds time elapsed", in print_footer()
1813 fprintf(output, "\n\n"); in print_footer()
1818 fprintf(output, in print_footer()
1825 fprintf(output, in print_footer()
1853 fprintf(stat_config.output, "%s", prefix); in print_counters()
1875 fputc('\n', stat_config.output); in print_counters()
1896 fflush(stat_config.output); in print_counters()
1899 static volatile int signr = -1;
1903 if ((child_pid == -1) || stat_config.interval) in skip_signal()
1913 child_pid = -1; in skip_signal()
1930 if (child_pid != -1) in sig_atexit()
1935 if (signr == -1) in sig_atexit()
1972 OPT_BOOLEAN('i', "no-inherit", &no_inherit,
1978 OPT_BOOLEAN('a', "all-cpus", &target.system_wide,
1979 "system-wide collection from all CPUs"),
1988 "display details about each run (only with -r option)"),
1990 "null run - dont start any counters"),
1992 "detailed run - start a lot of events"),
1995 OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL,
1999 "list of cpus to monitor in system-wide"),
2000 OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode,
2002 OPT_BOOLEAN(0, "no-merge", &no_merge, "Do not merge identical named events"),
2003 OPT_STRING('x', "field-separator", &csv_sep, "separator",
2007 OPT_STRING('o', "output", &output_name, "file", "output file name"),
2008 OPT_BOOLEAN(0, "append", &append_file, "append to the output file"),
2009 OPT_INTEGER(0, "log-fd", &output_fd,
2010 "log output to fd, instead of stderr"),
2015 OPT_UINTEGER('I', "interval-print", &stat_config.interval,
2018 OPT_INTEGER(0, "interval-count", &stat_config.times,
2020 OPT_BOOLEAN(0, "interval-clear", &interval_clear,
2024 OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode,
2026 OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode,
2028 OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode,
2032 OPT_CALLBACK_NOOPT(0, "metric-only", &metric_only, NULL,
2036 OPT_BOOLEAN(0, "smi-cost", &smi_cost,
2056 int i, max = -1; in cpu_map__get_max()
2058 for (i = 0; i < map->nr; i++) { in cpu_map__get_max()
2059 if (map->map[i] > max) in cpu_map__get_max()
2060 max = map->map[i]; in cpu_map__get_max()
2072 if (idx >= map->nr) in perf_stat__get_aggr()
2073 return -1; in perf_stat__get_aggr()
2075 cpu = map->map[idx]; in perf_stat__get_aggr()
2077 if (cpus_aggr_map->map[cpu] == -1) in perf_stat__get_aggr()
2078 cpus_aggr_map->map[cpu] = get_id(map, idx); in perf_stat__get_aggr()
2080 return cpus_aggr_map->map[cpu]; in perf_stat__get_aggr()
2099 if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) { in perf_stat_init_aggr_mode()
2101 return -1; in perf_stat_init_aggr_mode()
2106 if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) { in perf_stat_init_aggr_mode()
2108 return -1; in perf_stat_init_aggr_mode()
2121 * The evsel_list->cpus is the base we operate on, in perf_stat_init_aggr_mode()
2125 nr = cpu_map__get_max(evsel_list->cpus); in perf_stat_init_aggr_mode()
2127 return cpus_aggr_map ? 0 : -ENOMEM; in perf_stat_init_aggr_mode()
2142 if (idx > map->nr) in perf_env__get_cpu()
2143 return -1; in perf_env__get_cpu()
2145 cpu = map->map[idx]; in perf_env__get_cpu()
2147 if (cpu >= env->nr_cpus_avail) in perf_env__get_cpu()
2148 return -1; in perf_env__get_cpu()
2158 return cpu == -1 ? -1 : env->cpu[cpu].socket_id; in perf_env__get_socket()
2164 int core = -1, cpu = perf_env__get_cpu(env, map, idx); in perf_env__get_core()
2166 if (cpu != -1) { in perf_env__get_core()
2167 int socket_id = env->cpu[cpu].socket_id; in perf_env__get_core()
2175 core = (socket_id << 16) | (env->cpu[cpu].core_id & 0xffff); in perf_env__get_core()
2195 return perf_env__get_socket(map, idx, &perf_stat.session->header.env); in perf_stat__get_socket_file()
2200 return perf_env__get_core(map, idx, &perf_stat.session->header.env); in perf_stat__get_core_file()
2205 struct perf_env *env = &st->session->header.env; in perf_stat_init_aggr_mode_file()
2209 if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) { in perf_stat_init_aggr_mode_file()
2211 return -1; in perf_stat_init_aggr_mode_file()
2216 if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) { in perf_stat_init_aggr_mode_file()
2218 return -1; in perf_stat_init_aggr_mode_file()
2243 attr[i - off] = attr[i]; in topdown_filter_events()
2247 attr[i - off] = NULL; in topdown_filter_events()
2251 return -1; in topdown_filter_events()
2253 if (i - off == 0) { in topdown_filter_events()
2265 s[-1] = '}'; in topdown_filter_events()
2268 s[-1] = 0; in topdown_filter_events()
2284 * if -d/--detailed, -d -d or -d -d -d is used:
2312 * Detailed stats (-d), covering the L1 and last level data caches: in add_default_attributes()
2342 * Very detailed stats (-d -d), covering the instruction cache and the TLB caches: in add_default_attributes()
2385 * Very, very detailed stats (-d -d -d), adding prefetch events: in add_default_attributes()
2408 /* Handle -T as -M transaction. Once platform specific metrics in add_default_attributes()
2420 if (pmu_have_event("cpu", "cycles-ct") && in add_default_attributes()
2421 pmu_have_event("cpu", "el-start")) in add_default_attributes()
2431 return -1; in add_default_attributes()
2441 return -1; in add_default_attributes()
2447 return -1; in add_default_attributes()
2461 return -1; in add_default_attributes()
2465 return -1; in add_default_attributes()
2476 pr_err("top down event configuration requires --per-core mode\n"); in add_default_attributes()
2477 return -1; in add_default_attributes()
2481 pr_err("top down event configuration requires system-wide mode (-a)\n"); in add_default_attributes()
2482 return -1; in add_default_attributes()
2490 return -1; in add_default_attributes()
2502 return -1; in add_default_attributes()
2506 return -1; in add_default_attributes()
2511 if (!evsel_list->nr_entries) { in add_default_attributes()
2516 return -1; in add_default_attributes()
2517 if (pmu_have_event("cpu", "stalled-cycles-frontend")) { in add_default_attributes()
2520 return -1; in add_default_attributes()
2522 if (pmu_have_event("cpu", "stalled-cycles-backend")) { in add_default_attributes()
2525 return -1; in add_default_attributes()
2528 return -1; in add_default_attributes()
2538 return -1; in add_default_attributes()
2545 return -1; in add_default_attributes()
2564 perf_header__set_feat(&session->header, feat); in init_features()
2566 perf_header__clear_feat(&session->header, HEADER_BUILD_ID); in init_features()
2567 perf_header__clear_feat(&session->header, HEADER_TRACING_DATA); in init_features()
2568 perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK); in init_features()
2569 perf_header__clear_feat(&session->header, HEADER_AUXTRACE); in init_features()
2581 data->file.path = output_name; in __cmd_record()
2584 pr_err("Cannot use -r option with perf stat record.\n"); in __cmd_record()
2585 return -1; in __cmd_record()
2591 return -1; in __cmd_record()
2596 session->evlist = evsel_list; in __cmd_record()
2606 struct stat_round_event *stat_round = &event->stat_round; in process_stat_round_event()
2609 const char **argv = session->header.env.cmdline_argv; in process_stat_round_event()
2610 int argc = session->header.env.nr_cmdline; in process_stat_round_event()
2615 if (stat_round->type == PERF_STAT_ROUND_TYPE__FINAL) in process_stat_round_event()
2616 update_stats(&walltime_nsecs_stats, stat_round->time); in process_stat_round_event()
2618 if (stat_config.interval && stat_round->time) { in process_stat_round_event()
2619 tsh.tv_sec = stat_round->time / NSEC_PER_SEC; in process_stat_round_event()
2620 tsh.tv_nsec = stat_round->time % NSEC_PER_SEC; in process_stat_round_event()
2635 perf_event__read_stat_config(&stat_config, &event->stat_config); in process_stat_config_event()
2637 if (cpu_map__empty(st->cpus)) { in process_stat_config_event()
2638 if (st->aggr_mode != AGGR_UNSET) in process_stat_config_event()
2643 if (st->aggr_mode != AGGR_UNSET) in process_stat_config_event()
2644 stat_config.aggr_mode = st->aggr_mode; in process_stat_config_event()
2656 if (!st->cpus || !st->threads) in set_maps()
2659 if (WARN_ONCE(st->maps_allocated, "stats double allocation\n")) in set_maps()
2660 return -EINVAL; in set_maps()
2662 perf_evlist__set_maps(evsel_list, st->cpus, st->threads); in set_maps()
2665 return -ENOMEM; in set_maps()
2667 st->maps_allocated = true; in set_maps()
2678 if (st->threads) { in process_thread_map_event()
2683 st->threads = thread_map__new_event(&event->thread_map); in process_thread_map_event()
2684 if (!st->threads) in process_thread_map_event()
2685 return -ENOMEM; in process_thread_map_event()
2698 if (st->cpus) { in process_cpu_map_event()
2703 cpus = cpu_map__new_data(&event->cpu_map.data); in process_cpu_map_event()
2705 return -ENOMEM; in process_cpu_map_event()
2707 st->cpus = cpus; in process_cpu_map_event()
2715 config->stats = calloc(nthreads, sizeof(struct runtime_stat)); in runtime_stat_new()
2716 if (!config->stats) in runtime_stat_new()
2717 return -1; in runtime_stat_new()
2719 config->stats_num = nthreads; in runtime_stat_new()
2722 runtime_stat__init(&config->stats[i]); in runtime_stat_new()
2731 if (!config->stats) in runtime_stat_delete()
2734 for (i = 0; i < config->stats_num; i++) in runtime_stat_delete()
2735 runtime_stat__exit(&config->stats[i]); in runtime_stat_delete()
2737 free(config->stats); in runtime_stat_delete()
2763 OPT_SET_UINT(0, "per-socket", &perf_stat.aggr_mode, in __cmd_report()
2765 OPT_SET_UINT(0, "per-core", &perf_stat.aggr_mode, in __cmd_report()
2767 OPT_SET_UINT('A', "no-aggr", &perf_stat.aggr_mode, in __cmd_report()
2778 input_name = "-"; in __cmd_report()
2788 return -1; in __cmd_report()
2791 stat_config.output = stderr; in __cmd_report()
2792 evsel_list = session->evlist; in __cmd_report()
2805 * Make system wide (-a) the default target if in setup_system_wide()
2809 * - there's no workload specified in setup_system_wide()
2810 * - there is workload specified but all requested in setup_system_wide()
2822 if (!counter->system_wide) in setup_system_wide()
2826 if (evsel_list->nr_entries) in setup_system_wide()
2837 int status = -EINVAL, run_idx; in cmd_stat()
2839 FILE *output = stderr; in cmd_stat() local
2847 return -ENOMEM; in cmd_stat()
2851 /* String-parsing callback-based options would segfault when negated */ in cmd_stat()
2872 return -1; in cmd_stat()
2880 * For record command the -o is already taken care of. in cmd_stat()
2882 if (!STAT_RECORD && output_name && strcmp(output_name, "-")) in cmd_stat()
2883 output = NULL; in cmd_stat()
2886 fprintf(stderr, "cannot use both --output and --log-fd\n"); in cmd_stat()
2888 parse_options_usage(NULL, stat_options, "log-fd", 0); in cmd_stat()
2893 fprintf(stderr, "--metric-only is not supported with --per-thread\n"); in cmd_stat()
2898 fprintf(stderr, "--metric-only is not supported with -r\n"); in cmd_stat()
2903 fprintf(stderr, "--table is only supported with -r\n"); in cmd_stat()
2910 fprintf(stderr, "argument to --log-fd must be a > 0\n"); in cmd_stat()
2911 parse_options_usage(stat_usage, stat_options, "log-fd", 0); in cmd_stat()
2915 if (!output) { in cmd_stat()
2919 output = fopen(output_name, mode); in cmd_stat()
2920 if (!output) { in cmd_stat()
2921 perror("failed to create output file"); in cmd_stat()
2922 return -1; in cmd_stat()
2925 fprintf(output, "# started on %s\n", ctime(&tm.tv_sec)); in cmd_stat()
2928 output = fdopen(output_fd, mode); in cmd_stat()
2929 if (!output) { in cmd_stat()
2931 return -errno; in cmd_stat()
2935 stat_config.output = output; in cmd_stat()
2938 * let the spreadsheet do the pretty-printing in cmd_stat()
2941 /* User explicitly passed -B? */ in cmd_stat()
2943 fprintf(stderr, "-B option not supported with -x\n"); in cmd_stat()
2949 } else if (big_num_opt == 0) /* User passed --no-big-num */ in cmd_stat()
2973 pr_err("failed to setup -r option"); in cmd_stat()
2981 fprintf(stderr, "The --per-thread option is only " in cmd_stat()
2982 "available when monitoring via -p -t -a " in cmd_stat()
2983 "options or only --per-thread.\n"); in cmd_stat()
2991 * no_aggr, cgroup are for system-wide only in cmd_stat()
2992 * --per-thread is aggregated per thread, we dont mix it with cpu mode in cmd_stat()
2997 fprintf(stderr, "both cgroup and no-aggregation " in cmd_stat()
2998 "modes only available in system-wide mode\n"); in cmd_stat()
3029 * so we could print it out on output. in cmd_stat()
3032 thread_map__read_comms(evsel_list->threads); in cmd_stat()
3035 thread_map__nr(evsel_list->threads))) { in cmd_stat()
3044 pr_err("interval-count option should be used together with " in cmd_stat()
3045 "interval-print.\n"); in cmd_stat()
3046 parse_options_usage(stat_usage, stat_options, "interval-count", 0); in cmd_stat()
3062 pr_err("timeout option is not supported with interval-print.\n"); in cmd_stat()
3075 * We dont want to block the signals - that would cause in cmd_stat()
3076 * child tasks to inherit that and Ctrl-C would not work. in cmd_stat()
3077 * What we want is for Ctrl-C to work in the exec()-ed in cmd_stat()
3090 fprintf(output, "[ perf stat: executing run #%d ... ]\n", in cmd_stat()
3097 if (forever && status != -1 && !interval) { in cmd_stat()
3103 if (!forever && status != -1 && !interval) in cmd_stat()
3117 * tools remain -acme in cmd_stat()
3122 &perf_stat.session->machines.host); in cmd_stat()
3134 perf_stat.session->header.data_size += perf_stat.bytes_written; in cmd_stat()