3 #include <linux/time64.h>
10 #include "thread_map.h"
13 #include "sane_ctype.h"
16 #include <api/fs/fs.h>
18 #define CNTR_NOT_SUPPORTED "<not supported>"
19 #define CNTR_NOT_COUNTED "<not counted>"
21 static void print_running(struct perf_stat_config *config,
24 if (config->csv_output) {
25 fprintf(config->output, "%s%" PRIu64 "%s%.2f",
29 ena ? 100.0 * run / ena : 100.0);
30 } else if (run != ena) {
31 fprintf(config->output, " (%.2f%%)", 100.0 * run / ena);
35 static void print_noise_pct(struct perf_stat_config *config,
36 double total, double avg)
38 double pct = rel_stddev_stats(total, avg);
40 if (config->csv_output)
41 fprintf(config->output, "%s%.2f%%", config->csv_sep, pct);
43 fprintf(config->output, " ( +-%6.2f%% )", pct);
46 static void print_noise(struct perf_stat_config *config,
47 struct perf_evsel *evsel, double avg)
49 struct perf_stat_evsel *ps;
51 if (config->run_count == 1)
55 print_noise_pct(config, stddev_stats(&ps->res_stats[0]), avg);
58 static void print_cgroup(struct perf_stat_config *config, struct perf_evsel *evsel)
61 const char *cgrp_name = evsel->cgrp ? evsel->cgrp->name : "";
62 fprintf(config->output, "%s%s", config->csv_sep, cgrp_name);
67 static void aggr_printout(struct perf_stat_config *config,
68 struct perf_evsel *evsel, int id, int nr)
70 switch (config->aggr_mode) {
72 fprintf(config->output, "S%d-C%*d%s%*d%s",
73 cpu_map__id_to_socket(id),
74 config->csv_output ? 0 : -8,
75 cpu_map__id_to_cpu(id),
77 config->csv_output ? 0 : 4,
82 fprintf(config->output, "S%*d%s%*d%s",
83 config->csv_output ? 0 : -5,
86 config->csv_output ? 0 : 4,
92 fprintf(config->output, "S%d-C%*d%s",
93 cpu_map__id_to_socket(id),
94 config->csv_output ? 0 : -5,
95 cpu_map__id_to_cpu(id), config->csv_sep);
97 fprintf(config->output, "CPU%*d%s ",
98 config->csv_output ? 0 : -5,
99 perf_evsel__cpus(evsel)->map[id],
104 fprintf(config->output, "%*s-%*d%s",
105 config->csv_output ? 0 : 16,
106 thread_map__comm(evsel->threads, id),
107 config->csv_output ? 0 : -8,
108 thread_map__pid(evsel->threads, id),
124 struct perf_evsel *evsel;
127 #define METRIC_LEN 35
129 static void new_line_std(struct perf_stat_config *config __maybe_unused,
132 struct outstate *os = ctx;
137 static void do_new_line_std(struct perf_stat_config *config,
141 fputs(os->prefix, os->fh);
142 aggr_printout(config, os->evsel, os->id, os->nr);
143 if (config->aggr_mode == AGGR_NONE)
144 fprintf(os->fh, " ");
145 fprintf(os->fh, " ");
148 static void print_metric_std(struct perf_stat_config *config,
149 void *ctx, const char *color, const char *fmt,
150 const char *unit, double val)
152 struct outstate *os = ctx;
155 bool newline = os->newline;
159 if (unit == NULL || fmt == NULL) {
160 fprintf(out, "%-*s", METRIC_LEN, "");
165 do_new_line_std(config, os);
167 n = fprintf(out, " # ");
169 n += color_fprintf(out, color, fmt, val);
171 n += fprintf(out, fmt, val);
172 fprintf(out, " %-*s", METRIC_LEN - n - 1, unit);
175 static void new_line_csv(struct perf_stat_config *config, void *ctx)
177 struct outstate *os = ctx;
182 fprintf(os->fh, "%s%s", os->prefix, config->csv_sep);
183 aggr_printout(config, os->evsel, os->id, os->nr);
184 for (i = 0; i < os->nfields; i++)
185 fputs(config->csv_sep, os->fh);
188 static void print_metric_csv(struct perf_stat_config *config __maybe_unused,
190 const char *color __maybe_unused,
191 const char *fmt, const char *unit, double val)
193 struct outstate *os = ctx;
195 char buf[64], *vals, *ends;
197 if (unit == NULL || fmt == NULL) {
198 fprintf(out, "%s%s", config->csv_sep, config->csv_sep);
201 snprintf(buf, sizeof(buf), fmt, val);
202 ends = vals = ltrim(buf);
203 while (isdigit(*ends) || *ends == '.')
206 while (isspace(*unit))
208 fprintf(out, "%s%s%s%s", config->csv_sep, vals, config->csv_sep, unit);
211 /* Filter out some columns that don't work well in metrics only mode */
213 static bool valid_only_metric(const char *unit)
217 if (strstr(unit, "/sec") ||
218 strstr(unit, "hz") ||
219 strstr(unit, "Hz") ||
220 strstr(unit, "CPUs utilized"))
225 static const char *fixunit(char *buf, struct perf_evsel *evsel,
228 if (!strncmp(unit, "of all", 6)) {
229 snprintf(buf, 1024, "%s %s", perf_evsel__name(evsel),
236 static void print_metric_only(struct perf_stat_config *config,
237 void *ctx, const char *color, const char *fmt,
238 const char *unit, double val)
240 struct outstate *os = ctx;
242 char buf[1024], str[1024];
243 unsigned mlen = config->metric_only_len;
245 if (!valid_only_metric(unit))
247 unit = fixunit(buf, os->evsel, unit);
248 if (mlen < strlen(unit))
249 mlen = strlen(unit) + 1;
252 mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
254 color_snprintf(str, sizeof(str), color ?: "", fmt, val);
255 fprintf(out, "%*s ", mlen, str);
258 static void print_metric_only_csv(struct perf_stat_config *config __maybe_unused,
259 void *ctx, const char *color __maybe_unused,
261 const char *unit, double val)
263 struct outstate *os = ctx;
265 char buf[64], *vals, *ends;
268 if (!valid_only_metric(unit))
270 unit = fixunit(tbuf, os->evsel, unit);
271 snprintf(buf, sizeof buf, fmt, val);
272 ends = vals = ltrim(buf);
273 while (isdigit(*ends) || *ends == '.')
276 fprintf(out, "%s%s", vals, config->csv_sep);
279 static void new_line_metric(struct perf_stat_config *config __maybe_unused,
280 void *ctx __maybe_unused)
284 static void print_metric_header(struct perf_stat_config *config,
285 void *ctx, const char *color __maybe_unused,
286 const char *fmt __maybe_unused,
287 const char *unit, double val __maybe_unused)
289 struct outstate *os = ctx;
292 if (!valid_only_metric(unit))
294 unit = fixunit(tbuf, os->evsel, unit);
295 if (config->csv_output)
296 fprintf(os->fh, "%s%s", unit, config->csv_sep);
298 fprintf(os->fh, "%*s ", config->metric_only_len, unit);
301 static int first_shadow_cpu(struct perf_stat_config *config,
302 struct perf_evsel *evsel, int id)
304 struct perf_evlist *evlist = evsel->evlist;
307 if (!config->aggr_get_id)
310 if (config->aggr_mode == AGGR_NONE)
313 if (config->aggr_mode == AGGR_GLOBAL)
316 for (i = 0; i < perf_evsel__nr_cpus(evsel); i++) {
317 int cpu2 = perf_evsel__cpus(evsel)->map[i];
319 if (config->aggr_get_id(config, evlist->cpus, cpu2) == id)
325 static void abs_printout(struct perf_stat_config *config,
326 int id, int nr, struct perf_evsel *evsel, double avg)
328 FILE *output = config->output;
329 double sc = evsel->scale;
332 if (config->csv_output) {
333 fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";
336 fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s";
338 fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s";
341 aggr_printout(config, evsel, id, nr);
343 fprintf(output, fmt, avg, config->csv_sep);
346 fprintf(output, "%-*s%s",
347 config->csv_output ? 0 : config->unit_width,
348 evsel->unit, config->csv_sep);
350 fprintf(output, "%-*s", config->csv_output ? 0 : 25, perf_evsel__name(evsel));
352 print_cgroup(config, evsel);
355 static bool is_mixed_hw_group(struct perf_evsel *counter)
357 struct perf_evlist *evlist = counter->evlist;
358 u32 pmu_type = counter->attr.type;
359 struct perf_evsel *pos;
361 if (counter->nr_members < 2)
364 evlist__for_each_entry(evlist, pos) {
365 /* software events can be part of any hardware group */
366 if (pos->attr.type == PERF_TYPE_SOFTWARE)
368 if (pmu_type == PERF_TYPE_SOFTWARE) {
369 pmu_type = pos->attr.type;
372 if (pmu_type != pos->attr.type)
379 static void printout(struct perf_stat_config *config, int id, int nr,
380 struct perf_evsel *counter, double uval,
381 char *prefix, u64 run, u64 ena, double noise,
382 struct runtime_stat *st)
384 struct perf_stat_output_ctx out;
385 struct outstate os = {
386 .fh = config->output,
387 .prefix = prefix ? prefix : "",
392 print_metric_t pm = print_metric_std;
395 if (config->metric_only) {
396 nl = new_line_metric;
397 if (config->csv_output)
398 pm = print_metric_only_csv;
400 pm = print_metric_only;
404 if (config->csv_output && !config->metric_only) {
405 static int aggr_fields[] = {
413 pm = print_metric_csv;
416 os.nfields += aggr_fields[config->aggr_mode];
420 if (run == 0 || ena == 0 || counter->counts->scaled == -1) {
421 if (config->metric_only) {
422 pm(config, &os, NULL, "", "", 0);
425 aggr_printout(config, counter, id, nr);
427 fprintf(config->output, "%*s%s",
428 config->csv_output ? 0 : 18,
429 counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
432 if (counter->supported) {
433 config->print_free_counters_hint = 1;
434 if (is_mixed_hw_group(counter))
435 config->print_mixed_hw_group_error = 1;
438 fprintf(config->output, "%-*s%s",
439 config->csv_output ? 0 : config->unit_width,
440 counter->unit, config->csv_sep);
442 fprintf(config->output, "%*s",
443 config->csv_output ? 0 : -25,
444 perf_evsel__name(counter));
446 print_cgroup(config, counter);
448 if (!config->csv_output)
449 pm(config, &os, NULL, NULL, "", 0);
450 print_noise(config, counter, noise);
451 print_running(config, run, ena);
452 if (config->csv_output)
453 pm(config, &os, NULL, NULL, "", 0);
457 if (!config->metric_only)
458 abs_printout(config, id, nr, counter, uval);
460 out.print_metric = pm;
463 out.force_header = false;
465 if (config->csv_output && !config->metric_only) {
466 print_noise(config, counter, noise);
467 print_running(config, run, ena);
470 perf_stat__print_shadow_stats(config, counter, uval,
471 first_shadow_cpu(config, counter, id),
472 &out, &config->metric_events, st);
473 if (!config->csv_output && !config->metric_only) {
474 print_noise(config, counter, noise);
475 print_running(config, run, ena);
479 static void aggr_update_shadow(struct perf_stat_config *config,
480 struct perf_evlist *evlist)
484 struct perf_evsel *counter;
486 for (s = 0; s < config->aggr_map->nr; s++) {
487 id = config->aggr_map->map[s];
488 evlist__for_each_entry(evlist, counter) {
490 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
491 s2 = config->aggr_get_id(config, evlist->cpus, cpu);
494 val += perf_counts(counter->counts, cpu, 0)->val;
496 perf_stat__update_shadow_stats(counter, val,
497 first_shadow_cpu(config, counter, id),
503 static void uniquify_event_name(struct perf_evsel *counter)
508 if (counter->uniquified_name ||
509 !counter->pmu_name || !strncmp(counter->name, counter->pmu_name,
510 strlen(counter->pmu_name)))
513 config = strchr(counter->name, '/');
515 if (asprintf(&new_name,
516 "%s%s", counter->pmu_name, config) > 0) {
518 counter->name = new_name;
521 if (asprintf(&new_name,
522 "%s [%s]", counter->name, counter->pmu_name) > 0) {
524 counter->name = new_name;
528 counter->uniquified_name = true;
531 static void collect_all_aliases(struct perf_stat_config *config, struct perf_evsel *counter,
532 void (*cb)(struct perf_stat_config *config, struct perf_evsel *counter, void *data,
536 struct perf_evlist *evlist = counter->evlist;
537 struct perf_evsel *alias;
539 alias = list_prepare_entry(counter, &(evlist->entries), node);
540 list_for_each_entry_continue (alias, &evlist->entries, node) {
541 if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) ||
542 alias->scale != counter->scale ||
543 alias->cgrp != counter->cgrp ||
544 strcmp(alias->unit, counter->unit) ||
545 perf_evsel__is_clock(alias) != perf_evsel__is_clock(counter))
547 alias->merged_stat = true;
548 cb(config, alias, data, false);
552 static bool collect_data(struct perf_stat_config *config, struct perf_evsel *counter,
553 void (*cb)(struct perf_stat_config *config, struct perf_evsel *counter, void *data,
557 if (counter->merged_stat)
559 cb(config, counter, data, true);
560 if (config->no_merge)
561 uniquify_event_name(counter);
562 else if (counter->auto_merge_stats)
563 collect_all_aliases(config, counter, cb, data);
574 static void aggr_cb(struct perf_stat_config *config,
575 struct perf_evsel *counter, void *data, bool first)
577 struct aggr_data *ad = data;
580 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
581 struct perf_counts_values *counts;
583 s2 = config->aggr_get_id(config, perf_evsel__cpus(counter), cpu);
588 counts = perf_counts(counter->counts, cpu, 0);
590 * When any result is bad, make them all to give
591 * consistent output in interval mode.
593 if (counts->ena == 0 || counts->run == 0 ||
594 counter->counts->scaled == -1) {
599 ad->val += counts->val;
600 ad->ena += counts->ena;
601 ad->run += counts->run;
605 static void print_counter_aggrdata(struct perf_stat_config *config,
606 struct perf_evsel *counter, int s,
607 char *prefix, bool metric_only,
611 FILE *output = config->output;
616 ad.id = id = config->aggr_map->map[s];
617 ad.val = ad.ena = ad.run = 0;
619 if (!collect_data(config, counter, aggr_cb, &ad))
626 if (*first && metric_only) {
628 aggr_printout(config, counter, id, nr);
630 if (prefix && !metric_only)
631 fprintf(output, "%s", prefix);
633 uval = val * counter->scale;
634 printout(config, id, nr, counter, uval, prefix,
635 run, ena, 1.0, &rt_stat);
640 static void print_aggr(struct perf_stat_config *config,
641 struct perf_evlist *evlist,
644 bool metric_only = config->metric_only;
645 FILE *output = config->output;
646 struct perf_evsel *counter;
650 if (!(config->aggr_map || config->aggr_get_id))
653 aggr_update_shadow(config, evlist);
656 * With metric_only everything is on a single line.
657 * Without each counter has its own line.
659 for (s = 0; s < config->aggr_map->nr; s++) {
660 if (prefix && metric_only)
661 fprintf(output, "%s", prefix);
664 evlist__for_each_entry(evlist, counter) {
665 print_counter_aggrdata(config, counter, s,
674 static int cmp_val(const void *a, const void *b)
676 return ((struct perf_aggr_thread_value *)b)->val -
677 ((struct perf_aggr_thread_value *)a)->val;
680 static struct perf_aggr_thread_value *sort_aggr_thread(
681 struct perf_evsel *counter,
682 int nthreads, int ncpus,
684 struct target *_target)
686 int cpu, thread, i = 0;
688 struct perf_aggr_thread_value *buf;
690 buf = calloc(nthreads, sizeof(struct perf_aggr_thread_value));
694 for (thread = 0; thread < nthreads; thread++) {
695 u64 ena = 0, run = 0, val = 0;
697 for (cpu = 0; cpu < ncpus; cpu++) {
698 val += perf_counts(counter->counts, cpu, thread)->val;
699 ena += perf_counts(counter->counts, cpu, thread)->ena;
700 run += perf_counts(counter->counts, cpu, thread)->run;
703 uval = val * counter->scale;
706 * Skip value 0 when enabling --per-thread globally,
707 * otherwise too many 0 output.
709 if (uval == 0.0 && target__has_per_thread(_target))
712 buf[i].counter = counter;
721 qsort(buf, i, sizeof(struct perf_aggr_thread_value), cmp_val);
729 static void print_aggr_thread(struct perf_stat_config *config,
730 struct target *_target,
731 struct perf_evsel *counter, char *prefix)
733 FILE *output = config->output;
734 int nthreads = thread_map__nr(counter->threads);
735 int ncpus = cpu_map__nr(counter->cpus);
736 int thread, sorted_threads, id;
737 struct perf_aggr_thread_value *buf;
739 buf = sort_aggr_thread(counter, nthreads, ncpus, &sorted_threads, _target);
741 perror("cannot sort aggr thread");
745 for (thread = 0; thread < sorted_threads; thread++) {
747 fprintf(output, "%s", prefix);
751 printout(config, id, 0, buf[thread].counter, buf[thread].uval,
752 prefix, buf[thread].run, buf[thread].ena, 1.0,
755 printout(config, id, 0, buf[thread].counter, buf[thread].uval,
756 prefix, buf[thread].run, buf[thread].ena, 1.0,
765 double avg, avg_enabled, avg_running;
768 static void counter_aggr_cb(struct perf_stat_config *config __maybe_unused,
769 struct perf_evsel *counter, void *data,
770 bool first __maybe_unused)
772 struct caggr_data *cd = data;
773 struct perf_stat_evsel *ps = counter->stats;
775 cd->avg += avg_stats(&ps->res_stats[0]);
776 cd->avg_enabled += avg_stats(&ps->res_stats[1]);
777 cd->avg_running += avg_stats(&ps->res_stats[2]);
781 * Print out the results of a single counter:
782 * aggregated counts in system-wide mode
784 static void print_counter_aggr(struct perf_stat_config *config,
785 struct perf_evsel *counter, char *prefix)
787 bool metric_only = config->metric_only;
788 FILE *output = config->output;
790 struct caggr_data cd = { .avg = 0.0 };
792 if (!collect_data(config, counter, counter_aggr_cb, &cd))
795 if (prefix && !metric_only)
796 fprintf(output, "%s", prefix);
798 uval = cd.avg * counter->scale;
799 printout(config, -1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled,
802 fprintf(output, "\n");
805 static void counter_cb(struct perf_stat_config *config __maybe_unused,
806 struct perf_evsel *counter, void *data,
807 bool first __maybe_unused)
809 struct aggr_data *ad = data;
811 ad->val += perf_counts(counter->counts, ad->cpu, 0)->val;
812 ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena;
813 ad->run += perf_counts(counter->counts, ad->cpu, 0)->run;
817 * Print out the results of a single counter:
818 * does not use aggregated count in system-wide
820 static void print_counter(struct perf_stat_config *config,
821 struct perf_evsel *counter, char *prefix)
823 FILE *output = config->output;
828 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
829 struct aggr_data ad = { .cpu = cpu };
831 if (!collect_data(config, counter, counter_cb, &ad))
838 fprintf(output, "%s", prefix);
840 uval = val * counter->scale;
841 printout(config, cpu, 0, counter, uval, prefix, run, ena, 1.0,
848 static void print_no_aggr_metric(struct perf_stat_config *config,
849 struct perf_evlist *evlist,
854 struct perf_evsel *counter;
858 nrcpus = evlist->cpus->nr;
859 for (cpu = 0; cpu < nrcpus; cpu++) {
863 fputs(prefix, config->output);
864 evlist__for_each_entry(evlist, counter) {
866 aggr_printout(config, counter, cpu, 0);
869 val = perf_counts(counter->counts, cpu, 0)->val;
870 ena = perf_counts(counter->counts, cpu, 0)->ena;
871 run = perf_counts(counter->counts, cpu, 0)->run;
873 uval = val * counter->scale;
874 printout(config, cpu, 0, counter, uval, prefix, run, ena, 1.0,
877 fputc('\n', config->output);
881 static int aggr_header_lens[] = {
889 static const char *aggr_header_csv[] = {
890 [AGGR_CORE] = "core,cpus,",
891 [AGGR_SOCKET] = "socket,cpus",
892 [AGGR_NONE] = "cpu,",
893 [AGGR_THREAD] = "comm-pid,",
897 static void print_metric_headers(struct perf_stat_config *config,
898 struct perf_evlist *evlist,
899 const char *prefix, bool no_indent)
901 struct perf_stat_output_ctx out;
902 struct perf_evsel *counter;
903 struct outstate os = {
908 fprintf(config->output, "%s", prefix);
910 if (!config->csv_output && !no_indent)
911 fprintf(config->output, "%*s",
912 aggr_header_lens[config->aggr_mode], "");
913 if (config->csv_output) {
914 if (config->interval)
915 fputs("time,", config->output);
916 fputs(aggr_header_csv[config->aggr_mode], config->output);
919 /* Print metrics headers only */
920 evlist__for_each_entry(evlist, counter) {
923 out.print_metric = print_metric_header;
924 out.new_line = new_line_metric;
925 out.force_header = true;
927 perf_stat__print_shadow_stats(config, counter, 0,
930 &config->metric_events,
933 fputc('\n', config->output);
936 static void print_interval(struct perf_stat_config *config,
937 struct perf_evlist *evlist,
938 char *prefix, struct timespec *ts)
940 bool metric_only = config->metric_only;
941 unsigned int unit_width = config->unit_width;
942 FILE *output = config->output;
943 static int num_print_interval;
945 if (config->interval_clear)
948 sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep);
950 if ((num_print_interval == 0 && !config->csv_output) || config->interval_clear) {
951 switch (config->aggr_mode) {
953 fprintf(output, "# time socket cpus");
955 fprintf(output, " counts %*s events\n", unit_width, "unit");
958 fprintf(output, "# time core cpus");
960 fprintf(output, " counts %*s events\n", unit_width, "unit");
963 fprintf(output, "# time CPU ");
965 fprintf(output, " counts %*s events\n", unit_width, "unit");
968 fprintf(output, "# time comm-pid");
970 fprintf(output, " counts %*s events\n", unit_width, "unit");
974 fprintf(output, "# time");
976 fprintf(output, " counts %*s events\n", unit_width, "unit");
982 if ((num_print_interval == 0 || config->interval_clear) && metric_only)
983 print_metric_headers(config, evlist, " ", true);
984 if (++num_print_interval == 25)
985 num_print_interval = 0;
988 static void print_header(struct perf_stat_config *config,
989 struct target *_target,
990 int argc, const char **argv)
992 FILE *output = config->output;
997 if (!config->csv_output) {
998 fprintf(output, "\n");
999 fprintf(output, " Performance counter stats for ");
1000 if (_target->system_wide)
1001 fprintf(output, "\'system wide");
1002 else if (_target->cpu_list)
1003 fprintf(output, "\'CPU(s) %s", _target->cpu_list);
1004 else if (!target__has_task(_target)) {
1005 fprintf(output, "\'%s", argv ? argv[0] : "pipe");
1006 for (i = 1; argv && (i < argc); i++)
1007 fprintf(output, " %s", argv[i]);
1008 } else if (_target->pid)
1009 fprintf(output, "process id \'%s", _target->pid);
1011 fprintf(output, "thread id \'%s", _target->tid);
1013 fprintf(output, "\'");
1014 if (config->run_count > 1)
1015 fprintf(output, " (%d runs)", config->run_count);
1016 fprintf(output, ":\n\n");
1020 static int get_precision(double num)
1025 return lround(ceil(-log10(num)));
1028 static void print_table(struct perf_stat_config *config,
1029 FILE *output, int precision, double avg)
1032 int idx, indent = 0;
1034 scnprintf(tmp, 64, " %17.*f", precision, avg);
1035 while (tmp[indent] == ' ')
1038 fprintf(output, "%*s# Table of individual measurements:\n", indent, "");
1040 for (idx = 0; idx < config->run_count; idx++) {
1041 double run = (double) config->walltime_run[idx] / NSEC_PER_SEC;
1042 int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5);
1044 fprintf(output, " %17.*f (%+.*f) ",
1045 precision, run, precision, run - avg);
1047 for (h = 0; h < n; h++)
1048 fprintf(output, "#");
1050 fprintf(output, "\n");
1053 fprintf(output, "\n%*s# Final result:\n", indent, "");
1056 static double timeval2double(struct timeval *t)
1058 return t->tv_sec + (double) t->tv_usec/USEC_PER_SEC;
1061 static void print_footer(struct perf_stat_config *config)
1063 double avg = avg_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC;
1064 FILE *output = config->output;
1067 if (!config->null_run)
1068 fprintf(output, "\n");
1070 if (config->run_count == 1) {
1071 fprintf(output, " %17.9f seconds time elapsed", avg);
1073 if (config->ru_display) {
1074 double ru_utime = timeval2double(&config->ru_data.ru_utime);
1075 double ru_stime = timeval2double(&config->ru_data.ru_stime);
1077 fprintf(output, "\n\n");
1078 fprintf(output, " %17.9f seconds user\n", ru_utime);
1079 fprintf(output, " %17.9f seconds sys\n", ru_stime);
1082 double sd = stddev_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC;
1084 * Display at most 2 more significant
1085 * digits than the stddev inaccuracy.
1087 int precision = get_precision(sd) + 2;
1089 if (config->walltime_run_table)
1090 print_table(config, output, precision, avg);
1092 fprintf(output, " %17.*f +- %.*f seconds time elapsed",
1093 precision, avg, precision, sd);
1095 print_noise_pct(config, sd, avg);
1097 fprintf(output, "\n\n");
1099 if (config->print_free_counters_hint &&
1100 sysctl__read_int("kernel/nmi_watchdog", &n) >= 0 &&
1103 "Some events weren't counted. Try disabling the NMI watchdog:\n"
1104 " echo 0 > /proc/sys/kernel/nmi_watchdog\n"
1106 " echo 1 > /proc/sys/kernel/nmi_watchdog\n");
1108 if (config->print_mixed_hw_group_error)
1110 "The events in group usually have to be from "
1111 "the same PMU. Try reorganizing the group.\n");
1114 static void print_percore(struct perf_stat_config *config,
1115 struct perf_evsel *counter, char *prefix)
1117 bool metric_only = config->metric_only;
1118 FILE *output = config->output;
1122 if (!(config->aggr_map || config->aggr_get_id))
1125 for (s = 0; s < config->aggr_map->nr; s++) {
1126 if (prefix && metric_only)
1127 fprintf(output, "%s", prefix);
1129 print_counter_aggrdata(config, counter, s,
1130 prefix, metric_only,
1135 fputc('\n', output);
1139 perf_evlist__print_counters(struct perf_evlist *evlist,
1140 struct perf_stat_config *config,
1141 struct target *_target,
1142 struct timespec *ts,
1143 int argc, const char **argv)
1145 bool metric_only = config->metric_only;
1146 int interval = config->interval;
1147 struct perf_evsel *counter;
1148 char buf[64], *prefix = NULL;
1151 print_interval(config, evlist, prefix = buf, ts);
1153 print_header(config, _target, argc, argv);
1156 static int num_print_iv;
1158 if (num_print_iv == 0 && !interval)
1159 print_metric_headers(config, evlist, prefix, false);
1160 if (num_print_iv++ == 25)
1162 if (config->aggr_mode == AGGR_GLOBAL && prefix)
1163 fprintf(config->output, "%s", prefix);
1166 switch (config->aggr_mode) {
1169 print_aggr(config, evlist, prefix);
1172 evlist__for_each_entry(evlist, counter) {
1173 print_aggr_thread(config, _target, counter, prefix);
1177 evlist__for_each_entry(evlist, counter) {
1178 print_counter_aggr(config, counter, prefix);
1181 fputc('\n', config->output);
1185 print_no_aggr_metric(config, evlist, prefix);
1187 evlist__for_each_entry(evlist, counter) {
1188 if (counter->percore)
1189 print_percore(config, counter, prefix);
1191 print_counter(config, counter, prefix);
1200 if (!interval && !config->csv_output)
1201 print_footer(config);
1203 fflush(config->output);