aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r--tools/perf/builtin-stat.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3c7452b39f57..688dea7cb08f 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -52,6 +52,7 @@
52#include "util/evlist.h" 52#include "util/evlist.h"
53#include "util/evsel.h" 53#include "util/evsel.h"
54#include "util/debug.h" 54#include "util/debug.h"
55#include "util/drv_configs.h"
55#include "util/color.h" 56#include "util/color.h"
56#include "util/stat.h" 57#include "util/stat.h"
57#include "util/header.h" 58#include "util/header.h"
@@ -65,6 +66,7 @@
65#include "util/group.h" 66#include "util/group.h"
66#include "asm/bug.h" 67#include "asm/bug.h"
67 68
69#include <linux/time64.h>
68#include <api/fs/fs.h> 70#include <api/fs/fs.h>
69#include <stdlib.h> 71#include <stdlib.h>
70#include <sys/prctl.h> 72#include <sys/prctl.h>
@@ -172,7 +174,7 @@ static inline void diff_timespec(struct timespec *r, struct timespec *a,
172{ 174{
173 r->tv_sec = a->tv_sec - b->tv_sec; 175 r->tv_sec = a->tv_sec - b->tv_sec;
174 if (a->tv_nsec < b->tv_nsec) { 176 if (a->tv_nsec < b->tv_nsec) {
175 r->tv_nsec = a->tv_nsec + 1000000000L - b->tv_nsec; 177 r->tv_nsec = a->tv_nsec + NSEC_PER_SEC - b->tv_nsec;
176 r->tv_sec--; 178 r->tv_sec--;
177 } else { 179 } else {
178 r->tv_nsec = a->tv_nsec - b->tv_nsec ; 180 r->tv_nsec = a->tv_nsec - b->tv_nsec ;
@@ -354,7 +356,7 @@ static void process_interval(void)
354 diff_timespec(&rs, &ts, &ref_time); 356 diff_timespec(&rs, &ts, &ref_time);
355 357
356 if (STAT_RECORD) { 358 if (STAT_RECORD) {
357 if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSECS_PER_SEC + rs.tv_nsec, INTERVAL)) 359 if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL))
358 pr_err("failed to write stat round event\n"); 360 pr_err("failed to write stat round event\n");
359 } 361 }
360 362
@@ -364,7 +366,7 @@ static void process_interval(void)
364static void enable_counters(void) 366static void enable_counters(void)
365{ 367{
366 if (initial_delay) 368 if (initial_delay)
367 usleep(initial_delay * 1000); 369 usleep(initial_delay * USEC_PER_MSEC);
368 370
369 /* 371 /*
370 * We need to enable counters only if: 372 * We need to enable counters only if:
@@ -539,10 +541,11 @@ static int __run_perf_stat(int argc, const char **argv)
539 int status = 0; 541 int status = 0;
540 const bool forks = (argc > 0); 542 const bool forks = (argc > 0);
541 bool is_pipe = STAT_RECORD ? perf_stat.file.is_pipe : false; 543 bool is_pipe = STAT_RECORD ? perf_stat.file.is_pipe : false;
544 struct perf_evsel_config_term *err_term;
542 545
543 if (interval) { 546 if (interval) {
544 ts.tv_sec = interval / 1000; 547 ts.tv_sec = interval / USEC_PER_MSEC;
545 ts.tv_nsec = (interval % 1000) * 1000000; 548 ts.tv_nsec = (interval % USEC_PER_MSEC) * NSEC_PER_MSEC;
546 } else { 549 } else {
547 ts.tv_sec = 1; 550 ts.tv_sec = 1;
548 ts.tv_nsec = 0; 551 ts.tv_nsec = 0;
@@ -610,6 +613,13 @@ try_again:
610 return -1; 613 return -1;
611 } 614 }
612 615
616 if (perf_evlist__apply_drv_configs(evsel_list, &counter, &err_term)) {
617 error("failed to set config \"%s\" on event %s with %d (%s)\n",
618 err_term->val.drv_cfg, perf_evsel__name(counter), errno,
619 str_error_r(errno, msg, sizeof(msg)));
620 return -1;
621 }
622
613 if (STAT_RECORD) { 623 if (STAT_RECORD) {
614 int err, fd = perf_data_file__fd(&perf_stat.file); 624 int err, fd = perf_data_file__fd(&perf_stat.file);
615 625
@@ -971,7 +981,7 @@ static void print_metric_header(void *ctx, const char *color __maybe_unused,
971static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg) 981static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
972{ 982{
973 FILE *output = stat_config.output; 983 FILE *output = stat_config.output;
974 double msecs = avg / 1e6; 984 double msecs = avg / NSEC_PER_MSEC;
975 const char *fmt_v, *fmt_n; 985 const char *fmt_v, *fmt_n;
976 char name[25]; 986 char name[25];
977 987
@@ -1460,7 +1470,7 @@ static void print_footer(void)
1460 if (!null_run) 1470 if (!null_run)
1461 fprintf(output, "\n"); 1471 fprintf(output, "\n");
1462 fprintf(output, " %17.9f seconds time elapsed", 1472 fprintf(output, " %17.9f seconds time elapsed",
1463 avg_stats(&walltime_nsecs_stats)/1e9); 1473 avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC);
1464 if (run_count > 1) { 1474 if (run_count > 1) {
1465 fprintf(output, " "); 1475 fprintf(output, " ");
1466 print_noise_pct(stddev_stats(&walltime_nsecs_stats), 1476 print_noise_pct(stddev_stats(&walltime_nsecs_stats),
@@ -2175,8 +2185,8 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
2175 update_stats(&walltime_nsecs_stats, stat_round->time); 2185 update_stats(&walltime_nsecs_stats, stat_round->time);
2176 2186
2177 if (stat_config.interval && stat_round->time) { 2187 if (stat_config.interval && stat_round->time) {
2178 tsh.tv_sec = stat_round->time / NSECS_PER_SEC; 2188 tsh.tv_sec = stat_round->time / NSEC_PER_SEC;
2179 tsh.tv_nsec = stat_round->time % NSECS_PER_SEC; 2189 tsh.tv_nsec = stat_round->time % NSEC_PER_SEC;
2180 ts = &tsh; 2190 ts = &tsh;
2181 } 2191 }
2182 2192