Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1 | /* |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 2 | * builtin-stat.c |
| 3 | * |
| 4 | * Builtin stat command: Give a precise performance counters summary |
| 5 | * overview about any workload, CPU or specific PID. |
| 6 | * |
| 7 | * Sample output: |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 8 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 9 | $ perf stat ./hackbench 10 |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 10 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 11 | Time: 0.118 |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 12 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 13 | Performance counter stats for './hackbench 10': |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 14 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 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 |
| 19 | 5,205,202,243 cycles # 3.046 GHz |
| 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 |
| 22 | 2,603,501,247 instructions # 0.50 insns per cycle |
| 23 | # 1.48 stalled cycles per insn |
| 24 | 484,357,498 branches # 283.455 M/sec |
| 25 | 6,388,934 branch-misses # 1.32% of all branches |
| 26 | |
| 27 | 0.154822978 seconds time elapsed |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 28 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 29 | * |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 30 | * Copyright (C) 2008-2011, Red Hat Inc, Ingo Molnar <mingo@redhat.com> |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 31 | * |
| 32 | * Improvements and fixes by: |
| 33 | * |
| 34 | * Arjan van de Ven <arjan@linux.intel.com> |
| 35 | * Yanmin Zhang <yanmin.zhang@intel.com> |
| 36 | * Wu Fengguang <fengguang.wu@intel.com> |
| 37 | * Mike Galbraith <efault@gmx.de> |
| 38 | * Paul Mackerras <paulus@samba.org> |
Jaswinder Singh Rajput | 6e750a8f | 2009-06-27 03:02:07 +0530 | [diff] [blame] | 39 | * Jaswinder Singh Rajput <jaswinder@kernel.org> |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 40 | * |
| 41 | * Released under the GPL v2. (and only v2, not any later version) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 42 | */ |
| 43 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 44 | #include "perf.h" |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 45 | #include "builtin.h" |
Arnaldo Carvalho de Melo | f14d570 | 2014-10-17 12:17:40 -0300 | [diff] [blame] | 46 | #include "util/cgroup.h" |
Ingo Molnar | 148be2c | 2009-04-27 08:02:14 +0200 | [diff] [blame] | 47 | #include "util/util.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 48 | #include <subcmd/parse-options.h> |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 49 | #include "util/parse-events.h" |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 50 | #include "util/pmu.h" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 51 | #include "util/event.h" |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 52 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 53 | #include "util/evsel.h" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 54 | #include "util/debug.h" |
Mathieu Poirier | 5d8bb1e | 2016-09-16 09:50:03 -0600 | [diff] [blame] | 55 | #include "util/drv_configs.h" |
Ingo Molnar | a5d243d | 2011-04-27 05:39:24 +0200 | [diff] [blame] | 56 | #include "util/color.h" |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 57 | #include "util/stat.h" |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 58 | #include "util/header.h" |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 59 | #include "util/cpumap.h" |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 60 | #include "util/thread.h" |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 61 | #include "util/thread_map.h" |
Jiri Olsa | d809560 | 2015-08-07 12:51:03 +0200 | [diff] [blame] | 62 | #include "util/counts.h" |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 63 | #include "util/group.h" |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 64 | #include "util/session.h" |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 65 | #include "util/tool.h" |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 66 | #include "util/string2.h" |
Andi Kleen | b18f3e3 | 2017-08-31 12:40:31 -0700 | [diff] [blame] | 67 | #include "util/metricgroup.h" |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 68 | #include "asm/bug.h" |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 69 | |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 70 | #include <linux/time64.h> |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 71 | #include <api/fs/fs.h> |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 72 | #include <errno.h> |
Arnaldo Carvalho de Melo | 9607ad3 | 2017-04-19 15:49:18 -0300 | [diff] [blame] | 73 | #include <signal.h> |
Peter Zijlstra | 1f16c57 | 2012-10-23 13:40:14 +0200 | [diff] [blame] | 74 | #include <stdlib.h> |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 75 | #include <sys/prctl.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 76 | #include <inttypes.h> |
Stephane Eranian | 5af52b5 | 2010-05-18 15:00:01 +0200 | [diff] [blame] | 77 | #include <locale.h> |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 78 | #include <math.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 79 | #include <sys/types.h> |
| 80 | #include <sys/stat.h> |
Arnaldo Carvalho de Melo | 4208735 | 2017-04-19 19:06:30 -0300 | [diff] [blame] | 81 | #include <sys/wait.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 82 | #include <unistd.h> |
Jiri Olsa | 0ce2da1 | 2018-06-05 14:13:13 +0200 | [diff] [blame] | 83 | #include <sys/time.h> |
| 84 | #include <sys/resource.h> |
| 85 | #include <sys/wait.h> |
Peter Zijlstra | 16c8a10 | 2009-05-05 17:50:27 +0200 | [diff] [blame] | 86 | |
Arnaldo Carvalho de Melo | 3d689ed | 2017-04-17 16:10:49 -0300 | [diff] [blame] | 87 | #include "sane_ctype.h" |
| 88 | |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 89 | #define DEFAULT_SEPARATOR " " |
David Ahern | 2cee77c | 2011-05-30 08:55:59 -0600 | [diff] [blame] | 90 | #define CNTR_NOT_SUPPORTED "<not supported>" |
| 91 | #define CNTR_NOT_COUNTED "<not counted>" |
Kan Liang | daefd0b | 2017-05-26 12:05:38 -0700 | [diff] [blame] | 92 | #define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi" |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 93 | |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 94 | static void print_counters(struct timespec *ts, int argc, const char **argv); |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 95 | |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 96 | /* Default events used for perf stat -T */ |
Jiri Olsa | a454742 | 2015-06-03 16:25:53 +0200 | [diff] [blame] | 97 | static const char *transaction_attrs = { |
| 98 | "task-clock," |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 99 | "{" |
| 100 | "instructions," |
| 101 | "cycles," |
| 102 | "cpu/cycles-t/," |
| 103 | "cpu/tx-start/," |
| 104 | "cpu/el-start/," |
| 105 | "cpu/cycles-ct/" |
| 106 | "}" |
| 107 | }; |
| 108 | |
| 109 | /* More limited version when the CPU does not have all events. */ |
Jiri Olsa | a454742 | 2015-06-03 16:25:53 +0200 | [diff] [blame] | 110 | static const char * transaction_limited_attrs = { |
| 111 | "task-clock," |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 112 | "{" |
| 113 | "instructions," |
| 114 | "cycles," |
| 115 | "cpu/cycles-t/," |
| 116 | "cpu/tx-start/" |
| 117 | "}" |
| 118 | }; |
| 119 | |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 120 | static const char * topdown_attrs[] = { |
| 121 | "topdown-total-slots", |
| 122 | "topdown-slots-retired", |
| 123 | "topdown-recovery-bubbles", |
| 124 | "topdown-fetch-bubbles", |
| 125 | "topdown-slots-issued", |
| 126 | NULL, |
| 127 | }; |
| 128 | |
Kan Liang | daefd0b | 2017-05-26 12:05:38 -0700 | [diff] [blame] | 129 | static const char *smi_cost_attrs = { |
| 130 | "{" |
| 131 | "msr/aperf/," |
| 132 | "msr/smi/," |
| 133 | "cycles" |
| 134 | "}" |
| 135 | }; |
| 136 | |
Robert Richter | 666e6d4 | 2012-04-05 18:26:27 +0200 | [diff] [blame] | 137 | static struct perf_evlist *evsel_list; |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 138 | |
Andi Kleen | b18f3e3 | 2017-08-31 12:40:31 -0700 | [diff] [blame] | 139 | static struct rblist metric_events; |
| 140 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 141 | static struct target target = { |
Namhyung Kim | 77a6f01 | 2012-05-07 14:09:04 +0900 | [diff] [blame] | 142 | .uid = UINT_MAX, |
| 143 | }; |
Jaswinder Singh Rajput | 3d63259 | 2009-06-24 18:19:34 +0530 | [diff] [blame] | 144 | |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 145 | typedef int (*aggr_get_id_t)(struct cpu_map *m, int cpu); |
| 146 | |
Jaswinder Singh Rajput | 3d63259 | 2009-06-24 18:19:34 +0530 | [diff] [blame] | 147 | static int run_count = 1; |
Stephane Eranian | 2e6cdf9 | 2010-05-12 10:40:01 +0200 | [diff] [blame] | 148 | static bool no_inherit = false; |
Stephane Eranian | d07f0b1 | 2013-06-04 17:44:26 +0200 | [diff] [blame] | 149 | static volatile pid_t child_pid = -1; |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 150 | static bool null_run = false; |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 151 | static int detailed_run = 0; |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 152 | static bool transaction_run; |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 153 | static bool topdown_run = false; |
Kan Liang | daefd0b | 2017-05-26 12:05:38 -0700 | [diff] [blame] | 154 | static bool smi_cost = false; |
| 155 | static bool smi_reset = false; |
Arnaldo Carvalho de Melo | 201e0b0 | 2010-12-01 17:53:27 -0200 | [diff] [blame] | 156 | static bool big_num = true; |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 157 | static int big_num_opt = -1; |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 158 | static const char *csv_sep = NULL; |
| 159 | static bool csv_output = false; |
Lin Ming | 43bece7 | 2011-08-17 18:42:07 +0800 | [diff] [blame] | 160 | static bool group = false; |
Peter Zijlstra | 1f16c57 | 2012-10-23 13:40:14 +0200 | [diff] [blame] | 161 | static const char *pre_cmd = NULL; |
| 162 | static const char *post_cmd = NULL; |
| 163 | static bool sync_run = false; |
Andi Kleen | 4119168 | 2013-08-02 17:41:11 -0700 | [diff] [blame] | 164 | static unsigned int initial_delay = 0; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 165 | static unsigned int unit_width = 4; /* strlen("unit") */ |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 166 | static bool forever = false; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 167 | static bool metric_only = false; |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 168 | static bool force_metric_only = false; |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 169 | static bool no_merge = false; |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 170 | static bool walltime_run_table = false; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 171 | static struct timespec ref_time; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 172 | static struct cpu_map *aggr_map; |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 173 | static aggr_get_id_t aggr_get_id; |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 174 | static bool append_file; |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 175 | static bool interval_count; |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 176 | static const char *output_name; |
| 177 | static int output_fd; |
Borislav Petkov | 02d492e | 2017-02-07 01:40:05 +0100 | [diff] [blame] | 178 | static int print_free_counters_hint; |
Kan Liang | 30060ea | 2018-04-24 11:20:11 -0700 | [diff] [blame] | 179 | static int print_mixed_hw_group_error; |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 180 | static u64 *walltime_run; |
Jiri Olsa | 0ce2da1 | 2018-06-05 14:13:13 +0200 | [diff] [blame] | 181 | static bool ru_display = false; |
| 182 | static struct rusage ru_data; |
Stephane Eranian | 5af52b5 | 2010-05-18 15:00:01 +0200 | [diff] [blame] | 183 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 184 | struct perf_stat { |
| 185 | bool record; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 186 | struct perf_data data; |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 187 | struct perf_session *session; |
| 188 | u64 bytes_written; |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 189 | struct perf_tool tool; |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 190 | bool maps_allocated; |
| 191 | struct cpu_map *cpus; |
| 192 | struct thread_map *threads; |
Jiri Olsa | 89af4e0 | 2015-11-05 15:41:02 +0100 | [diff] [blame] | 193 | enum aggr_mode aggr_mode; |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | static struct perf_stat perf_stat; |
| 197 | #define STAT_RECORD perf_stat.record |
| 198 | |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 199 | static volatile int done = 0; |
| 200 | |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 201 | static struct perf_stat_config stat_config = { |
| 202 | .aggr_mode = AGGR_GLOBAL, |
Jiri Olsa | 711a572 | 2015-07-21 14:31:23 +0200 | [diff] [blame] | 203 | .scale = true, |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 204 | }; |
| 205 | |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 206 | static bool is_duration_time(struct perf_evsel *evsel) |
| 207 | { |
| 208 | return !strcmp(evsel->name, "duration_time"); |
| 209 | } |
| 210 | |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 211 | static inline void diff_timespec(struct timespec *r, struct timespec *a, |
| 212 | struct timespec *b) |
| 213 | { |
| 214 | r->tv_sec = a->tv_sec - b->tv_sec; |
| 215 | if (a->tv_nsec < b->tv_nsec) { |
Arnaldo Carvalho de Melo | 310ebb9 | 2016-08-08 14:57:04 -0300 | [diff] [blame] | 216 | r->tv_nsec = a->tv_nsec + NSEC_PER_SEC - b->tv_nsec; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 217 | r->tv_sec--; |
| 218 | } else { |
| 219 | r->tv_nsec = a->tv_nsec - b->tv_nsec ; |
| 220 | } |
| 221 | } |
| 222 | |
Jiri Olsa | 254ecbc7 | 2015-06-26 11:29:13 +0200 | [diff] [blame] | 223 | static void perf_stat__reset_stats(void) |
| 224 | { |
Jin Yao | 5673944 | 2017-12-05 22:03:07 +0800 | [diff] [blame] | 225 | int i; |
| 226 | |
Jiri Olsa | 254ecbc7 | 2015-06-26 11:29:13 +0200 | [diff] [blame] | 227 | perf_evlist__reset_stats(evsel_list); |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 228 | perf_stat__reset_shadow_stats(); |
Jin Yao | 5673944 | 2017-12-05 22:03:07 +0800 | [diff] [blame] | 229 | |
| 230 | for (i = 0; i < stat_config.stats_num; i++) |
| 231 | perf_stat__reset_shadow_per_stat(&stat_config.stats[i]); |
Jiri Olsa | 1eda3b2 | 2015-06-03 16:25:55 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Jiri Olsa | cac2142 | 2012-11-12 18:34:00 +0100 | [diff] [blame] | 234 | static int create_perf_stat_counter(struct perf_evsel *evsel) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 235 | { |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 236 | struct perf_event_attr *attr = &evsel->attr; |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 237 | struct perf_evsel *leader = evsel->leader; |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 238 | |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 239 | if (stat_config.scale) { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 240 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
| 241 | PERF_FORMAT_TOTAL_TIME_RUNNING; |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /* |
| 245 | * The event is part of non trivial group, let's enable |
| 246 | * the group read (for leader) and ID retrieval for all |
| 247 | * members. |
| 248 | */ |
| 249 | if (leader->nr_members > 1) |
| 250 | attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 251 | |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 252 | attr->inherit = !no_inherit; |
Arnaldo Carvalho de Melo | 5d2cd90 | 2011-04-14 11:20:14 -0300 | [diff] [blame] | 253 | |
Jiri Olsa | 6acd8e9 | 2015-11-25 16:36:54 +0100 | [diff] [blame] | 254 | /* |
| 255 | * Some events get initialized with sample_(period/type) set, |
| 256 | * like tracepoints. Clear it up for counting. |
| 257 | */ |
| 258 | attr->sample_period = 0; |
Jiri Olsa | 6db1a5c | 2016-01-05 22:09:05 +0100 | [diff] [blame] | 259 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 260 | /* |
| 261 | * But set sample_type to PERF_SAMPLE_IDENTIFIER, which should be harmless |
| 262 | * while avoiding that older tools show confusing messages. |
Jiri Olsa | 6db1a5c | 2016-01-05 22:09:05 +0100 | [diff] [blame] | 263 | * |
| 264 | * However for pipe sessions we need to keep it zero, |
| 265 | * because script's perf_evsel__check_attr is triggered |
| 266 | * by attr->sample_type != 0, and we can't run it on |
| 267 | * stat sessions. |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 268 | */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 269 | if (!(STAT_RECORD && perf_stat.data.is_pipe)) |
Jiri Olsa | 6db1a5c | 2016-01-05 22:09:05 +0100 | [diff] [blame] | 270 | attr->sample_type = PERF_SAMPLE_IDENTIFIER; |
Jiri Olsa | 6acd8e9 | 2015-11-25 16:36:54 +0100 | [diff] [blame] | 271 | |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 272 | /* |
| 273 | * Disabling all counters initially, they will be enabled |
| 274 | * either manually by us or by kernel via enable_on_exec |
| 275 | * set later. |
| 276 | */ |
Jiri Olsa | c8280ce | 2015-12-03 10:06:45 +0100 | [diff] [blame] | 277 | if (perf_evsel__is_group_leader(evsel)) { |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 278 | attr->disabled = 1; |
| 279 | |
Jiri Olsa | c8280ce | 2015-12-03 10:06:45 +0100 | [diff] [blame] | 280 | /* |
| 281 | * In case of initial_delay we enable tracee |
| 282 | * events manually. |
| 283 | */ |
| 284 | if (target__none(&target) && !initial_delay) |
| 285 | attr->enable_on_exec = 1; |
| 286 | } |
| 287 | |
Jin Yao | 1d9f8d1 | 2017-12-05 22:03:10 +0800 | [diff] [blame] | 288 | if (target__has_cpu(&target) && !target__has_per_thread(&target)) |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 289 | return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); |
Stephane Eranian | 5622c07 | 2012-04-27 14:45:38 +0200 | [diff] [blame] | 290 | |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 291 | return perf_evsel__open_per_thread(evsel, evsel_list->threads); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 294 | /* |
| 295 | * Does the counter have nsecs as a unit? |
| 296 | */ |
Arnaldo Carvalho de Melo | daec78a | 2011-01-03 16:49:44 -0200 | [diff] [blame] | 297 | static inline int nsec_counter(struct perf_evsel *evsel) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 298 | { |
Arnaldo Carvalho de Melo | daec78a | 2011-01-03 16:49:44 -0200 | [diff] [blame] | 299 | if (perf_evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) || |
| 300 | perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK)) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 301 | return 1; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 306 | static int process_synthesized_event(struct perf_tool *tool __maybe_unused, |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 307 | union perf_event *event, |
| 308 | struct perf_sample *sample __maybe_unused, |
| 309 | struct machine *machine __maybe_unused) |
| 310 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 311 | if (perf_data__write(&perf_stat.data, event, event->header.size) < 0) { |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 312 | pr_err("failed to write perf data, error: %m\n"); |
| 313 | return -1; |
| 314 | } |
| 315 | |
| 316 | perf_stat.bytes_written += event->header.size; |
| 317 | return 0; |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 320 | static int write_stat_round_event(u64 tm, u64 type) |
Jiri Olsa | 7aad0c3 | 2015-11-05 15:40:52 +0100 | [diff] [blame] | 321 | { |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 322 | return perf_event__synthesize_stat_round(NULL, tm, type, |
Jiri Olsa | 7aad0c3 | 2015-11-05 15:40:52 +0100 | [diff] [blame] | 323 | process_synthesized_event, |
| 324 | NULL); |
| 325 | } |
| 326 | |
| 327 | #define WRITE_STAT_ROUND_EVENT(time, interval) \ |
| 328 | write_stat_round_event(time, PERF_STAT_ROUND_TYPE__ ## interval) |
| 329 | |
Jiri Olsa | 5a6ea81 | 2015-11-05 15:40:51 +0100 | [diff] [blame] | 330 | #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) |
| 331 | |
| 332 | static int |
| 333 | perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread, |
| 334 | struct perf_counts_values *count) |
| 335 | { |
| 336 | struct perf_sample_id *sid = SID(counter, cpu, thread); |
| 337 | |
| 338 | return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, |
| 339 | process_synthesized_event, NULL); |
| 340 | } |
| 341 | |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 342 | /* |
| 343 | * Read out the results of a single counter: |
| 344 | * do not aggregate counts across CPUs in system-wide mode |
| 345 | */ |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 346 | static int read_counter(struct perf_evsel *counter) |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 347 | { |
Jiri Olsa | 9bf1a52 | 2014-11-21 10:31:09 +0100 | [diff] [blame] | 348 | int nthreads = thread_map__nr(evsel_list->threads); |
Mark Rutland | 00e727b | 2016-07-15 11:08:10 +0100 | [diff] [blame] | 349 | int ncpus, cpu, thread; |
| 350 | |
Jin Yao | 1d9f8d1 | 2017-12-05 22:03:10 +0800 | [diff] [blame] | 351 | if (target__has_cpu(&target) && !target__has_per_thread(&target)) |
Mark Rutland | 00e727b | 2016-07-15 11:08:10 +0100 | [diff] [blame] | 352 | ncpus = perf_evsel__nr_cpus(counter); |
| 353 | else |
| 354 | ncpus = 1; |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 355 | |
Suzuki K. Poulose | 3b4331d | 2015-02-13 18:40:58 +0000 | [diff] [blame] | 356 | if (!counter->supported) |
| 357 | return -ENOENT; |
| 358 | |
Jiri Olsa | 9bf1a52 | 2014-11-21 10:31:09 +0100 | [diff] [blame] | 359 | if (counter->system_wide) |
| 360 | nthreads = 1; |
| 361 | |
| 362 | for (thread = 0; thread < nthreads; thread++) { |
| 363 | for (cpu = 0; cpu < ncpus; cpu++) { |
Jiri Olsa | 3b3eb04 | 2015-06-26 11:29:20 +0200 | [diff] [blame] | 364 | struct perf_counts_values *count; |
| 365 | |
| 366 | count = perf_counts(counter->counts, cpu, thread); |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * The leader's group read loads data into its group members |
| 370 | * (via perf_evsel__read_counter) and sets threir count->loaded. |
| 371 | */ |
| 372 | if (!count->loaded && |
| 373 | perf_evsel__read_counter(counter, cpu, thread)) { |
Stephane Eranian | db49a71 | 2017-04-12 11:23:01 -0700 | [diff] [blame] | 374 | counter->counts->scaled = -1; |
| 375 | perf_counts(counter->counts, cpu, thread)->ena = 0; |
| 376 | perf_counts(counter->counts, cpu, thread)->run = 0; |
Jiri Olsa | 9bf1a52 | 2014-11-21 10:31:09 +0100 | [diff] [blame] | 377 | return -1; |
Stephane Eranian | db49a71 | 2017-04-12 11:23:01 -0700 | [diff] [blame] | 378 | } |
Jiri Olsa | 5a6ea81 | 2015-11-05 15:40:51 +0100 | [diff] [blame] | 379 | |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 380 | count->loaded = false; |
| 381 | |
Jiri Olsa | 5a6ea81 | 2015-11-05 15:40:51 +0100 | [diff] [blame] | 382 | if (STAT_RECORD) { |
| 383 | if (perf_evsel__write_stat_event(counter, cpu, thread, count)) { |
| 384 | pr_err("failed to write stat event\n"); |
| 385 | return -1; |
| 386 | } |
| 387 | } |
Andi Kleen | 0b1abbf | 2016-04-27 13:00:51 -0700 | [diff] [blame] | 388 | |
| 389 | if (verbose > 1) { |
| 390 | fprintf(stat_config.output, |
| 391 | "%s: %d: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", |
| 392 | perf_evsel__name(counter), |
| 393 | cpu, |
| 394 | count->val, count->ena, count->run); |
| 395 | } |
Jiri Olsa | 9bf1a52 | 2014-11-21 10:31:09 +0100 | [diff] [blame] | 396 | } |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 397 | } |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 398 | |
| 399 | return 0; |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Mark Rutland | 3df33ef | 2016-08-09 14:04:29 +0100 | [diff] [blame] | 402 | static void read_counters(void) |
Jiri Olsa | 106a94a | 2015-06-26 11:29:19 +0200 | [diff] [blame] | 403 | { |
| 404 | struct perf_evsel *counter; |
Stephane Eranian | db49a71 | 2017-04-12 11:23:01 -0700 | [diff] [blame] | 405 | int ret; |
Jiri Olsa | 106a94a | 2015-06-26 11:29:19 +0200 | [diff] [blame] | 406 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 407 | evlist__for_each_entry(evsel_list, counter) { |
Stephane Eranian | db49a71 | 2017-04-12 11:23:01 -0700 | [diff] [blame] | 408 | ret = read_counter(counter); |
| 409 | if (ret) |
Andi Kleen | 245bad8 | 2015-09-01 15:52:46 -0700 | [diff] [blame] | 410 | pr_debug("failed to read counter %s\n", counter->name); |
Jiri Olsa | 3b3eb04 | 2015-06-26 11:29:20 +0200 | [diff] [blame] | 411 | |
Stephane Eranian | db49a71 | 2017-04-12 11:23:01 -0700 | [diff] [blame] | 412 | if (ret == 0 && perf_stat_process_counter(&stat_config, counter)) |
Jiri Olsa | 3b3eb04 | 2015-06-26 11:29:20 +0200 | [diff] [blame] | 413 | pr_warning("failed to process counter %s\n", counter->name); |
Jiri Olsa | 106a94a | 2015-06-26 11:29:19 +0200 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Jiri Olsa | ba411a9 | 2015-06-26 11:29:24 +0200 | [diff] [blame] | 417 | static void process_interval(void) |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 418 | { |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 419 | struct timespec ts, rs; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 420 | |
Mark Rutland | 3df33ef | 2016-08-09 14:04:29 +0100 | [diff] [blame] | 421 | read_counters(); |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 422 | |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 423 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 424 | diff_timespec(&rs, &ts, &ref_time); |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 425 | |
Jiri Olsa | 7aad0c3 | 2015-11-05 15:40:52 +0100 | [diff] [blame] | 426 | if (STAT_RECORD) { |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 427 | if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL)) |
Jiri Olsa | 7aad0c3 | 2015-11-05 15:40:52 +0100 | [diff] [blame] | 428 | pr_err("failed to write stat round event\n"); |
| 429 | } |
| 430 | |
Andi Kleen | b90f133 | 2017-08-31 12:40:36 -0700 | [diff] [blame] | 431 | init_stats(&walltime_nsecs_stats); |
| 432 | update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 433 | print_counters(&rs, 0, NULL); |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 436 | static void enable_counters(void) |
Andi Kleen | 4119168 | 2013-08-02 17:41:11 -0700 | [diff] [blame] | 437 | { |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 438 | if (initial_delay) |
Arnaldo Carvalho de Melo | 310ebb9 | 2016-08-08 14:57:04 -0300 | [diff] [blame] | 439 | usleep(initial_delay * USEC_PER_MSEC); |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * We need to enable counters only if: |
| 443 | * - we don't have tracee (attaching to task or cpu) |
| 444 | * - we have initial delay configured |
| 445 | */ |
| 446 | if (!target__none(&target) || initial_delay) |
Jiri Olsa | ab46db0 | 2015-12-03 10:06:43 +0100 | [diff] [blame] | 447 | perf_evlist__enable(evsel_list); |
Andi Kleen | 4119168 | 2013-08-02 17:41:11 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Mark Rutland | 3df33ef | 2016-08-09 14:04:29 +0100 | [diff] [blame] | 450 | static void disable_counters(void) |
| 451 | { |
| 452 | /* |
| 453 | * If we don't have tracee (attaching to task or cpu), counters may |
| 454 | * still be running. To get accurate group ratios, we must stop groups |
| 455 | * from counting before reading their constituent counters. |
| 456 | */ |
| 457 | if (!target__none(&target)) |
| 458 | perf_evlist__disable(evsel_list); |
| 459 | } |
| 460 | |
Arnaldo Carvalho de Melo | f33cbe7 | 2014-01-02 15:11:25 -0300 | [diff] [blame] | 461 | static volatile int workload_exec_errno; |
Arnaldo Carvalho de Melo | 6af206f | 2013-12-28 15:45:08 -0300 | [diff] [blame] | 462 | |
| 463 | /* |
| 464 | * perf_evlist__prepare_workload will send a SIGUSR1 |
| 465 | * if the fork fails, since we asked by setting its |
| 466 | * want_signal to true. |
| 467 | */ |
Arnaldo Carvalho de Melo | f33cbe7 | 2014-01-02 15:11:25 -0300 | [diff] [blame] | 468 | static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *info, |
| 469 | void *ucontext __maybe_unused) |
Arnaldo Carvalho de Melo | 6af206f | 2013-12-28 15:45:08 -0300 | [diff] [blame] | 470 | { |
Arnaldo Carvalho de Melo | f33cbe7 | 2014-01-02 15:11:25 -0300 | [diff] [blame] | 471 | workload_exec_errno = info->si_value.sival_int; |
Arnaldo Carvalho de Melo | 6af206f | 2013-12-28 15:45:08 -0300 | [diff] [blame] | 472 | } |
| 473 | |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 474 | static int perf_stat_synthesize_config(bool is_pipe) |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 475 | { |
| 476 | int err; |
| 477 | |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 478 | if (is_pipe) { |
| 479 | err = perf_event__synthesize_attrs(NULL, perf_stat.session, |
| 480 | process_synthesized_event); |
| 481 | if (err < 0) { |
| 482 | pr_err("Couldn't synthesize attrs.\n"); |
| 483 | return err; |
| 484 | } |
| 485 | } |
| 486 | |
Andi Kleen | bfd8f72 | 2017-11-17 13:42:58 -0800 | [diff] [blame] | 487 | err = perf_event__synthesize_extra_attr(NULL, |
| 488 | evsel_list, |
| 489 | process_synthesized_event, |
| 490 | is_pipe); |
Jiri Olsa | 7b60a7e | 2015-11-05 15:40:54 +0100 | [diff] [blame] | 491 | |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 492 | err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads, |
| 493 | process_synthesized_event, |
| 494 | NULL); |
| 495 | if (err < 0) { |
| 496 | pr_err("Couldn't synthesize thread map.\n"); |
| 497 | return err; |
| 498 | } |
| 499 | |
| 500 | err = perf_event__synthesize_cpu_map(NULL, evsel_list->cpus, |
| 501 | process_synthesized_event, NULL); |
| 502 | if (err < 0) { |
| 503 | pr_err("Couldn't synthesize thread map.\n"); |
| 504 | return err; |
| 505 | } |
| 506 | |
| 507 | err = perf_event__synthesize_stat_config(NULL, &stat_config, |
| 508 | process_synthesized_event, NULL); |
| 509 | if (err < 0) { |
| 510 | pr_err("Couldn't synthesize config.\n"); |
| 511 | return err; |
| 512 | } |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
Jiri Olsa | 2af4646 | 2015-11-05 15:40:49 +0100 | [diff] [blame] | 517 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
| 518 | |
Andi Kleen | 42811d5 | 2017-10-05 19:00:28 -0700 | [diff] [blame] | 519 | static int __store_counter_ids(struct perf_evsel *counter) |
Jiri Olsa | 2af4646 | 2015-11-05 15:40:49 +0100 | [diff] [blame] | 520 | { |
| 521 | int cpu, thread; |
| 522 | |
Andi Kleen | 42811d5 | 2017-10-05 19:00:28 -0700 | [diff] [blame] | 523 | for (cpu = 0; cpu < xyarray__max_x(counter->fd); cpu++) { |
| 524 | for (thread = 0; thread < xyarray__max_y(counter->fd); |
| 525 | thread++) { |
Jiri Olsa | 2af4646 | 2015-11-05 15:40:49 +0100 | [diff] [blame] | 526 | int fd = FD(counter, cpu, thread); |
| 527 | |
| 528 | if (perf_evlist__id_add_fd(evsel_list, counter, |
| 529 | cpu, thread, fd) < 0) |
| 530 | return -1; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static int store_counter_ids(struct perf_evsel *counter) |
| 538 | { |
| 539 | struct cpu_map *cpus = counter->cpus; |
| 540 | struct thread_map *threads = counter->threads; |
| 541 | |
| 542 | if (perf_evsel__alloc_id(counter, cpus->nr, threads->nr)) |
| 543 | return -ENOMEM; |
| 544 | |
Andi Kleen | 42811d5 | 2017-10-05 19:00:28 -0700 | [diff] [blame] | 545 | return __store_counter_ids(counter); |
Jiri Olsa | 2af4646 | 2015-11-05 15:40:49 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 548 | static bool perf_evsel__should_store_id(struct perf_evsel *counter) |
| 549 | { |
| 550 | return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID; |
| 551 | } |
| 552 | |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 553 | static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel) |
| 554 | { |
| 555 | struct perf_evsel *c2, *leader; |
| 556 | bool is_open = true; |
| 557 | |
| 558 | leader = evsel->leader; |
| 559 | pr_debug("Weak group for %s/%d failed\n", |
| 560 | leader->name, leader->nr_members); |
| 561 | |
| 562 | /* |
| 563 | * for_each_group_member doesn't work here because it doesn't |
| 564 | * include the first entry. |
| 565 | */ |
| 566 | evlist__for_each_entry(evsel_list, c2) { |
| 567 | if (c2 == evsel) |
| 568 | is_open = false; |
| 569 | if (c2->leader == leader) { |
| 570 | if (is_open) |
| 571 | perf_evsel__close(c2); |
| 572 | c2->leader = c2; |
| 573 | c2->nr_members = 0; |
| 574 | } |
| 575 | } |
| 576 | return leader; |
| 577 | } |
| 578 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 579 | static int __run_perf_stat(int argc, const char **argv, int run_idx) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 580 | { |
Jiri Olsa | ec0d3d1 | 2015-07-21 14:31:25 +0200 | [diff] [blame] | 581 | int interval = stat_config.interval; |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 582 | int times = stat_config.times; |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 583 | int timeout = stat_config.timeout; |
Arnaldo Carvalho de Melo | d6195a6 | 2017-02-13 16:45:24 -0300 | [diff] [blame] | 584 | char msg[BUFSIZ]; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 585 | unsigned long long t0, t1; |
Jiri Olsa | cac2142 | 2012-11-12 18:34:00 +0100 | [diff] [blame] | 586 | struct perf_evsel *counter; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 587 | struct timespec ts; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 588 | size_t l; |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 589 | int status = 0; |
Zhang, Yanmin | 6be2850 | 2010-03-18 11:36:03 -0300 | [diff] [blame] | 590 | const bool forks = (argc > 0); |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 591 | bool is_pipe = STAT_RECORD ? perf_stat.data.is_pipe : false; |
Mathieu Poirier | 5d8bb1e | 2016-09-16 09:50:03 -0600 | [diff] [blame] | 592 | struct perf_evsel_config_term *err_term; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 593 | |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 594 | if (interval) { |
Arnaldo Carvalho de Melo | 310ebb9 | 2016-08-08 14:57:04 -0300 | [diff] [blame] | 595 | ts.tv_sec = interval / USEC_PER_MSEC; |
| 596 | ts.tv_nsec = (interval % USEC_PER_MSEC) * NSEC_PER_MSEC; |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 597 | } else if (timeout) { |
| 598 | ts.tv_sec = timeout / USEC_PER_MSEC; |
| 599 | ts.tv_nsec = (timeout % USEC_PER_MSEC) * NSEC_PER_MSEC; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 600 | } else { |
| 601 | ts.tv_sec = 1; |
| 602 | ts.tv_nsec = 0; |
| 603 | } |
| 604 | |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 605 | if (forks) { |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 606 | if (perf_evlist__prepare_workload(evsel_list, &target, argv, is_pipe, |
Arnaldo Carvalho de Melo | 735f7e0 | 2014-01-03 14:56:49 -0300 | [diff] [blame] | 607 | workload_exec_failed_signal) < 0) { |
Namhyung Kim | acf2892 | 2013-03-11 16:43:18 +0900 | [diff] [blame] | 608 | perror("failed to prepare workload"); |
| 609 | return -1; |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 610 | } |
Namhyung Kim | d20a47e | 2013-09-30 18:01:11 +0900 | [diff] [blame] | 611 | child_pid = evsel_list->workload.pid; |
Paul Mackerras | 051ae7f | 2009-06-29 21:13:21 +1000 | [diff] [blame] | 612 | } |
| 613 | |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 614 | if (group) |
Arnaldo Carvalho de Melo | 63dab22 | 2012-08-14 16:35:48 -0300 | [diff] [blame] | 615 | perf_evlist__set_leader(evsel_list); |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 616 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 617 | evlist__for_each_entry(evsel_list, counter) { |
Arnaldo Carvalho de Melo | 42ef8a7 | 2016-05-12 16:25:18 -0300 | [diff] [blame] | 618 | try_again: |
Jiri Olsa | cac2142 | 2012-11-12 18:34:00 +0100 | [diff] [blame] | 619 | if (create_perf_stat_counter(counter) < 0) { |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 620 | |
| 621 | /* Weak group failed. Reset the group. */ |
Andi Kleen | 35c1980 | 2017-09-05 14:13:24 -0700 | [diff] [blame] | 622 | if ((errno == EINVAL || errno == EBADF) && |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 623 | counter->leader != counter && |
| 624 | counter->weak_group) { |
| 625 | counter = perf_evsel__reset_weak_group(counter); |
| 626 | goto try_again; |
| 627 | } |
| 628 | |
David Ahern | 979987a | 2012-05-08 09:29:16 -0600 | [diff] [blame] | 629 | /* |
| 630 | * PPC returns ENXIO for HW counters until 2.6.37 |
| 631 | * (behavior changed with commit b0a873e). |
| 632 | */ |
Anton Blanchard | 38f6ae1 | 2011-12-02 09:38:33 +1100 | [diff] [blame] | 633 | if (errno == EINVAL || errno == ENOSYS || |
David Ahern | 979987a | 2012-05-08 09:29:16 -0600 | [diff] [blame] | 634 | errno == ENOENT || errno == EOPNOTSUPP || |
| 635 | errno == ENXIO) { |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 636 | if (verbose > 0) |
David Ahern | c63ca0c | 2011-04-29 16:04:15 -0600 | [diff] [blame] | 637 | ui__warning("%s event is not supported by the kernel.\n", |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 638 | perf_evsel__name(counter)); |
David Ahern | 2cee77c | 2011-05-30 08:55:59 -0600 | [diff] [blame] | 639 | counter->supported = false; |
Kan Liang | cb5ef60 | 2015-06-11 02:32:40 -0400 | [diff] [blame] | 640 | |
| 641 | if ((counter->leader != counter) || |
| 642 | !(counter->leader->nr_members > 1)) |
| 643 | continue; |
Arnaldo Carvalho de Melo | 42ef8a7 | 2016-05-12 16:25:18 -0300 | [diff] [blame] | 644 | } else if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) { |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 645 | if (verbose > 0) |
Arnaldo Carvalho de Melo | 42ef8a7 | 2016-05-12 16:25:18 -0300 | [diff] [blame] | 646 | ui__warning("%s\n", msg); |
| 647 | goto try_again; |
Jin Yao | ab6c79b | 2018-01-16 23:43:08 +0800 | [diff] [blame] | 648 | } else if (target__has_per_thread(&target) && |
| 649 | evsel_list->threads && |
| 650 | evsel_list->threads->err_thread != -1) { |
| 651 | /* |
| 652 | * For global --per-thread case, skip current |
| 653 | * error thread. |
| 654 | */ |
| 655 | if (!thread_map__remove(evsel_list->threads, |
| 656 | evsel_list->threads->err_thread)) { |
| 657 | evsel_list->threads->err_thread = -1; |
| 658 | goto try_again; |
| 659 | } |
| 660 | } |
Ingo Molnar | ede7029 | 2011-04-28 08:48:42 +0200 | [diff] [blame] | 661 | |
Arnaldo Carvalho de Melo | 56e52e8 | 2012-12-13 15:10:58 -0300 | [diff] [blame] | 662 | perf_evsel__open_strerror(counter, &target, |
| 663 | errno, msg, sizeof(msg)); |
| 664 | ui__error("%s\n", msg); |
| 665 | |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 666 | if (child_pid != -1) |
| 667 | kill(child_pid, SIGTERM); |
David Ahern | fceda7f | 2012-08-26 12:24:44 -0600 | [diff] [blame] | 668 | |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 669 | return -1; |
| 670 | } |
David Ahern | 2cee77c | 2011-05-30 08:55:59 -0600 | [diff] [blame] | 671 | counter->supported = true; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 672 | |
| 673 | l = strlen(counter->unit); |
| 674 | if (l > unit_width) |
| 675 | unit_width = l; |
Jiri Olsa | 2af4646 | 2015-11-05 15:40:49 +0100 | [diff] [blame] | 676 | |
Jiri Olsa | 82bf311 | 2017-07-26 14:02:06 +0200 | [diff] [blame] | 677 | if (perf_evsel__should_store_id(counter) && |
| 678 | store_counter_ids(counter)) |
Jiri Olsa | 2af4646 | 2015-11-05 15:40:49 +0100 | [diff] [blame] | 679 | return -1; |
Arnaldo Carvalho de Melo | 084ab9f | 2010-03-22 13:10:28 -0300 | [diff] [blame] | 680 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 681 | |
Arnaldo Carvalho de Melo | 23d4aad | 2015-03-24 19:23:47 -0300 | [diff] [blame] | 682 | if (perf_evlist__apply_filters(evsel_list, &counter)) { |
Arnaldo Carvalho de Melo | 62d94b0 | 2017-06-27 11:22:31 -0300 | [diff] [blame] | 683 | pr_err("failed to set filter \"%s\" on event %s with %d (%s)\n", |
Arnaldo Carvalho de Melo | 23d4aad | 2015-03-24 19:23:47 -0300 | [diff] [blame] | 684 | counter->filter, perf_evsel__name(counter), errno, |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 685 | str_error_r(errno, msg, sizeof(msg))); |
Frederic Weisbecker | cfd748a | 2011-03-14 16:40:30 +0100 | [diff] [blame] | 686 | return -1; |
| 687 | } |
| 688 | |
Mathieu Poirier | 5d8bb1e | 2016-09-16 09:50:03 -0600 | [diff] [blame] | 689 | if (perf_evlist__apply_drv_configs(evsel_list, &counter, &err_term)) { |
Arnaldo Carvalho de Melo | 62d94b0 | 2017-06-27 11:22:31 -0300 | [diff] [blame] | 690 | pr_err("failed to set config \"%s\" on event %s with %d (%s)\n", |
Mathieu Poirier | 5d8bb1e | 2016-09-16 09:50:03 -0600 | [diff] [blame] | 691 | err_term->val.drv_cfg, perf_evsel__name(counter), errno, |
| 692 | str_error_r(errno, msg, sizeof(msg))); |
| 693 | return -1; |
| 694 | } |
| 695 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 696 | if (STAT_RECORD) { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 697 | int err, fd = perf_data__fd(&perf_stat.data); |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 698 | |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 699 | if (is_pipe) { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 700 | err = perf_header__write_pipe(perf_data__fd(&perf_stat.data)); |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 701 | } else { |
| 702 | err = perf_session__write_header(perf_stat.session, evsel_list, |
| 703 | fd, false); |
| 704 | } |
| 705 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 706 | if (err < 0) |
| 707 | return err; |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 708 | |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 709 | err = perf_stat_synthesize_config(is_pipe); |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 710 | if (err < 0) |
| 711 | return err; |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 714 | /* |
| 715 | * Enable counters and exec the command: |
| 716 | */ |
| 717 | t0 = rdclock(); |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 718 | clock_gettime(CLOCK_MONOTONIC, &ref_time); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 719 | |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 720 | if (forks) { |
Namhyung Kim | acf2892 | 2013-03-11 16:43:18 +0900 | [diff] [blame] | 721 | perf_evlist__start_workload(evsel_list); |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 722 | enable_counters(); |
Namhyung Kim | acf2892 | 2013-03-11 16:43:18 +0900 | [diff] [blame] | 723 | |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 724 | if (interval || timeout) { |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 725 | while (!waitpid(child_pid, &status, WNOHANG)) { |
| 726 | nanosleep(&ts, NULL); |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 727 | if (timeout) |
| 728 | break; |
Jiri Olsa | ba411a9 | 2015-06-26 11:29:24 +0200 | [diff] [blame] | 729 | process_interval(); |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 730 | if (interval_count && !(--times)) |
| 731 | break; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 732 | } |
| 733 | } |
Jiri Olsa | 0ce2da1 | 2018-06-05 14:13:13 +0200 | [diff] [blame] | 734 | wait4(child_pid, &status, 0, &ru_data); |
Arnaldo Carvalho de Melo | 6af206f | 2013-12-28 15:45:08 -0300 | [diff] [blame] | 735 | |
Arnaldo Carvalho de Melo | f33cbe7 | 2014-01-02 15:11:25 -0300 | [diff] [blame] | 736 | if (workload_exec_errno) { |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 737 | const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg)); |
Arnaldo Carvalho de Melo | f33cbe7 | 2014-01-02 15:11:25 -0300 | [diff] [blame] | 738 | pr_err("Workload failed: %s\n", emsg); |
Arnaldo Carvalho de Melo | 6af206f | 2013-12-28 15:45:08 -0300 | [diff] [blame] | 739 | return -1; |
Arnaldo Carvalho de Melo | f33cbe7 | 2014-01-02 15:11:25 -0300 | [diff] [blame] | 740 | } |
Arnaldo Carvalho de Melo | 6af206f | 2013-12-28 15:45:08 -0300 | [diff] [blame] | 741 | |
Andi Kleen | 33e49ea | 2011-09-15 14:31:40 -0700 | [diff] [blame] | 742 | if (WIFSIGNALED(status)) |
| 743 | psignal(WTERMSIG(status), argv[0]); |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 744 | } else { |
Jiri Olsa | 67ccdec | 2015-12-03 10:06:44 +0100 | [diff] [blame] | 745 | enable_counters(); |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 746 | while (!done) { |
| 747 | nanosleep(&ts, NULL); |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 748 | if (timeout) |
| 749 | break; |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 750 | if (interval) { |
Jiri Olsa | ba411a9 | 2015-06-26 11:29:24 +0200 | [diff] [blame] | 751 | process_interval(); |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 752 | if (interval_count && !(--times)) |
| 753 | break; |
| 754 | } |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 755 | } |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 756 | } |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 757 | |
Mark Rutland | 3df33ef | 2016-08-09 14:04:29 +0100 | [diff] [blame] | 758 | disable_counters(); |
| 759 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 760 | t1 = rdclock(); |
| 761 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 762 | if (walltime_run_table) |
| 763 | walltime_run[run_idx] = t1 - t0; |
| 764 | |
Peter Zijlstra | 9e9772c | 2009-09-04 15:36:08 +0200 | [diff] [blame] | 765 | update_stats(&walltime_nsecs_stats, t1 - t0); |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 766 | |
Mark Rutland | 3df33ef | 2016-08-09 14:04:29 +0100 | [diff] [blame] | 767 | /* |
| 768 | * Closing a group leader splits the group, and as we only disable |
| 769 | * group leaders, results in remaining events becoming enabled. To |
| 770 | * avoid arbitrary skew, we must read all counters before closing any |
| 771 | * group leaders. |
| 772 | */ |
| 773 | read_counters(); |
| 774 | perf_evlist__close(evsel_list); |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 775 | |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 776 | return WEXITSTATUS(status); |
| 777 | } |
| 778 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 779 | static int run_perf_stat(int argc, const char **argv, int run_idx) |
Peter Zijlstra | 1f16c57 | 2012-10-23 13:40:14 +0200 | [diff] [blame] | 780 | { |
| 781 | int ret; |
| 782 | |
| 783 | if (pre_cmd) { |
| 784 | ret = system(pre_cmd); |
| 785 | if (ret) |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | if (sync_run) |
| 790 | sync(); |
| 791 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 792 | ret = __run_perf_stat(argc, argv, run_idx); |
Peter Zijlstra | 1f16c57 | 2012-10-23 13:40:14 +0200 | [diff] [blame] | 793 | if (ret) |
| 794 | return ret; |
| 795 | |
| 796 | if (post_cmd) { |
| 797 | ret = system(post_cmd); |
| 798 | if (ret) |
| 799 | return ret; |
| 800 | } |
| 801 | |
| 802 | return ret; |
| 803 | } |
| 804 | |
Andi Kleen | d73515c | 2015-03-11 07:16:27 -0700 | [diff] [blame] | 805 | static void print_running(u64 run, u64 ena) |
| 806 | { |
| 807 | if (csv_output) { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 808 | fprintf(stat_config.output, "%s%" PRIu64 "%s%.2f", |
Andi Kleen | d73515c | 2015-03-11 07:16:27 -0700 | [diff] [blame] | 809 | csv_sep, |
| 810 | run, |
| 811 | csv_sep, |
| 812 | ena ? 100.0 * run / ena : 100.0); |
| 813 | } else if (run != ena) { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 814 | fprintf(stat_config.output, " (%.2f%%)", 100.0 * run / ena); |
Andi Kleen | d73515c | 2015-03-11 07:16:27 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
Ingo Molnar | f99844c | 2011-04-27 05:35:39 +0200 | [diff] [blame] | 818 | static void print_noise_pct(double total, double avg) |
| 819 | { |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 820 | double pct = rel_stddev_stats(total, avg); |
Ingo Molnar | f99844c | 2011-04-27 05:35:39 +0200 | [diff] [blame] | 821 | |
Zhengyu He | 3ae9a34d | 2011-06-23 13:45:42 -0700 | [diff] [blame] | 822 | if (csv_output) |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 823 | fprintf(stat_config.output, "%s%.2f%%", csv_sep, pct); |
Jim Cromie | a1bca6c | 2011-09-07 17:14:02 -0600 | [diff] [blame] | 824 | else if (pct) |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 825 | fprintf(stat_config.output, " ( +-%6.2f%% )", pct); |
Ingo Molnar | f99844c | 2011-04-27 05:35:39 +0200 | [diff] [blame] | 826 | } |
| 827 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 828 | static void print_noise(struct perf_evsel *evsel, double avg) |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 829 | { |
Jiri Olsa | 581cc8a | 2015-10-16 12:41:03 +0200 | [diff] [blame] | 830 | struct perf_stat_evsel *ps; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 831 | |
Peter Zijlstra | 849abde | 2009-09-04 18:23:38 +0200 | [diff] [blame] | 832 | if (run_count == 1) |
| 833 | return; |
| 834 | |
Arnaldo Carvalho de Melo | e669e83 | 2017-10-26 14:22:34 -0300 | [diff] [blame] | 835 | ps = evsel->stats; |
Ingo Molnar | f99844c | 2011-04-27 05:35:39 +0200 | [diff] [blame] | 836 | print_noise_pct(stddev_stats(&ps->res_stats[0]), avg); |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 837 | } |
| 838 | |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 839 | static void aggr_printout(struct perf_evsel *evsel, int id, int nr) |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 840 | { |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 841 | switch (stat_config.aggr_mode) { |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 842 | case AGGR_CORE: |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 843 | fprintf(stat_config.output, "S%d-C%*d%s%*d%s", |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 844 | cpu_map__id_to_socket(id), |
| 845 | csv_output ? 0 : -8, |
| 846 | cpu_map__id_to_cpu(id), |
| 847 | csv_sep, |
| 848 | csv_output ? 0 : 4, |
| 849 | nr, |
| 850 | csv_sep); |
| 851 | break; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 852 | case AGGR_SOCKET: |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 853 | fprintf(stat_config.output, "S%*d%s%*d%s", |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 854 | csv_output ? 0 : -5, |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 855 | id, |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 856 | csv_sep, |
| 857 | csv_output ? 0 : 4, |
| 858 | nr, |
| 859 | csv_sep); |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 860 | break; |
| 861 | case AGGR_NONE: |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 862 | fprintf(stat_config.output, "CPU%*d%s", |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 863 | csv_output ? 0 : -4, |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 864 | perf_evsel__cpus(evsel)->map[id], csv_sep); |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 865 | break; |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 866 | case AGGR_THREAD: |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 867 | fprintf(stat_config.output, "%*s-%*d%s", |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 868 | csv_output ? 0 : 16, |
| 869 | thread_map__comm(evsel->threads, id), |
| 870 | csv_output ? 0 : -8, |
| 871 | thread_map__pid(evsel->threads, id), |
| 872 | csv_sep); |
| 873 | break; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 874 | case AGGR_GLOBAL: |
Jiri Olsa | 208df99 | 2015-10-16 12:41:04 +0200 | [diff] [blame] | 875 | case AGGR_UNSET: |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 876 | default: |
| 877 | break; |
| 878 | } |
| 879 | } |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 880 | |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 881 | struct outstate { |
| 882 | FILE *fh; |
| 883 | bool newline; |
Andi Kleen | f948339 | 2016-01-30 09:06:50 -0800 | [diff] [blame] | 884 | const char *prefix; |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 885 | int nfields; |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 886 | int id, nr; |
| 887 | struct perf_evsel *evsel; |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 888 | }; |
| 889 | |
| 890 | #define METRIC_LEN 35 |
| 891 | |
| 892 | static void new_line_std(void *ctx) |
| 893 | { |
| 894 | struct outstate *os = ctx; |
| 895 | |
| 896 | os->newline = true; |
| 897 | } |
| 898 | |
| 899 | static void do_new_line_std(struct outstate *os) |
| 900 | { |
| 901 | fputc('\n', os->fh); |
Andi Kleen | f948339 | 2016-01-30 09:06:50 -0800 | [diff] [blame] | 902 | fputs(os->prefix, os->fh); |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 903 | aggr_printout(os->evsel, os->id, os->nr); |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 904 | if (stat_config.aggr_mode == AGGR_NONE) |
| 905 | fprintf(os->fh, " "); |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 906 | fprintf(os->fh, " "); |
| 907 | } |
| 908 | |
| 909 | static void print_metric_std(void *ctx, const char *color, const char *fmt, |
| 910 | const char *unit, double val) |
| 911 | { |
| 912 | struct outstate *os = ctx; |
| 913 | FILE *out = os->fh; |
| 914 | int n; |
| 915 | bool newline = os->newline; |
| 916 | |
| 917 | os->newline = false; |
| 918 | |
| 919 | if (unit == NULL || fmt == NULL) { |
| 920 | fprintf(out, "%-*s", METRIC_LEN, ""); |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | if (newline) |
| 925 | do_new_line_std(os); |
| 926 | |
| 927 | n = fprintf(out, " # "); |
| 928 | if (color) |
| 929 | n += color_fprintf(out, color, fmt, val); |
| 930 | else |
| 931 | n += fprintf(out, fmt, val); |
| 932 | fprintf(out, " %-*s", METRIC_LEN - n - 1, unit); |
| 933 | } |
| 934 | |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 935 | static void new_line_csv(void *ctx) |
| 936 | { |
| 937 | struct outstate *os = ctx; |
| 938 | int i; |
| 939 | |
| 940 | fputc('\n', os->fh); |
| 941 | if (os->prefix) |
| 942 | fprintf(os->fh, "%s%s", os->prefix, csv_sep); |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 943 | aggr_printout(os->evsel, os->id, os->nr); |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 944 | for (i = 0; i < os->nfields; i++) |
| 945 | fputs(csv_sep, os->fh); |
| 946 | } |
| 947 | |
| 948 | static void print_metric_csv(void *ctx, |
| 949 | const char *color __maybe_unused, |
| 950 | const char *fmt, const char *unit, double val) |
| 951 | { |
| 952 | struct outstate *os = ctx; |
| 953 | FILE *out = os->fh; |
| 954 | char buf[64], *vals, *ends; |
| 955 | |
| 956 | if (unit == NULL || fmt == NULL) { |
Ilya Pronin | 40c2189 | 2018-03-05 22:43:53 -0800 | [diff] [blame] | 957 | fprintf(out, "%s%s", csv_sep, csv_sep); |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 958 | return; |
| 959 | } |
| 960 | snprintf(buf, sizeof(buf), fmt, val); |
Taeung Song | b07c40d | 2017-04-07 23:24:18 +0900 | [diff] [blame] | 961 | ends = vals = ltrim(buf); |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 962 | while (isdigit(*ends) || *ends == '.') |
| 963 | ends++; |
| 964 | *ends = 0; |
| 965 | while (isspace(*unit)) |
| 966 | unit++; |
| 967 | fprintf(out, "%s%s%s%s", csv_sep, vals, csv_sep, unit); |
| 968 | } |
| 969 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 970 | #define METRIC_ONLY_LEN 20 |
| 971 | |
| 972 | /* Filter out some columns that don't work well in metrics only mode */ |
| 973 | |
| 974 | static bool valid_only_metric(const char *unit) |
| 975 | { |
| 976 | if (!unit) |
| 977 | return false; |
| 978 | if (strstr(unit, "/sec") || |
| 979 | strstr(unit, "hz") || |
| 980 | strstr(unit, "Hz") || |
| 981 | strstr(unit, "CPUs utilized")) |
| 982 | return false; |
| 983 | return true; |
| 984 | } |
| 985 | |
| 986 | static const char *fixunit(char *buf, struct perf_evsel *evsel, |
| 987 | const char *unit) |
| 988 | { |
| 989 | if (!strncmp(unit, "of all", 6)) { |
| 990 | snprintf(buf, 1024, "%s %s", perf_evsel__name(evsel), |
| 991 | unit); |
| 992 | return buf; |
| 993 | } |
| 994 | return unit; |
| 995 | } |
| 996 | |
| 997 | static void print_metric_only(void *ctx, const char *color, const char *fmt, |
| 998 | const char *unit, double val) |
| 999 | { |
| 1000 | struct outstate *os = ctx; |
| 1001 | FILE *out = os->fh; |
| 1002 | int n; |
| 1003 | char buf[1024]; |
| 1004 | unsigned mlen = METRIC_ONLY_LEN; |
| 1005 | |
| 1006 | if (!valid_only_metric(unit)) |
| 1007 | return; |
| 1008 | unit = fixunit(buf, os->evsel, unit); |
| 1009 | if (color) |
| 1010 | n = color_fprintf(out, color, fmt, val); |
| 1011 | else |
| 1012 | n = fprintf(out, fmt, val); |
| 1013 | if (n > METRIC_ONLY_LEN) |
| 1014 | n = METRIC_ONLY_LEN; |
| 1015 | if (mlen < strlen(unit)) |
| 1016 | mlen = strlen(unit) + 1; |
| 1017 | fprintf(out, "%*s", mlen - n, ""); |
| 1018 | } |
| 1019 | |
| 1020 | static void print_metric_only_csv(void *ctx, const char *color __maybe_unused, |
| 1021 | const char *fmt, |
| 1022 | const char *unit, double val) |
| 1023 | { |
| 1024 | struct outstate *os = ctx; |
| 1025 | FILE *out = os->fh; |
| 1026 | char buf[64], *vals, *ends; |
| 1027 | char tbuf[1024]; |
| 1028 | |
| 1029 | if (!valid_only_metric(unit)) |
| 1030 | return; |
| 1031 | unit = fixunit(tbuf, os->evsel, unit); |
| 1032 | snprintf(buf, sizeof buf, fmt, val); |
Taeung Song | b07c40d | 2017-04-07 23:24:18 +0900 | [diff] [blame] | 1033 | ends = vals = ltrim(buf); |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1034 | while (isdigit(*ends) || *ends == '.') |
| 1035 | ends++; |
| 1036 | *ends = 0; |
| 1037 | fprintf(out, "%s%s", vals, csv_sep); |
| 1038 | } |
| 1039 | |
| 1040 | static void new_line_metric(void *ctx __maybe_unused) |
| 1041 | { |
| 1042 | } |
| 1043 | |
| 1044 | static void print_metric_header(void *ctx, const char *color __maybe_unused, |
| 1045 | const char *fmt __maybe_unused, |
| 1046 | const char *unit, double val __maybe_unused) |
| 1047 | { |
| 1048 | struct outstate *os = ctx; |
| 1049 | char tbuf[1024]; |
| 1050 | |
| 1051 | if (!valid_only_metric(unit)) |
| 1052 | return; |
| 1053 | unit = fixunit(tbuf, os->evsel, unit); |
| 1054 | if (csv_output) |
| 1055 | fprintf(os->fh, "%s%s", unit, csv_sep); |
| 1056 | else |
| 1057 | fprintf(os->fh, "%-*s ", METRIC_ONLY_LEN, unit); |
| 1058 | } |
| 1059 | |
Andi Kleen | da88c7f | 2014-09-24 13:50:46 -0700 | [diff] [blame] | 1060 | static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg) |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1061 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1062 | FILE *output = stat_config.output; |
Arnaldo Carvalho de Melo | 310ebb9 | 2016-08-08 14:57:04 -0300 | [diff] [blame] | 1063 | double msecs = avg / NSEC_PER_MSEC; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1064 | const char *fmt_v, *fmt_n; |
David Ahern | 4bbe5a6 | 2013-09-28 14:28:00 -0600 | [diff] [blame] | 1065 | char name[25]; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1066 | |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1067 | fmt_v = csv_output ? "%.6f%s" : "%18.6f%s"; |
| 1068 | fmt_n = csv_output ? "%s" : "%-25s"; |
| 1069 | |
Andi Kleen | da88c7f | 2014-09-24 13:50:46 -0700 | [diff] [blame] | 1070 | aggr_printout(evsel, id, nr); |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1071 | |
David Ahern | 4bbe5a6 | 2013-09-28 14:28:00 -0600 | [diff] [blame] | 1072 | scnprintf(name, sizeof(name), "%s%s", |
| 1073 | perf_evsel__name(evsel), csv_output ? "" : " (msec)"); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1074 | |
| 1075 | fprintf(output, fmt_v, msecs, csv_sep); |
| 1076 | |
| 1077 | if (csv_output) |
| 1078 | fprintf(output, "%s%s", evsel->unit, csv_sep); |
| 1079 | else |
| 1080 | fprintf(output, "%-*s%s", unit_width, evsel->unit, csv_sep); |
| 1081 | |
| 1082 | fprintf(output, fmt_n, name); |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 1083 | |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 1084 | if (evsel->cgrp) |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 1085 | fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1088 | static int first_shadow_cpu(struct perf_evsel *evsel, int id) |
| 1089 | { |
| 1090 | int i; |
| 1091 | |
| 1092 | if (!aggr_get_id) |
| 1093 | return 0; |
| 1094 | |
| 1095 | if (stat_config.aggr_mode == AGGR_NONE) |
| 1096 | return id; |
| 1097 | |
| 1098 | if (stat_config.aggr_mode == AGGR_GLOBAL) |
| 1099 | return 0; |
| 1100 | |
| 1101 | for (i = 0; i < perf_evsel__nr_cpus(evsel); i++) { |
| 1102 | int cpu2 = perf_evsel__cpus(evsel)->map[i]; |
| 1103 | |
| 1104 | if (aggr_get_id(evsel_list->cpus, cpu2) == id) |
| 1105 | return cpu2; |
| 1106 | } |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1110 | static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) |
| 1111 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1112 | FILE *output = stat_config.output; |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1113 | double sc = evsel->scale; |
| 1114 | const char *fmt; |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1115 | |
| 1116 | if (csv_output) { |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 1117 | fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s"; |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1118 | } else { |
| 1119 | if (big_num) |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 1120 | fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s"; |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1121 | else |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 1122 | fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s"; |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | aggr_printout(evsel, id, nr); |
| 1126 | |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1127 | fprintf(output, fmt, avg, csv_sep); |
| 1128 | |
| 1129 | if (evsel->unit) |
| 1130 | fprintf(output, "%-*s%s", |
| 1131 | csv_output ? 0 : unit_width, |
| 1132 | evsel->unit, csv_sep); |
| 1133 | |
| 1134 | fprintf(output, "%-*s", csv_output ? 0 : 25, perf_evsel__name(evsel)); |
| 1135 | |
| 1136 | if (evsel->cgrp) |
| 1137 | fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); |
Andi Kleen | eedfcb4 | 2015-11-02 17:50:21 -0800 | [diff] [blame] | 1138 | } |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1139 | |
Kan Liang | 30060ea | 2018-04-24 11:20:11 -0700 | [diff] [blame] | 1140 | static bool is_mixed_hw_group(struct perf_evsel *counter) |
| 1141 | { |
| 1142 | struct perf_evlist *evlist = counter->evlist; |
| 1143 | u32 pmu_type = counter->attr.type; |
| 1144 | struct perf_evsel *pos; |
| 1145 | |
| 1146 | if (counter->nr_members < 2) |
| 1147 | return false; |
| 1148 | |
| 1149 | evlist__for_each_entry(evlist, pos) { |
| 1150 | /* software events can be part of any hardware group */ |
| 1151 | if (pos->attr.type == PERF_TYPE_SOFTWARE) |
| 1152 | continue; |
| 1153 | if (pmu_type == PERF_TYPE_SOFTWARE) { |
| 1154 | pmu_type = pos->attr.type; |
| 1155 | continue; |
| 1156 | } |
| 1157 | if (pmu_type != pos->attr.type) |
| 1158 | return true; |
| 1159 | } |
| 1160 | |
| 1161 | return false; |
| 1162 | } |
| 1163 | |
Andi Kleen | f948339 | 2016-01-30 09:06:50 -0800 | [diff] [blame] | 1164 | static void printout(int id, int nr, struct perf_evsel *counter, double uval, |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1165 | char *prefix, u64 run, u64 ena, double noise, |
| 1166 | struct runtime_stat *st) |
Andi Kleen | eedfcb4 | 2015-11-02 17:50:21 -0800 | [diff] [blame] | 1167 | { |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 1168 | struct perf_stat_output_ctx out; |
Andi Kleen | f948339 | 2016-01-30 09:06:50 -0800 | [diff] [blame] | 1169 | struct outstate os = { |
| 1170 | .fh = stat_config.output, |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1171 | .prefix = prefix ? prefix : "", |
| 1172 | .id = id, |
| 1173 | .nr = nr, |
| 1174 | .evsel = counter, |
Andi Kleen | f948339 | 2016-01-30 09:06:50 -0800 | [diff] [blame] | 1175 | }; |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 1176 | print_metric_t pm = print_metric_std; |
| 1177 | void (*nl)(void *); |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1178 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1179 | if (metric_only) { |
| 1180 | nl = new_line_metric; |
| 1181 | if (csv_output) |
| 1182 | pm = print_metric_only_csv; |
| 1183 | else |
| 1184 | pm = print_metric_only; |
| 1185 | } else |
| 1186 | nl = new_line_std; |
Andi Kleen | eedfcb4 | 2015-11-02 17:50:21 -0800 | [diff] [blame] | 1187 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1188 | if (csv_output && !metric_only) { |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 1189 | static int aggr_fields[] = { |
| 1190 | [AGGR_GLOBAL] = 0, |
| 1191 | [AGGR_THREAD] = 1, |
| 1192 | [AGGR_NONE] = 1, |
| 1193 | [AGGR_SOCKET] = 2, |
| 1194 | [AGGR_CORE] = 2, |
| 1195 | }; |
| 1196 | |
| 1197 | pm = print_metric_csv; |
| 1198 | nl = new_line_csv; |
| 1199 | os.nfields = 3; |
| 1200 | os.nfields += aggr_fields[stat_config.aggr_mode]; |
| 1201 | if (counter->cgrp) |
| 1202 | os.nfields++; |
| 1203 | } |
Andi Kleen | b002f3b | 2016-02-17 14:44:00 -0800 | [diff] [blame] | 1204 | if (run == 0 || ena == 0 || counter->counts->scaled == -1) { |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1205 | if (metric_only) { |
| 1206 | pm(&os, NULL, "", "", 0); |
| 1207 | return; |
| 1208 | } |
Andi Kleen | cb110f4 | 2016-01-30 09:06:51 -0800 | [diff] [blame] | 1209 | aggr_printout(counter, id, nr); |
| 1210 | |
| 1211 | fprintf(stat_config.output, "%*s%s", |
| 1212 | csv_output ? 0 : 18, |
| 1213 | counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, |
| 1214 | csv_sep); |
| 1215 | |
Kan Liang | 30060ea | 2018-04-24 11:20:11 -0700 | [diff] [blame] | 1216 | if (counter->supported) { |
Borislav Petkov | 02d492e | 2017-02-07 01:40:05 +0100 | [diff] [blame] | 1217 | print_free_counters_hint = 1; |
Kan Liang | 30060ea | 2018-04-24 11:20:11 -0700 | [diff] [blame] | 1218 | if (is_mixed_hw_group(counter)) |
| 1219 | print_mixed_hw_group_error = 1; |
| 1220 | } |
Borislav Petkov | 02d492e | 2017-02-07 01:40:05 +0100 | [diff] [blame] | 1221 | |
Andi Kleen | cb110f4 | 2016-01-30 09:06:51 -0800 | [diff] [blame] | 1222 | fprintf(stat_config.output, "%-*s%s", |
| 1223 | csv_output ? 0 : unit_width, |
| 1224 | counter->unit, csv_sep); |
| 1225 | |
| 1226 | fprintf(stat_config.output, "%*s", |
| 1227 | csv_output ? 0 : -25, |
| 1228 | perf_evsel__name(counter)); |
| 1229 | |
| 1230 | if (counter->cgrp) |
| 1231 | fprintf(stat_config.output, "%s%s", |
| 1232 | csv_sep, counter->cgrp->name); |
| 1233 | |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 1234 | if (!csv_output) |
| 1235 | pm(&os, NULL, NULL, "", 0); |
| 1236 | print_noise(counter, noise); |
Andi Kleen | cb110f4 | 2016-01-30 09:06:51 -0800 | [diff] [blame] | 1237 | print_running(run, ena); |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 1238 | if (csv_output) |
| 1239 | pm(&os, NULL, NULL, "", 0); |
Andi Kleen | cb110f4 | 2016-01-30 09:06:51 -0800 | [diff] [blame] | 1240 | return; |
| 1241 | } |
| 1242 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1243 | if (metric_only) |
| 1244 | /* nothing */; |
| 1245 | else if (nsec_counter(counter)) |
Andi Kleen | eedfcb4 | 2015-11-02 17:50:21 -0800 | [diff] [blame] | 1246 | nsec_printout(id, nr, counter, uval); |
| 1247 | else |
| 1248 | abs_printout(id, nr, counter, uval); |
| 1249 | |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 1250 | out.print_metric = pm; |
| 1251 | out.new_line = nl; |
| 1252 | out.ctx = &os; |
Andi Kleen | 37932c1 | 2017-03-20 13:17:08 -0700 | [diff] [blame] | 1253 | out.force_header = false; |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 1254 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1255 | if (csv_output && !metric_only) { |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 1256 | print_noise(counter, noise); |
| 1257 | print_running(run, ena); |
| 1258 | } |
| 1259 | |
| 1260 | perf_stat__print_shadow_stats(counter, uval, |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1261 | first_shadow_cpu(counter, id), |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1262 | &out, &metric_events, st); |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1263 | if (!csv_output && !metric_only) { |
Andi Kleen | 92a61f6 | 2016-02-29 14:36:21 -0800 | [diff] [blame] | 1264 | print_noise(counter, noise); |
| 1265 | print_running(run, ena); |
| 1266 | } |
Jiri Olsa | 556b1fb | 2015-06-03 16:25:56 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1269 | static void aggr_update_shadow(void) |
| 1270 | { |
| 1271 | int cpu, s2, id, s; |
| 1272 | u64 val; |
| 1273 | struct perf_evsel *counter; |
| 1274 | |
| 1275 | for (s = 0; s < aggr_map->nr; s++) { |
| 1276 | id = aggr_map->map[s]; |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1277 | evlist__for_each_entry(evsel_list, counter) { |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1278 | val = 0; |
| 1279 | for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { |
| 1280 | s2 = aggr_get_id(evsel_list->cpus, cpu); |
| 1281 | if (s2 != id) |
| 1282 | continue; |
| 1283 | val += perf_counts(counter->counts, cpu, 0)->val; |
| 1284 | } |
Jiri Olsa | 54830dd | 2017-01-23 22:42:56 +0100 | [diff] [blame] | 1285 | perf_stat__update_shadow_stats(counter, val, |
Jin Yao | 1fcd039 | 2017-12-05 22:03:04 +0800 | [diff] [blame] | 1286 | first_shadow_cpu(counter, id), |
| 1287 | &rt_stat); |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1292 | static void uniquify_event_name(struct perf_evsel *counter) |
| 1293 | { |
| 1294 | char *new_name; |
| 1295 | char *config; |
| 1296 | |
Kan Liang | 80ee8c5 | 2018-04-24 11:20:14 -0700 | [diff] [blame] | 1297 | if (counter->uniquified_name || |
| 1298 | !counter->pmu_name || !strncmp(counter->name, counter->pmu_name, |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1299 | strlen(counter->pmu_name))) |
| 1300 | return; |
| 1301 | |
| 1302 | config = strchr(counter->name, '/'); |
| 1303 | if (config) { |
| 1304 | if (asprintf(&new_name, |
| 1305 | "%s%s", counter->pmu_name, config) > 0) { |
| 1306 | free(counter->name); |
| 1307 | counter->name = new_name; |
| 1308 | } |
| 1309 | } else { |
| 1310 | if (asprintf(&new_name, |
| 1311 | "%s [%s]", counter->name, counter->pmu_name) > 0) { |
| 1312 | free(counter->name); |
| 1313 | counter->name = new_name; |
| 1314 | } |
| 1315 | } |
Kan Liang | 80ee8c5 | 2018-04-24 11:20:14 -0700 | [diff] [blame] | 1316 | |
| 1317 | counter->uniquified_name = true; |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1318 | } |
| 1319 | |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 1320 | static void collect_all_aliases(struct perf_evsel *counter, |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1321 | void (*cb)(struct perf_evsel *counter, void *data, |
| 1322 | bool first), |
| 1323 | void *data) |
| 1324 | { |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 1325 | struct perf_evsel *alias; |
| 1326 | |
| 1327 | alias = list_prepare_entry(counter, &(evsel_list->entries), node); |
| 1328 | list_for_each_entry_continue (alias, &evsel_list->entries, node) { |
| 1329 | if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) || |
| 1330 | alias->scale != counter->scale || |
| 1331 | alias->cgrp != counter->cgrp || |
| 1332 | strcmp(alias->unit, counter->unit) || |
| 1333 | nsec_counter(alias) != nsec_counter(counter)) |
| 1334 | break; |
| 1335 | alias->merged_stat = true; |
| 1336 | cb(alias, data, false); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | static bool collect_data(struct perf_evsel *counter, |
| 1341 | void (*cb)(struct perf_evsel *counter, void *data, |
| 1342 | bool first), |
| 1343 | void *data) |
| 1344 | { |
| 1345 | if (counter->merged_stat) |
| 1346 | return false; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1347 | cb(counter, data, true); |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1348 | if (no_merge) |
| 1349 | uniquify_event_name(counter); |
| 1350 | else if (counter->auto_merge_stats) |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 1351 | collect_all_aliases(counter, cb, data); |
| 1352 | return true; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | struct aggr_data { |
| 1356 | u64 ena, run, val; |
| 1357 | int id; |
| 1358 | int nr; |
| 1359 | int cpu; |
| 1360 | }; |
| 1361 | |
| 1362 | static void aggr_cb(struct perf_evsel *counter, void *data, bool first) |
| 1363 | { |
| 1364 | struct aggr_data *ad = data; |
| 1365 | int cpu, s2; |
| 1366 | |
| 1367 | for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { |
| 1368 | struct perf_counts_values *counts; |
| 1369 | |
| 1370 | s2 = aggr_get_id(perf_evsel__cpus(counter), cpu); |
| 1371 | if (s2 != ad->id) |
| 1372 | continue; |
| 1373 | if (first) |
| 1374 | ad->nr++; |
| 1375 | counts = perf_counts(counter->counts, cpu, 0); |
Andi Kleen | b4229e9 | 2017-03-20 13:17:01 -0700 | [diff] [blame] | 1376 | /* |
| 1377 | * When any result is bad, make them all to give |
| 1378 | * consistent output in interval mode. |
| 1379 | */ |
| 1380 | if (counts->ena == 0 || counts->run == 0 || |
| 1381 | counter->counts->scaled == -1) { |
| 1382 | ad->ena = 0; |
| 1383 | ad->run = 0; |
| 1384 | break; |
| 1385 | } |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1386 | ad->val += counts->val; |
| 1387 | ad->ena += counts->ena; |
| 1388 | ad->run += counts->run; |
| 1389 | } |
| 1390 | } |
| 1391 | |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1392 | static void print_aggr(char *prefix) |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1393 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1394 | FILE *output = stat_config.output; |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1395 | struct perf_evsel *counter; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1396 | int s, id, nr; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1397 | double uval; |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1398 | u64 ena, run, val; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1399 | bool first; |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1400 | |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1401 | if (!(aggr_map || aggr_get_id)) |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1402 | return; |
| 1403 | |
Andi Kleen | 44d49a6 | 2016-02-29 14:36:22 -0800 | [diff] [blame] | 1404 | aggr_update_shadow(); |
| 1405 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1406 | /* |
| 1407 | * With metric_only everything is on a single line. |
| 1408 | * Without each counter has its own line. |
| 1409 | */ |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1410 | for (s = 0; s < aggr_map->nr; s++) { |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1411 | struct aggr_data ad; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1412 | if (prefix && metric_only) |
| 1413 | fprintf(output, "%s", prefix); |
| 1414 | |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1415 | ad.id = id = aggr_map->map[s]; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1416 | first = true; |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1417 | evlist__for_each_entry(evsel_list, counter) { |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1418 | if (is_duration_time(counter)) |
| 1419 | continue; |
| 1420 | |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1421 | ad.val = ad.ena = ad.run = 0; |
| 1422 | ad.nr = 0; |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 1423 | if (!collect_data(counter, aggr_cb, &ad)) |
| 1424 | continue; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1425 | nr = ad.nr; |
| 1426 | ena = ad.ena; |
| 1427 | run = ad.run; |
| 1428 | val = ad.val; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1429 | if (first && metric_only) { |
| 1430 | first = false; |
| 1431 | aggr_printout(counter, id, nr); |
| 1432 | } |
| 1433 | if (prefix && !metric_only) |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1434 | fprintf(output, "%s", prefix); |
| 1435 | |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1436 | uval = val * counter->scale; |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1437 | printout(id, nr, counter, uval, prefix, run, ena, 1.0, |
| 1438 | &rt_stat); |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1439 | if (!metric_only) |
| 1440 | fputc('\n', output); |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1441 | } |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1442 | if (metric_only) |
| 1443 | fputc('\n', output); |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1447 | static int cmp_val(const void *a, const void *b) |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1448 | { |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1449 | return ((struct perf_aggr_thread_value *)b)->val - |
| 1450 | ((struct perf_aggr_thread_value *)a)->val; |
| 1451 | } |
| 1452 | |
| 1453 | static struct perf_aggr_thread_value *sort_aggr_thread( |
| 1454 | struct perf_evsel *counter, |
| 1455 | int nthreads, int ncpus, |
| 1456 | int *ret) |
| 1457 | { |
| 1458 | int cpu, thread, i = 0; |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1459 | double uval; |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1460 | struct perf_aggr_thread_value *buf; |
| 1461 | |
| 1462 | buf = calloc(nthreads, sizeof(struct perf_aggr_thread_value)); |
| 1463 | if (!buf) |
| 1464 | return NULL; |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1465 | |
| 1466 | for (thread = 0; thread < nthreads; thread++) { |
| 1467 | u64 ena = 0, run = 0, val = 0; |
| 1468 | |
| 1469 | for (cpu = 0; cpu < ncpus; cpu++) { |
| 1470 | val += perf_counts(counter->counts, cpu, thread)->val; |
| 1471 | ena += perf_counts(counter->counts, cpu, thread)->ena; |
| 1472 | run += perf_counts(counter->counts, cpu, thread)->run; |
| 1473 | } |
| 1474 | |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1475 | uval = val * counter->scale; |
| 1476 | |
| 1477 | /* |
| 1478 | * Skip value 0 when enabling --per-thread globally, |
| 1479 | * otherwise too many 0 output. |
| 1480 | */ |
| 1481 | if (uval == 0.0 && target__has_per_thread(&target)) |
| 1482 | continue; |
| 1483 | |
| 1484 | buf[i].counter = counter; |
| 1485 | buf[i].id = thread; |
| 1486 | buf[i].uval = uval; |
| 1487 | buf[i].val = val; |
| 1488 | buf[i].run = run; |
| 1489 | buf[i].ena = ena; |
| 1490 | i++; |
| 1491 | } |
| 1492 | |
| 1493 | qsort(buf, i, sizeof(struct perf_aggr_thread_value), cmp_val); |
| 1494 | |
| 1495 | if (ret) |
| 1496 | *ret = i; |
| 1497 | |
| 1498 | return buf; |
| 1499 | } |
| 1500 | |
| 1501 | static void print_aggr_thread(struct perf_evsel *counter, char *prefix) |
| 1502 | { |
| 1503 | FILE *output = stat_config.output; |
| 1504 | int nthreads = thread_map__nr(counter->threads); |
| 1505 | int ncpus = cpu_map__nr(counter->cpus); |
| 1506 | int thread, sorted_threads, id; |
| 1507 | struct perf_aggr_thread_value *buf; |
| 1508 | |
| 1509 | buf = sort_aggr_thread(counter, nthreads, ncpus, &sorted_threads); |
| 1510 | if (!buf) { |
| 1511 | perror("cannot sort aggr thread"); |
| 1512 | return; |
| 1513 | } |
| 1514 | |
| 1515 | for (thread = 0; thread < sorted_threads; thread++) { |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1516 | if (prefix) |
| 1517 | fprintf(output, "%s", prefix); |
| 1518 | |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1519 | id = buf[thread].id; |
Jin Yao | 14e72a2 | 2017-12-05 22:03:08 +0800 | [diff] [blame] | 1520 | if (stat_config.stats) |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1521 | printout(id, 0, buf[thread].counter, buf[thread].uval, |
| 1522 | prefix, buf[thread].run, buf[thread].ena, 1.0, |
| 1523 | &stat_config.stats[id]); |
Jin Yao | 14e72a2 | 2017-12-05 22:03:08 +0800 | [diff] [blame] | 1524 | else |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1525 | printout(id, 0, buf[thread].counter, buf[thread].uval, |
| 1526 | prefix, buf[thread].run, buf[thread].ena, 1.0, |
| 1527 | &rt_stat); |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1528 | fputc('\n', output); |
| 1529 | } |
Jin Yao | 2973455 | 2017-12-05 22:03:11 +0800 | [diff] [blame] | 1530 | |
| 1531 | free(buf); |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1532 | } |
| 1533 | |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1534 | struct caggr_data { |
| 1535 | double avg, avg_enabled, avg_running; |
| 1536 | }; |
| 1537 | |
| 1538 | static void counter_aggr_cb(struct perf_evsel *counter, void *data, |
| 1539 | bool first __maybe_unused) |
| 1540 | { |
| 1541 | struct caggr_data *cd = data; |
Arnaldo Carvalho de Melo | e669e83 | 2017-10-26 14:22:34 -0300 | [diff] [blame] | 1542 | struct perf_stat_evsel *ps = counter->stats; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1543 | |
| 1544 | cd->avg += avg_stats(&ps->res_stats[0]); |
| 1545 | cd->avg_enabled += avg_stats(&ps->res_stats[1]); |
| 1546 | cd->avg_running += avg_stats(&ps->res_stats[2]); |
| 1547 | } |
| 1548 | |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1549 | /* |
| 1550 | * Print out the results of a single counter: |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1551 | * aggregated counts in system-wide mode |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1552 | */ |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 1553 | static void print_counter_aggr(struct perf_evsel *counter, char *prefix) |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1554 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1555 | FILE *output = stat_config.output; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1556 | double uval; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1557 | struct caggr_data cd = { .avg = 0.0 }; |
Andi Kleen | d73515c | 2015-03-11 07:16:27 -0700 | [diff] [blame] | 1558 | |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 1559 | if (!collect_data(counter, counter_aggr_cb, &cd)) |
| 1560 | return; |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1561 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1562 | if (prefix && !metric_only) |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 1563 | fprintf(output, "%s", prefix); |
| 1564 | |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1565 | uval = cd.avg * counter->scale; |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1566 | printout(-1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled, |
| 1567 | cd.avg, &rt_stat); |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1568 | if (!metric_only) |
| 1569 | fprintf(output, "\n"); |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1570 | } |
| 1571 | |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1572 | static void counter_cb(struct perf_evsel *counter, void *data, |
| 1573 | bool first __maybe_unused) |
| 1574 | { |
| 1575 | struct aggr_data *ad = data; |
| 1576 | |
| 1577 | ad->val += perf_counts(counter->counts, ad->cpu, 0)->val; |
| 1578 | ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena; |
| 1579 | ad->run += perf_counts(counter->counts, ad->cpu, 0)->run; |
| 1580 | } |
| 1581 | |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1582 | /* |
| 1583 | * Print out the results of a single counter: |
| 1584 | * does not use aggregated count in system-wide |
| 1585 | */ |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 1586 | static void print_counter(struct perf_evsel *counter, char *prefix) |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1587 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1588 | FILE *output = stat_config.output; |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1589 | u64 ena, run, val; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1590 | double uval; |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1591 | int cpu; |
| 1592 | |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 1593 | for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1594 | struct aggr_data ad = { .cpu = cpu }; |
| 1595 | |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 1596 | if (!collect_data(counter, counter_cb, &ad)) |
| 1597 | return; |
Andi Kleen | fbe51fb | 2017-03-20 13:16:59 -0700 | [diff] [blame] | 1598 | val = ad.val; |
| 1599 | ena = ad.ena; |
| 1600 | run = ad.run; |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 1601 | |
| 1602 | if (prefix) |
| 1603 | fprintf(output, "%s", prefix); |
| 1604 | |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1605 | uval = val * counter->scale; |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1606 | printout(cpu, 0, counter, uval, prefix, run, ena, 1.0, |
| 1607 | &rt_stat); |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1608 | |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 1609 | fputc('\n', output); |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1610 | } |
| 1611 | } |
| 1612 | |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1613 | static void print_no_aggr_metric(char *prefix) |
| 1614 | { |
| 1615 | int cpu; |
| 1616 | int nrcpus = 0; |
| 1617 | struct perf_evsel *counter; |
| 1618 | u64 ena, run, val; |
| 1619 | double uval; |
| 1620 | |
| 1621 | nrcpus = evsel_list->cpus->nr; |
| 1622 | for (cpu = 0; cpu < nrcpus; cpu++) { |
| 1623 | bool first = true; |
| 1624 | |
| 1625 | if (prefix) |
| 1626 | fputs(prefix, stat_config.output); |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1627 | evlist__for_each_entry(evsel_list, counter) { |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1628 | if (is_duration_time(counter)) |
| 1629 | continue; |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1630 | if (first) { |
| 1631 | aggr_printout(counter, cpu, 0); |
| 1632 | first = false; |
| 1633 | } |
| 1634 | val = perf_counts(counter->counts, cpu, 0)->val; |
| 1635 | ena = perf_counts(counter->counts, cpu, 0)->ena; |
| 1636 | run = perf_counts(counter->counts, cpu, 0)->run; |
| 1637 | |
| 1638 | uval = val * counter->scale; |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1639 | printout(cpu, 0, counter, uval, prefix, run, ena, 1.0, |
| 1640 | &rt_stat); |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1641 | } |
| 1642 | fputc('\n', stat_config.output); |
| 1643 | } |
| 1644 | } |
| 1645 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1646 | static int aggr_header_lens[] = { |
| 1647 | [AGGR_CORE] = 18, |
| 1648 | [AGGR_SOCKET] = 12, |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1649 | [AGGR_NONE] = 6, |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1650 | [AGGR_THREAD] = 24, |
| 1651 | [AGGR_GLOBAL] = 0, |
| 1652 | }; |
| 1653 | |
Andi Kleen | c51fd63 | 2016-05-24 12:52:39 -0700 | [diff] [blame] | 1654 | static const char *aggr_header_csv[] = { |
| 1655 | [AGGR_CORE] = "core,cpus,", |
| 1656 | [AGGR_SOCKET] = "socket,cpus", |
| 1657 | [AGGR_NONE] = "cpu,", |
| 1658 | [AGGR_THREAD] = "comm-pid,", |
| 1659 | [AGGR_GLOBAL] = "" |
| 1660 | }; |
| 1661 | |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1662 | static void print_metric_headers(const char *prefix, bool no_indent) |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1663 | { |
| 1664 | struct perf_stat_output_ctx out; |
| 1665 | struct perf_evsel *counter; |
| 1666 | struct outstate os = { |
| 1667 | .fh = stat_config.output |
| 1668 | }; |
| 1669 | |
| 1670 | if (prefix) |
| 1671 | fprintf(stat_config.output, "%s", prefix); |
| 1672 | |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1673 | if (!csv_output && !no_indent) |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1674 | fprintf(stat_config.output, "%*s", |
| 1675 | aggr_header_lens[stat_config.aggr_mode], ""); |
Andi Kleen | c51fd63 | 2016-05-24 12:52:39 -0700 | [diff] [blame] | 1676 | if (csv_output) { |
| 1677 | if (stat_config.interval) |
| 1678 | fputs("time,", stat_config.output); |
| 1679 | fputs(aggr_header_csv[stat_config.aggr_mode], |
| 1680 | stat_config.output); |
| 1681 | } |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1682 | |
| 1683 | /* Print metrics headers only */ |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1684 | evlist__for_each_entry(evsel_list, counter) { |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1685 | if (is_duration_time(counter)) |
| 1686 | continue; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1687 | os.evsel = counter; |
| 1688 | out.ctx = &os; |
| 1689 | out.print_metric = print_metric_header; |
| 1690 | out.new_line = new_line_metric; |
Andi Kleen | 37932c1 | 2017-03-20 13:17:08 -0700 | [diff] [blame] | 1691 | out.force_header = true; |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1692 | os.evsel = counter; |
| 1693 | perf_stat__print_shadow_stats(counter, 0, |
| 1694 | 0, |
Andi Kleen | b18f3e3 | 2017-08-31 12:40:31 -0700 | [diff] [blame] | 1695 | &out, |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1696 | &metric_events, |
| 1697 | &rt_stat); |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1698 | } |
| 1699 | fputc('\n', stat_config.output); |
| 1700 | } |
| 1701 | |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1702 | static void print_interval(char *prefix, struct timespec *ts) |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1703 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1704 | FILE *output = stat_config.output; |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1705 | static int num_print_interval; |
| 1706 | |
| 1707 | sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep); |
| 1708 | |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1709 | if (num_print_interval == 0 && !csv_output) { |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 1710 | switch (stat_config.aggr_mode) { |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1711 | case AGGR_SOCKET: |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1712 | fprintf(output, "# time socket cpus"); |
| 1713 | if (!metric_only) |
| 1714 | fprintf(output, " counts %*s events\n", unit_width, "unit"); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1715 | break; |
| 1716 | case AGGR_CORE: |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1717 | fprintf(output, "# time core cpus"); |
| 1718 | if (!metric_only) |
| 1719 | fprintf(output, " counts %*s events\n", unit_width, "unit"); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1720 | break; |
| 1721 | case AGGR_NONE: |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1722 | fprintf(output, "# time CPU"); |
| 1723 | if (!metric_only) |
| 1724 | fprintf(output, " counts %*s events\n", unit_width, "unit"); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1725 | break; |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1726 | case AGGR_THREAD: |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1727 | fprintf(output, "# time comm-pid"); |
| 1728 | if (!metric_only) |
| 1729 | fprintf(output, " counts %*s events\n", unit_width, "unit"); |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1730 | break; |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1731 | case AGGR_GLOBAL: |
| 1732 | default: |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1733 | fprintf(output, "# time"); |
| 1734 | if (!metric_only) |
| 1735 | fprintf(output, " counts %*s events\n", unit_width, "unit"); |
Jiri Olsa | 208df99 | 2015-10-16 12:41:04 +0200 | [diff] [blame] | 1736 | case AGGR_UNSET: |
| 1737 | break; |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1738 | } |
| 1739 | } |
| 1740 | |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1741 | if (num_print_interval == 0 && metric_only) |
| 1742 | print_metric_headers(" ", true); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1743 | if (++num_print_interval == 25) |
| 1744 | num_print_interval = 0; |
| 1745 | } |
| 1746 | |
| 1747 | static void print_header(int argc, const char **argv) |
| 1748 | { |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1749 | FILE *output = stat_config.output; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1750 | int i; |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 1751 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1752 | fflush(stdout); |
| 1753 | |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 1754 | if (!csv_output) { |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 1755 | fprintf(output, "\n"); |
| 1756 | fprintf(output, " Performance counter stats for "); |
David Ahern | 62d3b61 | 2013-09-28 14:27:58 -0600 | [diff] [blame] | 1757 | if (target.system_wide) |
| 1758 | fprintf(output, "\'system wide"); |
| 1759 | else if (target.cpu_list) |
| 1760 | fprintf(output, "\'CPU(s) %s", target.cpu_list); |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 1761 | else if (!target__has_task(&target)) { |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 1762 | fprintf(output, "\'%s", argv ? argv[0] : "pipe"); |
| 1763 | for (i = 1; argv && (i < argc); i++) |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 1764 | fprintf(output, " %s", argv[i]); |
Namhyung Kim | 20f946b | 2012-04-26 14:15:16 +0900 | [diff] [blame] | 1765 | } else if (target.pid) |
| 1766 | fprintf(output, "process id \'%s", target.pid); |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 1767 | else |
Namhyung Kim | 20f946b | 2012-04-26 14:15:16 +0900 | [diff] [blame] | 1768 | fprintf(output, "thread id \'%s", target.tid); |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 1769 | |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 1770 | fprintf(output, "\'"); |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 1771 | if (run_count > 1) |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 1772 | fprintf(output, " (%d runs)", run_count); |
| 1773 | fprintf(output, ":\n\n"); |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 1774 | } |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
Jiri Olsa | bc22de9 | 2018-04-23 11:08:20 +0200 | [diff] [blame] | 1777 | static int get_precision(double num) |
| 1778 | { |
| 1779 | if (num > 1) |
| 1780 | return 0; |
| 1781 | |
| 1782 | return lround(ceil(-log10(num))); |
| 1783 | } |
| 1784 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 1785 | static void print_table(FILE *output, int precision, double avg) |
| 1786 | { |
| 1787 | char tmp[64]; |
| 1788 | int idx, indent = 0; |
| 1789 | |
| 1790 | scnprintf(tmp, 64, " %17.*f", precision, avg); |
| 1791 | while (tmp[indent] == ' ') |
| 1792 | indent++; |
| 1793 | |
| 1794 | fprintf(output, "%*s# Table of individual measurements:\n", indent, ""); |
| 1795 | |
| 1796 | for (idx = 0; idx < run_count; idx++) { |
| 1797 | double run = (double) walltime_run[idx] / NSEC_PER_SEC; |
Jiri Olsa | abc60ba | 2018-04-23 11:08:22 +0200 | [diff] [blame] | 1798 | int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5); |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 1799 | |
Jiri Olsa | abc60ba | 2018-04-23 11:08:22 +0200 | [diff] [blame] | 1800 | fprintf(output, " %17.*f (%+.*f) ", |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 1801 | precision, run, precision, run - avg); |
Jiri Olsa | abc60ba | 2018-04-23 11:08:22 +0200 | [diff] [blame] | 1802 | |
| 1803 | for (h = 0; h < n; h++) |
| 1804 | fprintf(output, "#"); |
| 1805 | |
| 1806 | fprintf(output, "\n"); |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | fprintf(output, "\n%*s# Final result:\n", indent, ""); |
| 1810 | } |
| 1811 | |
Jiri Olsa | 0ce2da1 | 2018-06-05 14:13:13 +0200 | [diff] [blame] | 1812 | static double timeval2double(struct timeval *t) |
| 1813 | { |
| 1814 | return t->tv_sec + (double) t->tv_usec/USEC_PER_SEC; |
| 1815 | } |
| 1816 | |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1817 | static void print_footer(void) |
| 1818 | { |
Jiri Olsa | bc22de9 | 2018-04-23 11:08:20 +0200 | [diff] [blame] | 1819 | double avg = avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC; |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1820 | FILE *output = stat_config.output; |
Andi Kleen | 918c7b06 | 2017-05-22 18:00:16 -0700 | [diff] [blame] | 1821 | int n; |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1822 | |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1823 | if (!null_run) |
| 1824 | fprintf(output, "\n"); |
Jiri Olsa | bc22de9 | 2018-04-23 11:08:20 +0200 | [diff] [blame] | 1825 | |
| 1826 | if (run_count == 1) { |
| 1827 | fprintf(output, " %17.9f seconds time elapsed", avg); |
Jiri Olsa | 0ce2da1 | 2018-06-05 14:13:13 +0200 | [diff] [blame] | 1828 | |
| 1829 | if (ru_display) { |
| 1830 | double ru_utime = timeval2double(&ru_data.ru_utime); |
| 1831 | double ru_stime = timeval2double(&ru_data.ru_stime); |
| 1832 | |
| 1833 | fprintf(output, "\n\n"); |
| 1834 | fprintf(output, " %17.9f seconds user\n", ru_utime); |
| 1835 | fprintf(output, " %17.9f seconds sys\n", ru_stime); |
| 1836 | } |
Jiri Olsa | bc22de9 | 2018-04-23 11:08:20 +0200 | [diff] [blame] | 1837 | } else { |
| 1838 | double sd = stddev_stats(&walltime_nsecs_stats) / NSEC_PER_SEC; |
| 1839 | /* |
| 1840 | * Display at most 2 more significant |
| 1841 | * digits than the stddev inaccuracy. |
| 1842 | */ |
| 1843 | int precision = get_precision(sd) + 2; |
| 1844 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 1845 | if (walltime_run_table) |
| 1846 | print_table(output, precision, avg); |
| 1847 | |
Jiri Olsa | bc22de9 | 2018-04-23 11:08:20 +0200 | [diff] [blame] | 1848 | fprintf(output, " %17.*f +- %.*f seconds time elapsed", |
| 1849 | precision, avg, precision, sd); |
| 1850 | |
| 1851 | print_noise_pct(sd, avg); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1852 | } |
| 1853 | fprintf(output, "\n\n"); |
Borislav Petkov | 02d492e | 2017-02-07 01:40:05 +0100 | [diff] [blame] | 1854 | |
Andi Kleen | 918c7b06 | 2017-05-22 18:00:16 -0700 | [diff] [blame] | 1855 | if (print_free_counters_hint && |
| 1856 | sysctl__read_int("kernel/nmi_watchdog", &n) >= 0 && |
| 1857 | n > 0) |
Borislav Petkov | 02d492e | 2017-02-07 01:40:05 +0100 | [diff] [blame] | 1858 | fprintf(output, |
| 1859 | "Some events weren't counted. Try disabling the NMI watchdog:\n" |
| 1860 | " echo 0 > /proc/sys/kernel/nmi_watchdog\n" |
| 1861 | " perf stat ...\n" |
| 1862 | " echo 1 > /proc/sys/kernel/nmi_watchdog\n"); |
Kan Liang | 30060ea | 2018-04-24 11:20:11 -0700 | [diff] [blame] | 1863 | |
| 1864 | if (print_mixed_hw_group_error) |
| 1865 | fprintf(output, |
| 1866 | "The events in group usually have to be from " |
| 1867 | "the same PMU. Try reorganizing the group.\n"); |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | static void print_counters(struct timespec *ts, int argc, const char **argv) |
| 1871 | { |
Jiri Olsa | ec0d3d1 | 2015-07-21 14:31:25 +0200 | [diff] [blame] | 1872 | int interval = stat_config.interval; |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1873 | struct perf_evsel *counter; |
| 1874 | char buf[64], *prefix = NULL; |
| 1875 | |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 1876 | /* Do not print anything if we record to the pipe. */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1877 | if (STAT_RECORD && perf_stat.data.is_pipe) |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 1878 | return; |
| 1879 | |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1880 | if (interval) |
| 1881 | print_interval(prefix = buf, ts); |
| 1882 | else |
| 1883 | print_header(argc, argv); |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 1884 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1885 | if (metric_only) { |
| 1886 | static int num_print_iv; |
| 1887 | |
Andi Kleen | 41c8ca2 | 2016-05-24 12:52:38 -0700 | [diff] [blame] | 1888 | if (num_print_iv == 0 && !interval) |
| 1889 | print_metric_headers(prefix, false); |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1890 | if (num_print_iv++ == 25) |
| 1891 | num_print_iv = 0; |
| 1892 | if (stat_config.aggr_mode == AGGR_GLOBAL && prefix) |
| 1893 | fprintf(stat_config.output, "%s", prefix); |
| 1894 | } |
| 1895 | |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 1896 | switch (stat_config.aggr_mode) { |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 1897 | case AGGR_CORE: |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1898 | case AGGR_SOCKET: |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1899 | print_aggr(prefix); |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1900 | break; |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1901 | case AGGR_THREAD: |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1902 | evlist__for_each_entry(evsel_list, counter) { |
| 1903 | if (is_duration_time(counter)) |
| 1904 | continue; |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1905 | print_aggr_thread(counter, prefix); |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1906 | } |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 1907 | break; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1908 | case AGGR_GLOBAL: |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1909 | evlist__for_each_entry(evsel_list, counter) { |
| 1910 | if (is_duration_time(counter)) |
| 1911 | continue; |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1912 | print_counter_aggr(counter, prefix); |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1913 | } |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 1914 | if (metric_only) |
| 1915 | fputc('\n', stat_config.output); |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1916 | break; |
| 1917 | case AGGR_NONE: |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1918 | if (metric_only) |
| 1919 | print_no_aggr_metric(prefix); |
| 1920 | else { |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1921 | evlist__for_each_entry(evsel_list, counter) { |
| 1922 | if (is_duration_time(counter)) |
| 1923 | continue; |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1924 | print_counter(counter, prefix); |
Andi Kleen | e864c5c | 2017-08-31 12:40:35 -0700 | [diff] [blame] | 1925 | } |
Andi Kleen | 206cab6 | 2016-03-03 15:57:37 -0800 | [diff] [blame] | 1926 | } |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1927 | break; |
Jiri Olsa | 208df99 | 2015-10-16 12:41:04 +0200 | [diff] [blame] | 1928 | case AGGR_UNSET: |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 1929 | default: |
| 1930 | break; |
Stephane Eranian | f5b4a9c3 | 2010-11-16 11:05:01 +0200 | [diff] [blame] | 1931 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1932 | |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 1933 | if (!interval && !csv_output) |
| 1934 | print_footer(); |
| 1935 | |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 1936 | fflush(stat_config.output); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1937 | } |
| 1938 | |
Peter Zijlstra | f7b7c26 | 2009-06-10 15:55:59 +0200 | [diff] [blame] | 1939 | static volatile int signr = -1; |
| 1940 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1941 | static void skip_signal(int signo) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1942 | { |
Jiri Olsa | ec0d3d1 | 2015-07-21 14:31:25 +0200 | [diff] [blame] | 1943 | if ((child_pid == -1) || stat_config.interval) |
Liming Wang | 60666c6 | 2009-12-31 16:05:50 +0800 | [diff] [blame] | 1944 | done = 1; |
| 1945 | |
Peter Zijlstra | f7b7c26 | 2009-06-10 15:55:59 +0200 | [diff] [blame] | 1946 | signr = signo; |
Stephane Eranian | d07f0b1 | 2013-06-04 17:44:26 +0200 | [diff] [blame] | 1947 | /* |
| 1948 | * render child_pid harmless |
| 1949 | * won't send SIGTERM to a random |
| 1950 | * process in case of race condition |
| 1951 | * and fast PID recycling |
| 1952 | */ |
| 1953 | child_pid = -1; |
Peter Zijlstra | f7b7c26 | 2009-06-10 15:55:59 +0200 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | static void sig_atexit(void) |
| 1957 | { |
Stephane Eranian | d07f0b1 | 2013-06-04 17:44:26 +0200 | [diff] [blame] | 1958 | sigset_t set, oset; |
| 1959 | |
| 1960 | /* |
| 1961 | * avoid race condition with SIGCHLD handler |
| 1962 | * in skip_signal() which is modifying child_pid |
| 1963 | * goal is to avoid send SIGTERM to a random |
| 1964 | * process |
| 1965 | */ |
| 1966 | sigemptyset(&set); |
| 1967 | sigaddset(&set, SIGCHLD); |
| 1968 | sigprocmask(SIG_BLOCK, &set, &oset); |
| 1969 | |
Chris Wilson | 933da83 | 2009-10-04 01:35:01 +0100 | [diff] [blame] | 1970 | if (child_pid != -1) |
| 1971 | kill(child_pid, SIGTERM); |
| 1972 | |
Stephane Eranian | d07f0b1 | 2013-06-04 17:44:26 +0200 | [diff] [blame] | 1973 | sigprocmask(SIG_SETMASK, &oset, NULL); |
| 1974 | |
Peter Zijlstra | f7b7c26 | 2009-06-10 15:55:59 +0200 | [diff] [blame] | 1975 | if (signr == -1) |
| 1976 | return; |
| 1977 | |
| 1978 | signal(signr, SIG_DFL); |
| 1979 | kill(getpid(), signr); |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1980 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1981 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1982 | static int stat__set_big_num(const struct option *opt __maybe_unused, |
| 1983 | const char *s __maybe_unused, int unset) |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 1984 | { |
| 1985 | big_num_opt = unset ? 0 : 1; |
| 1986 | return 0; |
| 1987 | } |
| 1988 | |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 1989 | static int enable_metric_only(const struct option *opt __maybe_unused, |
| 1990 | const char *s __maybe_unused, int unset) |
| 1991 | { |
| 1992 | force_metric_only = true; |
| 1993 | metric_only = !unset; |
| 1994 | return 0; |
| 1995 | } |
| 1996 | |
Andi Kleen | b18f3e3 | 2017-08-31 12:40:31 -0700 | [diff] [blame] | 1997 | static int parse_metric_groups(const struct option *opt, |
| 1998 | const char *str, |
| 1999 | int unset __maybe_unused) |
| 2000 | { |
| 2001 | return metricgroup__parse_groups(opt, str, &metric_events); |
| 2002 | } |
| 2003 | |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2004 | static const struct option stat_options[] = { |
| 2005 | OPT_BOOLEAN('T', "transaction", &transaction_run, |
| 2006 | "hardware transaction statistics"), |
| 2007 | OPT_CALLBACK('e', "event", &evsel_list, "event", |
| 2008 | "event selector. use 'perf list' to list available events", |
| 2009 | parse_events_option), |
| 2010 | OPT_CALLBACK(0, "filter", &evsel_list, "filter", |
| 2011 | "event filter", parse_filter), |
| 2012 | OPT_BOOLEAN('i', "no-inherit", &no_inherit, |
| 2013 | "child tasks do not inherit counters"), |
| 2014 | OPT_STRING('p', "pid", &target.pid, "pid", |
| 2015 | "stat events on existing process id"), |
| 2016 | OPT_STRING('t', "tid", &target.tid, "tid", |
| 2017 | "stat events on existing thread id"), |
| 2018 | OPT_BOOLEAN('a', "all-cpus", &target.system_wide, |
| 2019 | "system-wide collection from all CPUs"), |
| 2020 | OPT_BOOLEAN('g', "group", &group, |
| 2021 | "put the counters into a counter group"), |
| 2022 | OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), |
| 2023 | OPT_INCR('v', "verbose", &verbose, |
| 2024 | "be more verbose (show counter open errors, etc)"), |
| 2025 | OPT_INTEGER('r', "repeat", &run_count, |
| 2026 | "repeat command and print average + stddev (max: 100, forever: 0)"), |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 2027 | OPT_BOOLEAN(0, "table", &walltime_run_table, |
| 2028 | "display details about each run (only with -r option)"), |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2029 | OPT_BOOLEAN('n', "null", &null_run, |
| 2030 | "null run - dont start any counters"), |
| 2031 | OPT_INCR('d', "detailed", &detailed_run, |
| 2032 | "detailed run - start a lot of events"), |
| 2033 | OPT_BOOLEAN('S', "sync", &sync_run, |
| 2034 | "call sync() before starting a run"), |
| 2035 | OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, |
| 2036 | "print large numbers with thousands\' separators", |
| 2037 | stat__set_big_num), |
| 2038 | OPT_STRING('C', "cpu", &target.cpu_list, "cpu", |
| 2039 | "list of cpus to monitor in system-wide"), |
| 2040 | OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, |
| 2041 | "disable CPU count aggregation", AGGR_NONE), |
Andi Kleen | 430daf2 | 2017-03-20 13:17:00 -0700 | [diff] [blame] | 2042 | OPT_BOOLEAN(0, "no-merge", &no_merge, "Do not merge identical named events"), |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2043 | OPT_STRING('x', "field-separator", &csv_sep, "separator", |
| 2044 | "print counts with custom separator"), |
| 2045 | OPT_CALLBACK('G', "cgroup", &evsel_list, "name", |
| 2046 | "monitor event in cgroup name only", parse_cgroups), |
| 2047 | OPT_STRING('o', "output", &output_name, "file", "output file name"), |
| 2048 | OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), |
| 2049 | OPT_INTEGER(0, "log-fd", &output_fd, |
| 2050 | "log output to fd, instead of stderr"), |
| 2051 | OPT_STRING(0, "pre", &pre_cmd, "command", |
| 2052 | "command to run prior to the measured command"), |
| 2053 | OPT_STRING(0, "post", &post_cmd, "command", |
| 2054 | "command to run after to the measured command"), |
| 2055 | OPT_UINTEGER('I', "interval-print", &stat_config.interval, |
Alexey Budankov | 9dc9a95 | 2018-04-03 21:18:33 +0300 | [diff] [blame] | 2056 | "print counts at regular interval in ms " |
| 2057 | "(overhead is possible for values <= 100ms)"), |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 2058 | OPT_INTEGER(0, "interval-count", &stat_config.times, |
| 2059 | "print counts for fixed number of times"), |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 2060 | OPT_UINTEGER(0, "timeout", &stat_config.timeout, |
| 2061 | "stop workload and print counts after a timeout period in ms (>= 10ms)"), |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2062 | OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, |
| 2063 | "aggregate counts per processor socket", AGGR_SOCKET), |
| 2064 | OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, |
| 2065 | "aggregate counts per physical processor core", AGGR_CORE), |
| 2066 | OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, |
| 2067 | "aggregate counts per thread", AGGR_THREAD), |
| 2068 | OPT_UINTEGER('D', "delay", &initial_delay, |
| 2069 | "ms to wait before starting measurement after program start"), |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 2070 | OPT_CALLBACK_NOOPT(0, "metric-only", &metric_only, NULL, |
| 2071 | "Only print computed metrics. No raw values", enable_metric_only), |
| 2072 | OPT_BOOLEAN(0, "topdown", &topdown_run, |
| 2073 | "measure topdown level 1 statistics"), |
Kan Liang | daefd0b | 2017-05-26 12:05:38 -0700 | [diff] [blame] | 2074 | OPT_BOOLEAN(0, "smi-cost", &smi_cost, |
| 2075 | "measure SMI cost"), |
Andi Kleen | b18f3e3 | 2017-08-31 12:40:31 -0700 | [diff] [blame] | 2076 | OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list", |
| 2077 | "monitor specified metrics or metric groups (separated by ,)", |
| 2078 | parse_metric_groups), |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2079 | OPT_END() |
| 2080 | }; |
| 2081 | |
Jiri Olsa | 1fe7a30 | 2015-10-16 12:41:15 +0200 | [diff] [blame] | 2082 | static int perf_stat__get_socket(struct cpu_map *map, int cpu) |
| 2083 | { |
| 2084 | return cpu_map__get_socket(map, cpu, NULL); |
| 2085 | } |
| 2086 | |
| 2087 | static int perf_stat__get_core(struct cpu_map *map, int cpu) |
| 2088 | { |
| 2089 | return cpu_map__get_core(map, cpu, NULL); |
| 2090 | } |
| 2091 | |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 2092 | static int cpu_map__get_max(struct cpu_map *map) |
| 2093 | { |
| 2094 | int i, max = -1; |
| 2095 | |
| 2096 | for (i = 0; i < map->nr; i++) { |
| 2097 | if (map->map[i] > max) |
| 2098 | max = map->map[i]; |
| 2099 | } |
| 2100 | |
| 2101 | return max; |
| 2102 | } |
| 2103 | |
| 2104 | static struct cpu_map *cpus_aggr_map; |
| 2105 | |
| 2106 | static int perf_stat__get_aggr(aggr_get_id_t get_id, struct cpu_map *map, int idx) |
| 2107 | { |
| 2108 | int cpu; |
| 2109 | |
| 2110 | if (idx >= map->nr) |
| 2111 | return -1; |
| 2112 | |
| 2113 | cpu = map->map[idx]; |
| 2114 | |
| 2115 | if (cpus_aggr_map->map[cpu] == -1) |
| 2116 | cpus_aggr_map->map[cpu] = get_id(map, idx); |
| 2117 | |
| 2118 | return cpus_aggr_map->map[cpu]; |
| 2119 | } |
| 2120 | |
| 2121 | static int perf_stat__get_socket_cached(struct cpu_map *map, int idx) |
| 2122 | { |
| 2123 | return perf_stat__get_aggr(perf_stat__get_socket, map, idx); |
| 2124 | } |
| 2125 | |
| 2126 | static int perf_stat__get_core_cached(struct cpu_map *map, int idx) |
| 2127 | { |
| 2128 | return perf_stat__get_aggr(perf_stat__get_core, map, idx); |
| 2129 | } |
| 2130 | |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 2131 | static int perf_stat_init_aggr_mode(void) |
| 2132 | { |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 2133 | int nr; |
| 2134 | |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 2135 | switch (stat_config.aggr_mode) { |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 2136 | case AGGR_SOCKET: |
| 2137 | if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) { |
| 2138 | perror("cannot build socket map"); |
| 2139 | return -1; |
| 2140 | } |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 2141 | aggr_get_id = perf_stat__get_socket_cached; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 2142 | break; |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 2143 | case AGGR_CORE: |
| 2144 | if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) { |
| 2145 | perror("cannot build core map"); |
| 2146 | return -1; |
| 2147 | } |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 2148 | aggr_get_id = perf_stat__get_core_cached; |
Stephane Eranian | 12c08a9 | 2013-02-14 13:57:29 +0100 | [diff] [blame] | 2149 | break; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 2150 | case AGGR_NONE: |
| 2151 | case AGGR_GLOBAL: |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 2152 | case AGGR_THREAD: |
Jiri Olsa | 208df99 | 2015-10-16 12:41:04 +0200 | [diff] [blame] | 2153 | case AGGR_UNSET: |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 2154 | default: |
| 2155 | break; |
| 2156 | } |
Jiri Olsa | 1e5a293 | 2015-10-25 15:51:18 +0100 | [diff] [blame] | 2157 | |
| 2158 | /* |
| 2159 | * The evsel_list->cpus is the base we operate on, |
| 2160 | * taking the highest cpu number to be the size of |
| 2161 | * the aggregation translate cpumap. |
| 2162 | */ |
| 2163 | nr = cpu_map__get_max(evsel_list->cpus); |
| 2164 | cpus_aggr_map = cpu_map__empty_new(nr + 1); |
| 2165 | return cpus_aggr_map ? 0 : -ENOMEM; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 2166 | } |
| 2167 | |
Masami Hiramatsu | 544c2ae | 2015-12-09 11:11:27 +0900 | [diff] [blame] | 2168 | static void perf_stat__exit_aggr_mode(void) |
| 2169 | { |
| 2170 | cpu_map__put(aggr_map); |
| 2171 | cpu_map__put(cpus_aggr_map); |
| 2172 | aggr_map = NULL; |
| 2173 | cpus_aggr_map = NULL; |
| 2174 | } |
| 2175 | |
Jiri Olsa | 68d702f | 2015-11-05 15:40:58 +0100 | [diff] [blame] | 2176 | static inline int perf_env__get_cpu(struct perf_env *env, struct cpu_map *map, int idx) |
| 2177 | { |
| 2178 | int cpu; |
| 2179 | |
| 2180 | if (idx > map->nr) |
| 2181 | return -1; |
| 2182 | |
| 2183 | cpu = map->map[idx]; |
| 2184 | |
Jan Stancek | da8a58b | 2017-02-17 12:10:26 +0100 | [diff] [blame] | 2185 | if (cpu >= env->nr_cpus_avail) |
Jiri Olsa | 68d702f | 2015-11-05 15:40:58 +0100 | [diff] [blame] | 2186 | return -1; |
| 2187 | |
| 2188 | return cpu; |
| 2189 | } |
| 2190 | |
| 2191 | static int perf_env__get_socket(struct cpu_map *map, int idx, void *data) |
| 2192 | { |
| 2193 | struct perf_env *env = data; |
| 2194 | int cpu = perf_env__get_cpu(env, map, idx); |
| 2195 | |
| 2196 | return cpu == -1 ? -1 : env->cpu[cpu].socket_id; |
| 2197 | } |
| 2198 | |
| 2199 | static int perf_env__get_core(struct cpu_map *map, int idx, void *data) |
| 2200 | { |
| 2201 | struct perf_env *env = data; |
| 2202 | int core = -1, cpu = perf_env__get_cpu(env, map, idx); |
| 2203 | |
| 2204 | if (cpu != -1) { |
| 2205 | int socket_id = env->cpu[cpu].socket_id; |
| 2206 | |
| 2207 | /* |
| 2208 | * Encode socket in upper 16 bits |
| 2209 | * core_id is relative to socket, and |
| 2210 | * we need a global id. So we combine |
| 2211 | * socket + core id. |
| 2212 | */ |
| 2213 | core = (socket_id << 16) | (env->cpu[cpu].core_id & 0xffff); |
| 2214 | } |
| 2215 | |
| 2216 | return core; |
| 2217 | } |
| 2218 | |
| 2219 | static int perf_env__build_socket_map(struct perf_env *env, struct cpu_map *cpus, |
| 2220 | struct cpu_map **sockp) |
| 2221 | { |
| 2222 | return cpu_map__build_map(cpus, sockp, perf_env__get_socket, env); |
| 2223 | } |
| 2224 | |
| 2225 | static int perf_env__build_core_map(struct perf_env *env, struct cpu_map *cpus, |
| 2226 | struct cpu_map **corep) |
| 2227 | { |
| 2228 | return cpu_map__build_map(cpus, corep, perf_env__get_core, env); |
| 2229 | } |
| 2230 | |
| 2231 | static int perf_stat__get_socket_file(struct cpu_map *map, int idx) |
| 2232 | { |
| 2233 | return perf_env__get_socket(map, idx, &perf_stat.session->header.env); |
| 2234 | } |
| 2235 | |
| 2236 | static int perf_stat__get_core_file(struct cpu_map *map, int idx) |
| 2237 | { |
| 2238 | return perf_env__get_core(map, idx, &perf_stat.session->header.env); |
| 2239 | } |
| 2240 | |
| 2241 | static int perf_stat_init_aggr_mode_file(struct perf_stat *st) |
| 2242 | { |
| 2243 | struct perf_env *env = &st->session->header.env; |
| 2244 | |
| 2245 | switch (stat_config.aggr_mode) { |
| 2246 | case AGGR_SOCKET: |
| 2247 | if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) { |
| 2248 | perror("cannot build socket map"); |
| 2249 | return -1; |
| 2250 | } |
| 2251 | aggr_get_id = perf_stat__get_socket_file; |
| 2252 | break; |
| 2253 | case AGGR_CORE: |
| 2254 | if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) { |
| 2255 | perror("cannot build core map"); |
| 2256 | return -1; |
| 2257 | } |
| 2258 | aggr_get_id = perf_stat__get_core_file; |
| 2259 | break; |
| 2260 | case AGGR_NONE: |
| 2261 | case AGGR_GLOBAL: |
| 2262 | case AGGR_THREAD: |
| 2263 | case AGGR_UNSET: |
| 2264 | default: |
| 2265 | break; |
| 2266 | } |
| 2267 | |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 2271 | static int topdown_filter_events(const char **attr, char **str, bool use_group) |
| 2272 | { |
| 2273 | int off = 0; |
| 2274 | int i; |
| 2275 | int len = 0; |
| 2276 | char *s; |
| 2277 | |
| 2278 | for (i = 0; attr[i]; i++) { |
| 2279 | if (pmu_have_event("cpu", attr[i])) { |
| 2280 | len += strlen(attr[i]) + 1; |
| 2281 | attr[i - off] = attr[i]; |
| 2282 | } else |
| 2283 | off++; |
| 2284 | } |
| 2285 | attr[i - off] = NULL; |
| 2286 | |
| 2287 | *str = malloc(len + 1 + 2); |
| 2288 | if (!*str) |
| 2289 | return -1; |
| 2290 | s = *str; |
| 2291 | if (i - off == 0) { |
| 2292 | *s = 0; |
| 2293 | return 0; |
| 2294 | } |
| 2295 | if (use_group) |
| 2296 | *s++ = '{'; |
| 2297 | for (i = 0; attr[i]; i++) { |
| 2298 | strcpy(s, attr[i]); |
| 2299 | s += strlen(s); |
| 2300 | *s++ = ','; |
| 2301 | } |
| 2302 | if (use_group) { |
| 2303 | s[-1] = '}'; |
| 2304 | *s = 0; |
| 2305 | } else |
| 2306 | s[-1] = 0; |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | __weak bool arch_topdown_check_group(bool *warn) |
| 2311 | { |
| 2312 | *warn = false; |
| 2313 | return false; |
| 2314 | } |
| 2315 | |
| 2316 | __weak void arch_topdown_group_warn(void) |
| 2317 | { |
| 2318 | } |
| 2319 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2320 | /* |
| 2321 | * Add default attributes, if there were no attributes specified or |
| 2322 | * if -d/--detailed, -d -d or -d -d -d is used: |
| 2323 | */ |
| 2324 | static int add_default_attributes(void) |
| 2325 | { |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 2326 | int err; |
Andi Kleen | 9dec447 | 2016-02-26 16:27:56 -0800 | [diff] [blame] | 2327 | struct perf_event_attr default_attrs0[] = { |
Arnaldo Carvalho de Melo | b070a547 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 2328 | |
| 2329 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK }, |
| 2330 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES }, |
| 2331 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS }, |
| 2332 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS }, |
| 2333 | |
| 2334 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES }, |
Andi Kleen | 9dec447 | 2016-02-26 16:27:56 -0800 | [diff] [blame] | 2335 | }; |
| 2336 | struct perf_event_attr frontend_attrs[] = { |
Arnaldo Carvalho de Melo | b070a547 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 2337 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND }, |
Andi Kleen | 9dec447 | 2016-02-26 16:27:56 -0800 | [diff] [blame] | 2338 | }; |
| 2339 | struct perf_event_attr backend_attrs[] = { |
Arnaldo Carvalho de Melo | b070a547 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 2340 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_BACKEND }, |
Andi Kleen | 9dec447 | 2016-02-26 16:27:56 -0800 | [diff] [blame] | 2341 | }; |
| 2342 | struct perf_event_attr default_attrs1[] = { |
Arnaldo Carvalho de Melo | b070a547 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 2343 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS }, |
| 2344 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS }, |
| 2345 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES }, |
| 2346 | |
| 2347 | }; |
| 2348 | |
| 2349 | /* |
| 2350 | * Detailed stats (-d), covering the L1 and last level data caches: |
| 2351 | */ |
| 2352 | struct perf_event_attr detailed_attrs[] = { |
| 2353 | |
| 2354 | { .type = PERF_TYPE_HW_CACHE, |
| 2355 | .config = |
| 2356 | PERF_COUNT_HW_CACHE_L1D << 0 | |
| 2357 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2358 | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, |
| 2359 | |
| 2360 | { .type = PERF_TYPE_HW_CACHE, |
| 2361 | .config = |
| 2362 | PERF_COUNT_HW_CACHE_L1D << 0 | |
| 2363 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2364 | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, |
| 2365 | |
| 2366 | { .type = PERF_TYPE_HW_CACHE, |
| 2367 | .config = |
| 2368 | PERF_COUNT_HW_CACHE_LL << 0 | |
| 2369 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2370 | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, |
| 2371 | |
| 2372 | { .type = PERF_TYPE_HW_CACHE, |
| 2373 | .config = |
| 2374 | PERF_COUNT_HW_CACHE_LL << 0 | |
| 2375 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2376 | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, |
| 2377 | }; |
| 2378 | |
| 2379 | /* |
| 2380 | * Very detailed stats (-d -d), covering the instruction cache and the TLB caches: |
| 2381 | */ |
| 2382 | struct perf_event_attr very_detailed_attrs[] = { |
| 2383 | |
| 2384 | { .type = PERF_TYPE_HW_CACHE, |
| 2385 | .config = |
| 2386 | PERF_COUNT_HW_CACHE_L1I << 0 | |
| 2387 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2388 | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, |
| 2389 | |
| 2390 | { .type = PERF_TYPE_HW_CACHE, |
| 2391 | .config = |
| 2392 | PERF_COUNT_HW_CACHE_L1I << 0 | |
| 2393 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2394 | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, |
| 2395 | |
| 2396 | { .type = PERF_TYPE_HW_CACHE, |
| 2397 | .config = |
| 2398 | PERF_COUNT_HW_CACHE_DTLB << 0 | |
| 2399 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2400 | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, |
| 2401 | |
| 2402 | { .type = PERF_TYPE_HW_CACHE, |
| 2403 | .config = |
| 2404 | PERF_COUNT_HW_CACHE_DTLB << 0 | |
| 2405 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2406 | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, |
| 2407 | |
| 2408 | { .type = PERF_TYPE_HW_CACHE, |
| 2409 | .config = |
| 2410 | PERF_COUNT_HW_CACHE_ITLB << 0 | |
| 2411 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2412 | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, |
| 2413 | |
| 2414 | { .type = PERF_TYPE_HW_CACHE, |
| 2415 | .config = |
| 2416 | PERF_COUNT_HW_CACHE_ITLB << 0 | |
| 2417 | (PERF_COUNT_HW_CACHE_OP_READ << 8) | |
| 2418 | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, |
| 2419 | |
| 2420 | }; |
| 2421 | |
| 2422 | /* |
| 2423 | * Very, very detailed stats (-d -d -d), adding prefetch events: |
| 2424 | */ |
| 2425 | struct perf_event_attr very_very_detailed_attrs[] = { |
| 2426 | |
| 2427 | { .type = PERF_TYPE_HW_CACHE, |
| 2428 | .config = |
| 2429 | PERF_COUNT_HW_CACHE_L1D << 0 | |
| 2430 | (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | |
| 2431 | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, |
| 2432 | |
| 2433 | { .type = PERF_TYPE_HW_CACHE, |
| 2434 | .config = |
| 2435 | PERF_COUNT_HW_CACHE_L1D << 0 | |
| 2436 | (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | |
| 2437 | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, |
| 2438 | }; |
| 2439 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2440 | /* Set attrs if no event is selected and !null_run: */ |
| 2441 | if (null_run) |
| 2442 | return 0; |
| 2443 | |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 2444 | if (transaction_run) { |
Thomas Richter | fca32340 | 2018-03-08 15:57:35 +0100 | [diff] [blame] | 2445 | struct parse_events_error errinfo; |
| 2446 | |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 2447 | if (pmu_have_event("cpu", "cycles-ct") && |
| 2448 | pmu_have_event("cpu", "el-start")) |
Thomas Richter | fca32340 | 2018-03-08 15:57:35 +0100 | [diff] [blame] | 2449 | err = parse_events(evsel_list, transaction_attrs, |
| 2450 | &errinfo); |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 2451 | else |
Thomas Richter | fca32340 | 2018-03-08 15:57:35 +0100 | [diff] [blame] | 2452 | err = parse_events(evsel_list, |
| 2453 | transaction_limited_attrs, |
| 2454 | &errinfo); |
Jiri Olsa | a454742 | 2015-06-03 16:25:53 +0200 | [diff] [blame] | 2455 | if (err) { |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 2456 | fprintf(stderr, "Cannot set up transaction events\n"); |
| 2457 | return -1; |
| 2458 | } |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
Kan Liang | daefd0b | 2017-05-26 12:05:38 -0700 | [diff] [blame] | 2462 | if (smi_cost) { |
| 2463 | int smi; |
| 2464 | |
| 2465 | if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) { |
| 2466 | fprintf(stderr, "freeze_on_smi is not supported.\n"); |
| 2467 | return -1; |
| 2468 | } |
| 2469 | |
| 2470 | if (!smi) { |
| 2471 | if (sysfs__write_int(FREEZE_ON_SMI_PATH, 1) < 0) { |
| 2472 | fprintf(stderr, "Failed to set freeze_on_smi.\n"); |
| 2473 | return -1; |
| 2474 | } |
| 2475 | smi_reset = true; |
| 2476 | } |
| 2477 | |
| 2478 | if (pmu_have_event("msr", "aperf") && |
| 2479 | pmu_have_event("msr", "smi")) { |
| 2480 | if (!force_metric_only) |
| 2481 | metric_only = true; |
| 2482 | err = parse_events(evsel_list, smi_cost_attrs, NULL); |
| 2483 | } else { |
| 2484 | fprintf(stderr, "To measure SMI cost, it needs " |
| 2485 | "msr/aperf/, msr/smi/ and cpu/cycles/ support\n"); |
| 2486 | return -1; |
| 2487 | } |
| 2488 | if (err) { |
| 2489 | fprintf(stderr, "Cannot set up SMI cost events\n"); |
| 2490 | return -1; |
| 2491 | } |
| 2492 | return 0; |
| 2493 | } |
| 2494 | |
Andi Kleen | 44b1e60 | 2016-05-30 12:49:42 -0300 | [diff] [blame] | 2495 | if (topdown_run) { |
| 2496 | char *str = NULL; |
| 2497 | bool warn = false; |
| 2498 | |
| 2499 | if (stat_config.aggr_mode != AGGR_GLOBAL && |
| 2500 | stat_config.aggr_mode != AGGR_CORE) { |
| 2501 | pr_err("top down event configuration requires --per-core mode\n"); |
| 2502 | return -1; |
| 2503 | } |
| 2504 | stat_config.aggr_mode = AGGR_CORE; |
| 2505 | if (nr_cgroups || !target__has_cpu(&target)) { |
| 2506 | pr_err("top down event configuration requires system-wide mode (-a)\n"); |
| 2507 | return -1; |
| 2508 | } |
| 2509 | |
| 2510 | if (!force_metric_only) |
| 2511 | metric_only = true; |
| 2512 | if (topdown_filter_events(topdown_attrs, &str, |
| 2513 | arch_topdown_check_group(&warn)) < 0) { |
| 2514 | pr_err("Out of memory\n"); |
| 2515 | return -1; |
| 2516 | } |
| 2517 | if (topdown_attrs[0] && str) { |
| 2518 | if (warn) |
| 2519 | arch_topdown_group_warn(); |
| 2520 | err = parse_events(evsel_list, str, NULL); |
| 2521 | if (err) { |
| 2522 | fprintf(stderr, |
| 2523 | "Cannot set up top down events %s: %d\n", |
| 2524 | str, err); |
| 2525 | free(str); |
| 2526 | return -1; |
| 2527 | } |
| 2528 | } else { |
| 2529 | fprintf(stderr, "System does not support topdown\n"); |
| 2530 | return -1; |
| 2531 | } |
| 2532 | free(str); |
| 2533 | } |
| 2534 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2535 | if (!evsel_list->nr_entries) { |
Namhyung Kim | a1f3d56 | 2016-05-13 15:01:03 +0900 | [diff] [blame] | 2536 | if (target__has_cpu(&target)) |
| 2537 | default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK; |
| 2538 | |
Andi Kleen | 9dec447 | 2016-02-26 16:27:56 -0800 | [diff] [blame] | 2539 | if (perf_evlist__add_default_attrs(evsel_list, default_attrs0) < 0) |
| 2540 | return -1; |
| 2541 | if (pmu_have_event("cpu", "stalled-cycles-frontend")) { |
| 2542 | if (perf_evlist__add_default_attrs(evsel_list, |
| 2543 | frontend_attrs) < 0) |
| 2544 | return -1; |
| 2545 | } |
| 2546 | if (pmu_have_event("cpu", "stalled-cycles-backend")) { |
| 2547 | if (perf_evlist__add_default_attrs(evsel_list, |
| 2548 | backend_attrs) < 0) |
| 2549 | return -1; |
| 2550 | } |
| 2551 | if (perf_evlist__add_default_attrs(evsel_list, default_attrs1) < 0) |
Arnaldo Carvalho de Melo | 50d08e4 | 2011-11-04 09:10:59 -0200 | [diff] [blame] | 2552 | return -1; |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | /* Detailed events get appended to the event list: */ |
| 2556 | |
| 2557 | if (detailed_run < 1) |
| 2558 | return 0; |
| 2559 | |
| 2560 | /* Append detailed run extra attributes: */ |
Arnaldo Carvalho de Melo | 79695e1 | 2012-05-30 13:53:54 -0300 | [diff] [blame] | 2561 | if (perf_evlist__add_default_attrs(evsel_list, detailed_attrs) < 0) |
Arnaldo Carvalho de Melo | 50d08e4 | 2011-11-04 09:10:59 -0200 | [diff] [blame] | 2562 | return -1; |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2563 | |
| 2564 | if (detailed_run < 2) |
| 2565 | return 0; |
| 2566 | |
| 2567 | /* Append very detailed run extra attributes: */ |
Arnaldo Carvalho de Melo | 79695e1 | 2012-05-30 13:53:54 -0300 | [diff] [blame] | 2568 | if (perf_evlist__add_default_attrs(evsel_list, very_detailed_attrs) < 0) |
Arnaldo Carvalho de Melo | 50d08e4 | 2011-11-04 09:10:59 -0200 | [diff] [blame] | 2569 | return -1; |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2570 | |
| 2571 | if (detailed_run < 3) |
| 2572 | return 0; |
| 2573 | |
| 2574 | /* Append very, very detailed run extra attributes: */ |
Arnaldo Carvalho de Melo | 79695e1 | 2012-05-30 13:53:54 -0300 | [diff] [blame] | 2575 | return perf_evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 2576 | } |
| 2577 | |
Jiri Olsa | 8a59f3c | 2016-01-12 10:35:29 +0100 | [diff] [blame] | 2578 | static const char * const stat_record_usage[] = { |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2579 | "perf stat record [<options>]", |
| 2580 | NULL, |
| 2581 | }; |
| 2582 | |
Jiri Olsa | 3ba78bd | 2015-11-05 15:40:47 +0100 | [diff] [blame] | 2583 | static void init_features(struct perf_session *session) |
| 2584 | { |
| 2585 | int feat; |
| 2586 | |
| 2587 | for (feat = HEADER_FIRST_FEATURE; feat < HEADER_LAST_FEATURE; feat++) |
| 2588 | perf_header__set_feat(&session->header, feat); |
| 2589 | |
| 2590 | perf_header__clear_feat(&session->header, HEADER_BUILD_ID); |
| 2591 | perf_header__clear_feat(&session->header, HEADER_TRACING_DATA); |
| 2592 | perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK); |
| 2593 | perf_header__clear_feat(&session->header, HEADER_AUXTRACE); |
| 2594 | } |
| 2595 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2596 | static int __cmd_record(int argc, const char **argv) |
| 2597 | { |
| 2598 | struct perf_session *session; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2599 | struct perf_data *data = &perf_stat.data; |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2600 | |
Jiri Olsa | 8a59f3c | 2016-01-12 10:35:29 +0100 | [diff] [blame] | 2601 | argc = parse_options(argc, argv, stat_options, stat_record_usage, |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2602 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 2603 | |
| 2604 | if (output_name) |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 2605 | data->file.path = output_name; |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2606 | |
Jiri Olsa | e9d6db8e8 | 2015-11-05 15:40:53 +0100 | [diff] [blame] | 2607 | if (run_count != 1 || forever) { |
| 2608 | pr_err("Cannot use -r option with perf stat record.\n"); |
| 2609 | return -1; |
| 2610 | } |
| 2611 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2612 | session = perf_session__new(data, false, NULL); |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2613 | if (session == NULL) { |
| 2614 | pr_err("Perf session creation failed.\n"); |
| 2615 | return -1; |
| 2616 | } |
| 2617 | |
Jiri Olsa | 3ba78bd | 2015-11-05 15:40:47 +0100 | [diff] [blame] | 2618 | init_features(session); |
| 2619 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2620 | session->evlist = evsel_list; |
| 2621 | perf_stat.session = session; |
| 2622 | perf_stat.record = true; |
| 2623 | return argc; |
| 2624 | } |
| 2625 | |
Jiri Olsa | a56f939 | 2015-11-05 15:40:59 +0100 | [diff] [blame] | 2626 | static int process_stat_round_event(struct perf_tool *tool __maybe_unused, |
| 2627 | union perf_event *event, |
| 2628 | struct perf_session *session) |
| 2629 | { |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 2630 | struct stat_round_event *stat_round = &event->stat_round; |
Jiri Olsa | a56f939 | 2015-11-05 15:40:59 +0100 | [diff] [blame] | 2631 | struct perf_evsel *counter; |
| 2632 | struct timespec tsh, *ts = NULL; |
| 2633 | const char **argv = session->header.env.cmdline_argv; |
| 2634 | int argc = session->header.env.nr_cmdline; |
| 2635 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2636 | evlist__for_each_entry(evsel_list, counter) |
Jiri Olsa | a56f939 | 2015-11-05 15:40:59 +0100 | [diff] [blame] | 2637 | perf_stat_process_counter(&stat_config, counter); |
| 2638 | |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 2639 | if (stat_round->type == PERF_STAT_ROUND_TYPE__FINAL) |
| 2640 | update_stats(&walltime_nsecs_stats, stat_round->time); |
Jiri Olsa | a56f939 | 2015-11-05 15:40:59 +0100 | [diff] [blame] | 2641 | |
Andi Kleen | e3b03b6 | 2016-05-05 16:04:03 -0700 | [diff] [blame] | 2642 | if (stat_config.interval && stat_round->time) { |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 2643 | tsh.tv_sec = stat_round->time / NSEC_PER_SEC; |
| 2644 | tsh.tv_nsec = stat_round->time % NSEC_PER_SEC; |
Jiri Olsa | a56f939 | 2015-11-05 15:40:59 +0100 | [diff] [blame] | 2645 | ts = &tsh; |
| 2646 | } |
| 2647 | |
| 2648 | print_counters(ts, argc, argv); |
| 2649 | return 0; |
| 2650 | } |
| 2651 | |
Jiri Olsa | 62ba18b | 2015-11-05 15:40:57 +0100 | [diff] [blame] | 2652 | static |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 2653 | int process_stat_config_event(struct perf_tool *tool, |
Jiri Olsa | 62ba18b | 2015-11-05 15:40:57 +0100 | [diff] [blame] | 2654 | union perf_event *event, |
| 2655 | struct perf_session *session __maybe_unused) |
| 2656 | { |
Jiri Olsa | 68d702f | 2015-11-05 15:40:58 +0100 | [diff] [blame] | 2657 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); |
| 2658 | |
Jiri Olsa | 62ba18b | 2015-11-05 15:40:57 +0100 | [diff] [blame] | 2659 | perf_event__read_stat_config(&stat_config, &event->stat_config); |
Jiri Olsa | 68d702f | 2015-11-05 15:40:58 +0100 | [diff] [blame] | 2660 | |
Jiri Olsa | 89af4e0 | 2015-11-05 15:41:02 +0100 | [diff] [blame] | 2661 | if (cpu_map__empty(st->cpus)) { |
| 2662 | if (st->aggr_mode != AGGR_UNSET) |
| 2663 | pr_warning("warning: processing task data, aggregation mode not set\n"); |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
| 2667 | if (st->aggr_mode != AGGR_UNSET) |
| 2668 | stat_config.aggr_mode = st->aggr_mode; |
| 2669 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2670 | if (perf_stat.data.is_pipe) |
Jiri Olsa | 68d702f | 2015-11-05 15:40:58 +0100 | [diff] [blame] | 2671 | perf_stat_init_aggr_mode(); |
| 2672 | else |
| 2673 | perf_stat_init_aggr_mode_file(st); |
| 2674 | |
Jiri Olsa | 62ba18b | 2015-11-05 15:40:57 +0100 | [diff] [blame] | 2675 | return 0; |
| 2676 | } |
| 2677 | |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 2678 | static int set_maps(struct perf_stat *st) |
| 2679 | { |
| 2680 | if (!st->cpus || !st->threads) |
| 2681 | return 0; |
| 2682 | |
| 2683 | if (WARN_ONCE(st->maps_allocated, "stats double allocation\n")) |
| 2684 | return -EINVAL; |
| 2685 | |
| 2686 | perf_evlist__set_maps(evsel_list, st->cpus, st->threads); |
| 2687 | |
| 2688 | if (perf_evlist__alloc_stats(evsel_list, true)) |
| 2689 | return -ENOMEM; |
| 2690 | |
| 2691 | st->maps_allocated = true; |
| 2692 | return 0; |
| 2693 | } |
| 2694 | |
| 2695 | static |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 2696 | int process_thread_map_event(struct perf_tool *tool, |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 2697 | union perf_event *event, |
| 2698 | struct perf_session *session __maybe_unused) |
| 2699 | { |
| 2700 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); |
| 2701 | |
| 2702 | if (st->threads) { |
| 2703 | pr_warning("Extra thread map event, ignoring.\n"); |
| 2704 | return 0; |
| 2705 | } |
| 2706 | |
| 2707 | st->threads = thread_map__new_event(&event->thread_map); |
| 2708 | if (!st->threads) |
| 2709 | return -ENOMEM; |
| 2710 | |
| 2711 | return set_maps(st); |
| 2712 | } |
| 2713 | |
| 2714 | static |
Arnaldo Carvalho de Melo | 7e6a799 | 2016-12-12 10:52:10 -0300 | [diff] [blame] | 2715 | int process_cpu_map_event(struct perf_tool *tool, |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 2716 | union perf_event *event, |
| 2717 | struct perf_session *session __maybe_unused) |
| 2718 | { |
| 2719 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); |
| 2720 | struct cpu_map *cpus; |
| 2721 | |
| 2722 | if (st->cpus) { |
| 2723 | pr_warning("Extra cpu map event, ignoring.\n"); |
| 2724 | return 0; |
| 2725 | } |
| 2726 | |
| 2727 | cpus = cpu_map__new_data(&event->cpu_map.data); |
| 2728 | if (!cpus) |
| 2729 | return -ENOMEM; |
| 2730 | |
| 2731 | st->cpus = cpus; |
| 2732 | return set_maps(st); |
| 2733 | } |
| 2734 | |
Jin Yao | 5673944 | 2017-12-05 22:03:07 +0800 | [diff] [blame] | 2735 | static int runtime_stat_new(struct perf_stat_config *config, int nthreads) |
| 2736 | { |
| 2737 | int i; |
| 2738 | |
| 2739 | config->stats = calloc(nthreads, sizeof(struct runtime_stat)); |
| 2740 | if (!config->stats) |
| 2741 | return -1; |
| 2742 | |
| 2743 | config->stats_num = nthreads; |
| 2744 | |
| 2745 | for (i = 0; i < nthreads; i++) |
| 2746 | runtime_stat__init(&config->stats[i]); |
| 2747 | |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| 2751 | static void runtime_stat_delete(struct perf_stat_config *config) |
| 2752 | { |
| 2753 | int i; |
| 2754 | |
| 2755 | if (!config->stats) |
| 2756 | return; |
| 2757 | |
| 2758 | for (i = 0; i < config->stats_num; i++) |
| 2759 | runtime_stat__exit(&config->stats[i]); |
| 2760 | |
| 2761 | free(config->stats); |
| 2762 | } |
| 2763 | |
Jiri Olsa | 8a59f3c | 2016-01-12 10:35:29 +0100 | [diff] [blame] | 2764 | static const char * const stat_report_usage[] = { |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2765 | "perf stat report [<options>]", |
| 2766 | NULL, |
| 2767 | }; |
| 2768 | |
| 2769 | static struct perf_stat perf_stat = { |
| 2770 | .tool = { |
| 2771 | .attr = perf_event__process_attr, |
Jiri Olsa | fa6ea78 | 2015-11-05 15:41:00 +0100 | [diff] [blame] | 2772 | .event_update = perf_event__process_event_update, |
Jiri Olsa | 1975d36 | 2015-11-05 15:40:56 +0100 | [diff] [blame] | 2773 | .thread_map = process_thread_map_event, |
| 2774 | .cpu_map = process_cpu_map_event, |
Jiri Olsa | 62ba18b | 2015-11-05 15:40:57 +0100 | [diff] [blame] | 2775 | .stat_config = process_stat_config_event, |
Jiri Olsa | a56f939 | 2015-11-05 15:40:59 +0100 | [diff] [blame] | 2776 | .stat = perf_event__process_stat_event, |
| 2777 | .stat_round = process_stat_round_event, |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2778 | }, |
Jiri Olsa | 89af4e0 | 2015-11-05 15:41:02 +0100 | [diff] [blame] | 2779 | .aggr_mode = AGGR_UNSET, |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2780 | }; |
| 2781 | |
| 2782 | static int __cmd_report(int argc, const char **argv) |
| 2783 | { |
| 2784 | struct perf_session *session; |
| 2785 | const struct option options[] = { |
| 2786 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
Jiri Olsa | 89af4e0 | 2015-11-05 15:41:02 +0100 | [diff] [blame] | 2787 | OPT_SET_UINT(0, "per-socket", &perf_stat.aggr_mode, |
| 2788 | "aggregate counts per processor socket", AGGR_SOCKET), |
| 2789 | OPT_SET_UINT(0, "per-core", &perf_stat.aggr_mode, |
| 2790 | "aggregate counts per physical processor core", AGGR_CORE), |
| 2791 | OPT_SET_UINT('A', "no-aggr", &perf_stat.aggr_mode, |
| 2792 | "disable CPU count aggregation", AGGR_NONE), |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2793 | OPT_END() |
| 2794 | }; |
| 2795 | struct stat st; |
| 2796 | int ret; |
| 2797 | |
Jiri Olsa | 8a59f3c | 2016-01-12 10:35:29 +0100 | [diff] [blame] | 2798 | argc = parse_options(argc, argv, options, stat_report_usage, 0); |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2799 | |
| 2800 | if (!input_name || !strlen(input_name)) { |
| 2801 | if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) |
| 2802 | input_name = "-"; |
| 2803 | else |
| 2804 | input_name = "perf.data"; |
| 2805 | } |
| 2806 | |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 2807 | perf_stat.data.file.path = input_name; |
| 2808 | perf_stat.data.mode = PERF_DATA_MODE_READ; |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2809 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2810 | session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2811 | if (session == NULL) |
| 2812 | return -1; |
| 2813 | |
| 2814 | perf_stat.session = session; |
| 2815 | stat_config.output = stderr; |
| 2816 | evsel_list = session->evlist; |
| 2817 | |
| 2818 | ret = perf_session__process_events(session); |
| 2819 | if (ret) |
| 2820 | return ret; |
| 2821 | |
| 2822 | perf_session__delete(session); |
| 2823 | return 0; |
| 2824 | } |
| 2825 | |
Jiri Olsa | e3ba76d | 2017-02-27 10:48:18 +0100 | [diff] [blame] | 2826 | static void setup_system_wide(int forks) |
| 2827 | { |
| 2828 | /* |
| 2829 | * Make system wide (-a) the default target if |
| 2830 | * no target was specified and one of following |
| 2831 | * conditions is met: |
| 2832 | * |
| 2833 | * - there's no workload specified |
| 2834 | * - there is workload specified but all requested |
| 2835 | * events are system wide events |
| 2836 | */ |
| 2837 | if (!target__none(&target)) |
| 2838 | return; |
| 2839 | |
| 2840 | if (!forks) |
| 2841 | target.system_wide = true; |
| 2842 | else { |
| 2843 | struct perf_evsel *counter; |
| 2844 | |
| 2845 | evlist__for_each_entry(evsel_list, counter) { |
| 2846 | if (!counter->system_wide) |
| 2847 | return; |
| 2848 | } |
| 2849 | |
| 2850 | if (evsel_list->nr_entries) |
| 2851 | target.system_wide = true; |
| 2852 | } |
| 2853 | } |
| 2854 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 2855 | int cmd_stat(int argc, const char **argv) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 2856 | { |
Arnaldo Carvalho de Melo | b070a547 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 2857 | const char * const stat_usage[] = { |
| 2858 | "perf stat [<options>] [<command>]", |
| 2859 | NULL |
| 2860 | }; |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 2861 | int status = -EINVAL, run_idx; |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 2862 | const char *mode; |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 2863 | FILE *output = stderr; |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 2864 | unsigned int interval, timeout; |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2865 | const char * const stat_subcommands[] = { "record", "report" }; |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 2866 | |
Stephane Eranian | 5af52b5 | 2010-05-18 15:00:01 +0200 | [diff] [blame] | 2867 | setlocale(LC_ALL, ""); |
| 2868 | |
Namhyung Kim | 334fe7a | 2013-03-11 16:43:12 +0900 | [diff] [blame] | 2869 | evsel_list = perf_evlist__new(); |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 2870 | if (evsel_list == NULL) |
| 2871 | return -ENOMEM; |
| 2872 | |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 2873 | parse_events__shrink_config_terms(); |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2874 | argc = parse_options_subcommand(argc, argv, stat_options, stat_subcommands, |
| 2875 | (const char **) stat_usage, |
| 2876 | PARSE_OPT_STOP_AT_NON_OPTION); |
Andi Kleen | 37932c1 | 2017-03-20 13:17:08 -0700 | [diff] [blame] | 2877 | perf_stat__collect_metric_expr(evsel_list); |
Andi Kleen | fb4605b | 2016-03-01 10:57:52 -0800 | [diff] [blame] | 2878 | perf_stat__init_shadow_stats(); |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2879 | |
Jiri Olsa | 6edb78a | 2015-11-05 15:41:01 +0100 | [diff] [blame] | 2880 | if (csv_sep) { |
| 2881 | csv_output = true; |
| 2882 | if (!strcmp(csv_sep, "\\t")) |
| 2883 | csv_sep = "\t"; |
| 2884 | } else |
| 2885 | csv_sep = DEFAULT_SEPARATOR; |
| 2886 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2887 | if (argc && !strncmp(argv[0], "rec", 3)) { |
| 2888 | argc = __cmd_record(argc, argv); |
| 2889 | if (argc < 0) |
| 2890 | return -1; |
Jiri Olsa | ba6039b6 | 2015-11-05 15:40:55 +0100 | [diff] [blame] | 2891 | } else if (argc && !strncmp(argv[0], "rep", 3)) |
| 2892 | return __cmd_report(argc, argv); |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 2893 | |
Jiri Olsa | ec0d3d1 | 2015-07-21 14:31:25 +0200 | [diff] [blame] | 2894 | interval = stat_config.interval; |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 2895 | timeout = stat_config.timeout; |
Jiri Olsa | ec0d3d1 | 2015-07-21 14:31:25 +0200 | [diff] [blame] | 2896 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 2897 | /* |
| 2898 | * For record command the -o is already taken care of. |
| 2899 | */ |
| 2900 | if (!STAT_RECORD && output_name && strcmp(output_name, "-")) |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 2901 | output = NULL; |
| 2902 | |
Jim Cromie | 56f3bae | 2011-09-07 17:14:00 -0600 | [diff] [blame] | 2903 | if (output_name && output_fd) { |
| 2904 | fprintf(stderr, "cannot use both --output and --log-fd\n"); |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2905 | parse_options_usage(stat_usage, stat_options, "o", 1); |
| 2906 | parse_options_usage(NULL, stat_options, "log-fd", 0); |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 2907 | goto out; |
Jim Cromie | 56f3bae | 2011-09-07 17:14:00 -0600 | [diff] [blame] | 2908 | } |
Stephane Eranian | fc3e4d0 | 2012-05-15 13:11:11 +0200 | [diff] [blame] | 2909 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 2910 | if (metric_only && stat_config.aggr_mode == AGGR_THREAD) { |
| 2911 | fprintf(stderr, "--metric-only is not supported with --per-thread\n"); |
| 2912 | goto out; |
| 2913 | } |
| 2914 | |
Andi Kleen | 54b5091 | 2016-03-03 15:57:36 -0800 | [diff] [blame] | 2915 | if (metric_only && run_count > 1) { |
| 2916 | fprintf(stderr, "--metric-only is not supported with -r\n"); |
| 2917 | goto out; |
| 2918 | } |
| 2919 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 2920 | if (walltime_run_table && run_count <= 1) { |
| 2921 | fprintf(stderr, "--table is only supported with -r\n"); |
| 2922 | parse_options_usage(stat_usage, stat_options, "r", 1); |
| 2923 | parse_options_usage(NULL, stat_options, "table", 0); |
| 2924 | goto out; |
| 2925 | } |
| 2926 | |
Stephane Eranian | fc3e4d0 | 2012-05-15 13:11:11 +0200 | [diff] [blame] | 2927 | if (output_fd < 0) { |
| 2928 | fprintf(stderr, "argument to --log-fd must be a > 0\n"); |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2929 | parse_options_usage(stat_usage, stat_options, "log-fd", 0); |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 2930 | goto out; |
Stephane Eranian | fc3e4d0 | 2012-05-15 13:11:11 +0200 | [diff] [blame] | 2931 | } |
| 2932 | |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 2933 | if (!output) { |
| 2934 | struct timespec tm; |
| 2935 | mode = append_file ? "a" : "w"; |
| 2936 | |
| 2937 | output = fopen(output_name, mode); |
| 2938 | if (!output) { |
| 2939 | perror("failed to create output file"); |
David Ahern | fceda7f | 2012-08-26 12:24:44 -0600 | [diff] [blame] | 2940 | return -1; |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 2941 | } |
| 2942 | clock_gettime(CLOCK_REALTIME, &tm); |
| 2943 | fprintf(output, "# started on %s\n", ctime(&tm.tv_sec)); |
Stephane Eranian | fc3e4d0 | 2012-05-15 13:11:11 +0200 | [diff] [blame] | 2944 | } else if (output_fd > 0) { |
Jim Cromie | 56f3bae | 2011-09-07 17:14:00 -0600 | [diff] [blame] | 2945 | mode = append_file ? "a" : "w"; |
| 2946 | output = fdopen(output_fd, mode); |
| 2947 | if (!output) { |
| 2948 | perror("Failed opening logfd"); |
| 2949 | return -errno; |
| 2950 | } |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 2951 | } |
| 2952 | |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 2953 | stat_config.output = output; |
| 2954 | |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 2955 | /* |
| 2956 | * let the spreadsheet do the pretty-printing |
| 2957 | */ |
| 2958 | if (csv_output) { |
Jim Cromie | 61a9f32 | 2011-09-07 17:14:04 -0600 | [diff] [blame] | 2959 | /* User explicitly passed -B? */ |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 2960 | if (big_num_opt == 1) { |
| 2961 | fprintf(stderr, "-B option not supported with -x\n"); |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2962 | parse_options_usage(stat_usage, stat_options, "B", 1); |
| 2963 | parse_options_usage(NULL, stat_options, "x", 1); |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 2964 | goto out; |
Stephane Eranian | d7470b6 | 2010-12-01 18:49:05 +0200 | [diff] [blame] | 2965 | } else /* Nope, so disable big number formatting */ |
| 2966 | big_num = false; |
| 2967 | } else if (big_num_opt == 0) /* User passed --no-big-num */ |
| 2968 | big_num = false; |
| 2969 | |
Jiri Olsa | e3ba76d | 2017-02-27 10:48:18 +0100 | [diff] [blame] | 2970 | setup_system_wide(argc); |
David Ahern | ac3063b | 2013-09-30 07:37:37 -0600 | [diff] [blame] | 2971 | |
Jiri Olsa | 0ce2da1 | 2018-06-05 14:13:13 +0200 | [diff] [blame] | 2972 | /* |
| 2973 | * Display user/system times only for single |
| 2974 | * run and when there's specified tracee. |
| 2975 | */ |
| 2976 | if ((run_count == 1) && target__none(&target)) |
| 2977 | ru_display = true; |
| 2978 | |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 2979 | if (run_count < 0) { |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 2980 | pr_err("Run count must be a positive number\n"); |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 2981 | parse_options_usage(stat_usage, stat_options, "r", 1); |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 2982 | goto out; |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 2983 | } else if (run_count == 0) { |
| 2984 | forever = true; |
| 2985 | run_count = 1; |
| 2986 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 2987 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 2988 | if (walltime_run_table) { |
| 2989 | walltime_run = zalloc(run_count * sizeof(walltime_run[0])); |
| 2990 | if (!walltime_run) { |
| 2991 | pr_err("failed to setup -r option"); |
| 2992 | goto out; |
| 2993 | } |
| 2994 | } |
| 2995 | |
Jin Yao | 1d9f8d1 | 2017-12-05 22:03:10 +0800 | [diff] [blame] | 2996 | if ((stat_config.aggr_mode == AGGR_THREAD) && |
| 2997 | !target__has_task(&target)) { |
| 2998 | if (!target.system_wide || target.cpu_list) { |
| 2999 | fprintf(stderr, "The --per-thread option is only " |
| 3000 | "available when monitoring via -p -t -a " |
| 3001 | "options or only --per-thread.\n"); |
| 3002 | parse_options_usage(NULL, stat_options, "p", 1); |
| 3003 | parse_options_usage(NULL, stat_options, "t", 1); |
| 3004 | goto out; |
| 3005 | } |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | /* |
| 3009 | * no_aggr, cgroup are for system-wide only |
| 3010 | * --per-thread is aggregated per thread, we dont mix it with cpu mode |
| 3011 | */ |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 3012 | if (((stat_config.aggr_mode != AGGR_GLOBAL && |
| 3013 | stat_config.aggr_mode != AGGR_THREAD) || nr_cgroups) && |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3014 | !target__has_cpu(&target)) { |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 3015 | fprintf(stderr, "both cgroup and no-aggregation " |
| 3016 | "modes only available in system-wide mode\n"); |
| 3017 | |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 3018 | parse_options_usage(stat_usage, stat_options, "G", 1); |
| 3019 | parse_options_usage(NULL, stat_options, "A", 1); |
| 3020 | parse_options_usage(NULL, stat_options, "a", 1); |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 3021 | goto out; |
Stephane Eranian | d7e7a45 | 2013-02-06 15:46:02 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
Ingo Molnar | 2cba3ff | 2011-05-19 13:30:56 +0200 | [diff] [blame] | 3024 | if (add_default_attributes()) |
| 3025 | goto out; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 3026 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3027 | target__validate(&target); |
Arnaldo Carvalho de Melo | 5c98d466 | 2011-01-03 17:53:33 -0200 | [diff] [blame] | 3028 | |
Jin Yao | 1d9f8d1 | 2017-12-05 22:03:10 +0800 | [diff] [blame] | 3029 | if ((stat_config.aggr_mode == AGGR_THREAD) && (target.system_wide)) |
| 3030 | target.per_thread = true; |
| 3031 | |
Namhyung Kim | 77a6f01 | 2012-05-07 14:09:04 +0900 | [diff] [blame] | 3032 | if (perf_evlist__create_maps(evsel_list, &target) < 0) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3033 | if (target__has_task(&target)) { |
Namhyung Kim | 77a6f01 | 2012-05-07 14:09:04 +0900 | [diff] [blame] | 3034 | pr_err("Problems finding threads of monitor\n"); |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 3035 | parse_options_usage(stat_usage, stat_options, "p", 1); |
| 3036 | parse_options_usage(NULL, stat_options, "t", 1); |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3037 | } else if (target__has_cpu(&target)) { |
Namhyung Kim | 77a6f01 | 2012-05-07 14:09:04 +0900 | [diff] [blame] | 3038 | perror("failed to parse CPUs map"); |
Jiri Olsa | e054731 | 2015-11-05 15:40:45 +0100 | [diff] [blame] | 3039 | parse_options_usage(stat_usage, stat_options, "C", 1); |
| 3040 | parse_options_usage(NULL, stat_options, "a", 1); |
Namhyung Kim | cc03c54 | 2013-11-01 16:33:15 +0900 | [diff] [blame] | 3041 | } |
| 3042 | goto out; |
Arnaldo Carvalho de Melo | 60d567e | 2011-01-03 17:49:48 -0200 | [diff] [blame] | 3043 | } |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 3044 | |
| 3045 | /* |
| 3046 | * Initialize thread_map with comm names, |
| 3047 | * so we could print it out on output. |
| 3048 | */ |
Jin Yao | 5673944 | 2017-12-05 22:03:07 +0800 | [diff] [blame] | 3049 | if (stat_config.aggr_mode == AGGR_THREAD) { |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 3050 | thread_map__read_comms(evsel_list->threads); |
Jin Yao | 5673944 | 2017-12-05 22:03:07 +0800 | [diff] [blame] | 3051 | if (target.system_wide) { |
| 3052 | if (runtime_stat_new(&stat_config, |
| 3053 | thread_map__nr(evsel_list->threads))) { |
| 3054 | goto out; |
| 3055 | } |
| 3056 | } |
| 3057 | } |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 3058 | |
yuzhoujian | db06a26 | 2018-01-29 10:25:22 +0100 | [diff] [blame] | 3059 | if (stat_config.times && interval) |
| 3060 | interval_count = true; |
| 3061 | else if (stat_config.times && !interval) { |
| 3062 | pr_err("interval-count option should be used together with " |
| 3063 | "interval-print.\n"); |
| 3064 | parse_options_usage(stat_usage, stat_options, "interval-count", 0); |
| 3065 | parse_options_usage(stat_usage, stat_options, "I", 1); |
| 3066 | goto out; |
| 3067 | } |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 3068 | |
yuzhoujian | f1f8ad5 | 2018-01-29 10:25:23 +0100 | [diff] [blame] | 3069 | if (timeout && timeout < 100) { |
| 3070 | if (timeout < 10) { |
| 3071 | pr_err("timeout must be >= 10ms.\n"); |
| 3072 | parse_options_usage(stat_usage, stat_options, "timeout", 0); |
| 3073 | goto out; |
| 3074 | } else |
| 3075 | pr_warning("timeout < 100ms. " |
| 3076 | "The overhead percentage could be high in some cases. " |
| 3077 | "Please proceed with caution.\n"); |
| 3078 | } |
| 3079 | if (timeout && interval) { |
| 3080 | pr_err("timeout option is not supported with interval-print.\n"); |
| 3081 | parse_options_usage(stat_usage, stat_options, "timeout", 0); |
| 3082 | parse_options_usage(stat_usage, stat_options, "I", 1); |
| 3083 | goto out; |
| 3084 | } |
| 3085 | |
Arnaldo Carvalho de Melo | d134ffb | 2013-03-18 11:24:21 -0300 | [diff] [blame] | 3086 | if (perf_evlist__alloc_stats(evsel_list, interval)) |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 3087 | goto out; |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 3088 | |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 3089 | if (perf_stat_init_aggr_mode()) |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 3090 | goto out; |
Stephane Eranian | 86ee6e1 | 2013-02-14 13:57:27 +0100 | [diff] [blame] | 3091 | |
Ingo Molnar | 58d7e99 | 2009-05-15 11:03:23 +0200 | [diff] [blame] | 3092 | /* |
| 3093 | * We dont want to block the signals - that would cause |
| 3094 | * child tasks to inherit that and Ctrl-C would not work. |
| 3095 | * What we want is for Ctrl-C to work in the exec()-ed |
| 3096 | * task, but being ignored by perf stat itself: |
| 3097 | */ |
Peter Zijlstra | f7b7c26 | 2009-06-10 15:55:59 +0200 | [diff] [blame] | 3098 | atexit(sig_atexit); |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 3099 | if (!forever) |
| 3100 | signal(SIGINT, skip_signal); |
Stephane Eranian | 13370a9 | 2013-01-29 12:47:44 +0100 | [diff] [blame] | 3101 | signal(SIGCHLD, skip_signal); |
Ingo Molnar | 58d7e99 | 2009-05-15 11:03:23 +0200 | [diff] [blame] | 3102 | signal(SIGALRM, skip_signal); |
| 3103 | signal(SIGABRT, skip_signal); |
| 3104 | |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 3105 | status = 0; |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 3106 | for (run_idx = 0; forever || run_idx < run_count; run_idx++) { |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 3107 | if (run_count != 1 && verbose > 0) |
Stephane Eranian | 4aa9015 | 2011-08-15 22:22:33 +0200 | [diff] [blame] | 3108 | fprintf(output, "[ perf stat: executing run #%d ... ]\n", |
| 3109 | run_idx + 1); |
Ingo Molnar | f9cef0a | 2011-04-28 18:17:11 +0200 | [diff] [blame] | 3110 | |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 3111 | status = run_perf_stat(argc, argv, run_idx); |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 3112 | if (forever && status != -1) { |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 3113 | print_counters(NULL, argc, argv); |
Jiri Olsa | 254ecbc7 | 2015-06-26 11:29:13 +0200 | [diff] [blame] | 3114 | perf_stat__reset_stats(); |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 3115 | } |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 3116 | } |
| 3117 | |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 3118 | if (!forever && status != -1 && !interval) |
Jiri Olsa | d4f63a4 | 2015-06-26 11:29:26 +0200 | [diff] [blame] | 3119 | print_counters(NULL, argc, argv); |
Arnaldo Carvalho de Melo | d134ffb | 2013-03-18 11:24:21 -0300 | [diff] [blame] | 3120 | |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 3121 | if (STAT_RECORD) { |
| 3122 | /* |
| 3123 | * We synthesize the kernel mmap record just so that older tools |
| 3124 | * don't emit warnings about not being able to resolve symbols |
| 3125 | * due to /proc/sys/kernel/kptr_restrict settings and instear provide |
| 3126 | * a saner message about no samples being in the perf.data file. |
| 3127 | * |
| 3128 | * This also serves to suppress a warning about f_header.data.size == 0 |
Jiri Olsa | 8b99b1a | 2015-11-05 15:40:48 +0100 | [diff] [blame] | 3129 | * in header.c at the moment 'perf stat record' gets introduced, which |
| 3130 | * is not really needed once we start adding the stat specific PERF_RECORD_ |
| 3131 | * records, but the need to suppress the kptr_restrict messages in older |
| 3132 | * tools remain -acme |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 3133 | */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3134 | int fd = perf_data__fd(&perf_stat.data); |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 3135 | int err = perf_event__synthesize_kernel_mmap((void *)&perf_stat, |
| 3136 | process_synthesized_event, |
| 3137 | &perf_stat.session->machines.host); |
| 3138 | if (err) { |
| 3139 | pr_warning("Couldn't synthesize the kernel mmap record, harmless, " |
| 3140 | "older tools may produce warnings about this file\n."); |
| 3141 | } |
| 3142 | |
Jiri Olsa | 7aad0c3 | 2015-11-05 15:40:52 +0100 | [diff] [blame] | 3143 | if (!interval) { |
| 3144 | if (WRITE_STAT_ROUND_EVENT(walltime_nsecs_stats.max, FINAL)) |
| 3145 | pr_err("failed to write stat round event\n"); |
| 3146 | } |
| 3147 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3148 | if (!perf_stat.data.is_pipe) { |
Jiri Olsa | 664c98d | 2015-11-05 15:40:50 +0100 | [diff] [blame] | 3149 | perf_stat.session->header.data_size += perf_stat.bytes_written; |
| 3150 | perf_session__write_header(perf_stat.session, evsel_list, fd, true); |
| 3151 | } |
Jiri Olsa | 4979d0c | 2015-11-05 15:40:46 +0100 | [diff] [blame] | 3152 | |
| 3153 | perf_session__delete(perf_stat.session); |
| 3154 | } |
| 3155 | |
Masami Hiramatsu | 544c2ae | 2015-12-09 11:11:27 +0900 | [diff] [blame] | 3156 | perf_stat__exit_aggr_mode(); |
Arnaldo Carvalho de Melo | d134ffb | 2013-03-18 11:24:21 -0300 | [diff] [blame] | 3157 | perf_evlist__free_stats(evsel_list); |
Arnaldo Carvalho de Melo | 0015e2e | 2011-02-01 16:18:10 -0200 | [diff] [blame] | 3158 | out: |
Jiri Olsa | e55c14a | 2018-04-23 11:08:21 +0200 | [diff] [blame] | 3159 | free(walltime_run); |
| 3160 | |
Kan Liang | daefd0b | 2017-05-26 12:05:38 -0700 | [diff] [blame] | 3161 | if (smi_cost && smi_reset) |
| 3162 | sysfs__write_int(FREEZE_ON_SMI_PATH, 0); |
| 3163 | |
Arnaldo Carvalho de Melo | 0015e2e | 2011-02-01 16:18:10 -0200 | [diff] [blame] | 3164 | perf_evlist__delete(evsel_list); |
Jin Yao | 5673944 | 2017-12-05 22:03:07 +0800 | [diff] [blame] | 3165 | |
| 3166 | runtime_stat_delete(&stat_config); |
| 3167 | |
Ingo Molnar | 42202dd | 2009-06-13 14:57:28 +0200 | [diff] [blame] | 3168 | return status; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 3169 | } |