blob: ec4fbd410a4b04ccfced83dc210cfafbcb3f6948 [file] [log] [blame]
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001#include "builtin.h"
2
Andrea Gelminib7eead82010-08-05 15:51:38 +02003#include "perf.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02004#include "util/cache.h"
Andrea Gelminib7eead82010-08-05 15:51:38 +02005#include "util/debug.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -06006#include <subcmd/exec-cmd.h>
Andrea Gelminib7eead82010-08-05 15:51:38 +02007#include "util/header.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -06008#include <subcmd/parse-options.h>
Stephane Eranianfc36f942015-08-31 18:41:10 +02009#include "util/perf_regs.h"
Andrea Gelminib7eead82010-08-05 15:51:38 +020010#include "util/session.h"
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020011#include "util/tool.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020012#include "util/symbol.h"
13#include "util/thread.h"
Ingo Molnarcf723442009-11-28 10:11:00 +010014#include "util/trace-event.h"
Andrea Gelminib7eead82010-08-05 15:51:38 +020015#include "util/util.h"
David Ahern1424dc92011-03-09 22:23:28 -070016#include "util/evlist.h"
17#include "util/evsel.h"
Feng Tang36385be2012-09-07 16:42:24 +080018#include "util/sort.h"
Jiri Olsaf5fc14122013-10-15 16:27:32 +020019#include "util/data.h"
Adrian Hunter7a680eb2015-04-09 18:53:56 +030020#include "util/auxtrace.h"
Jiri Olsacfc88742016-01-05 22:09:06 +010021#include "util/cpumap.h"
22#include "util/thread_map.h"
23#include "util/stat.h"
Anton Blanchard5d67be92011-07-04 21:57:50 +100024#include <linux/bitmap.h>
Jiri Olsacfc88742016-01-05 22:09:06 +010025#include "asm/bug.h"
Jiri Olsac19ac912016-02-24 09:46:54 +010026#include "util/mem-events.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020027
Tom Zanussi956ffd02009-11-25 01:15:46 -060028static char const *script_name;
29static char const *generate_script_lang;
Frederic Weisbeckerffabd992010-05-27 16:27:47 +020030static bool debug_mode;
Frederic Weisbeckere1889d72010-04-24 01:55:09 +020031static u64 last_timestamp;
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +020032static u64 nr_unordered;
David Ahernc0230b22011-03-09 22:23:27 -070033static bool no_callchain;
Namhyung Kim47390ae2013-06-04 14:20:28 +090034static bool latency_format;
Robert Richter317df652011-11-25 15:05:25 +010035static bool system_wide;
Adrian Hunter400ea6d2015-04-09 18:54:05 +030036static bool print_flags;
Adrian Hunter83e19862015-09-25 16:15:36 +030037static bool nanosecs;
Anton Blanchard5d67be92011-07-04 21:57:50 +100038static const char *cpu_list;
39static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
Jiri Olsa91a2c3d2016-01-05 22:09:07 +010040static struct perf_stat_config stat_config;
Tom Zanussi956ffd02009-11-25 01:15:46 -060041
Adrian Hunter44cbe722015-09-25 16:15:50 +030042unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH;
Adrian Hunter03cd1fe2015-09-25 16:15:49 +030043
David Ahern745f43e2011-03-09 22:23:26 -070044enum perf_output_field {
45 PERF_OUTPUT_COMM = 1U << 0,
46 PERF_OUTPUT_TID = 1U << 1,
47 PERF_OUTPUT_PID = 1U << 2,
48 PERF_OUTPUT_TIME = 1U << 3,
49 PERF_OUTPUT_CPU = 1U << 4,
50 PERF_OUTPUT_EVNAME = 1U << 5,
51 PERF_OUTPUT_TRACE = 1U << 6,
David Ahern787bef12011-05-27 14:28:43 -060052 PERF_OUTPUT_IP = 1U << 7,
53 PERF_OUTPUT_SYM = 1U << 8,
David Ahern610723f2011-05-27 14:28:44 -060054 PERF_OUTPUT_DSO = 1U << 9,
David Ahern7cec0922011-05-30 13:08:23 -060055 PERF_OUTPUT_ADDR = 1U << 10,
Akihiro Nagaia978f2a2012-01-30 13:43:15 +090056 PERF_OUTPUT_SYMOFFSET = 1U << 11,
Adrian Huntercc8fae12013-12-06 09:42:57 +020057 PERF_OUTPUT_SRCLINE = 1U << 12,
Jiri Olsa535aeaae2014-08-25 16:45:42 +020058 PERF_OUTPUT_PERIOD = 1U << 13,
Stephane Eranianfc36f942015-08-31 18:41:10 +020059 PERF_OUTPUT_IREGS = 1U << 14,
Stephane Eraniandc323ce2015-08-31 18:41:13 +020060 PERF_OUTPUT_BRSTACK = 1U << 15,
61 PERF_OUTPUT_BRSTACKSYM = 1U << 16,
Jiri Olsa94ddddf2016-02-15 09:34:51 +010062 PERF_OUTPUT_DATA_SRC = 1U << 17,
63 PERF_OUTPUT_WEIGHT = 1U << 18,
Wang Nan30372f02016-02-24 11:20:45 +000064 PERF_OUTPUT_BPF_OUTPUT = 1U << 19,
David Ahern745f43e2011-03-09 22:23:26 -070065};
66
67struct output_option {
68 const char *str;
69 enum perf_output_field field;
70} all_output_options[] = {
71 {.str = "comm", .field = PERF_OUTPUT_COMM},
72 {.str = "tid", .field = PERF_OUTPUT_TID},
73 {.str = "pid", .field = PERF_OUTPUT_PID},
74 {.str = "time", .field = PERF_OUTPUT_TIME},
75 {.str = "cpu", .field = PERF_OUTPUT_CPU},
76 {.str = "event", .field = PERF_OUTPUT_EVNAME},
77 {.str = "trace", .field = PERF_OUTPUT_TRACE},
David Ahern787bef12011-05-27 14:28:43 -060078 {.str = "ip", .field = PERF_OUTPUT_IP},
David Ahernc0230b22011-03-09 22:23:27 -070079 {.str = "sym", .field = PERF_OUTPUT_SYM},
David Ahern610723f2011-05-27 14:28:44 -060080 {.str = "dso", .field = PERF_OUTPUT_DSO},
David Ahern7cec0922011-05-30 13:08:23 -060081 {.str = "addr", .field = PERF_OUTPUT_ADDR},
Akihiro Nagaia978f2a2012-01-30 13:43:15 +090082 {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET},
Adrian Huntercc8fae12013-12-06 09:42:57 +020083 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
Jiri Olsa535aeaae2014-08-25 16:45:42 +020084 {.str = "period", .field = PERF_OUTPUT_PERIOD},
Stephane Eranianfc36f942015-08-31 18:41:10 +020085 {.str = "iregs", .field = PERF_OUTPUT_IREGS},
Stephane Eraniandc323ce2015-08-31 18:41:13 +020086 {.str = "brstack", .field = PERF_OUTPUT_BRSTACK},
87 {.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM},
Jiri Olsa94ddddf2016-02-15 09:34:51 +010088 {.str = "data_src", .field = PERF_OUTPUT_DATA_SRC},
89 {.str = "weight", .field = PERF_OUTPUT_WEIGHT},
Wang Nan30372f02016-02-24 11:20:45 +000090 {.str = "bpf-output", .field = PERF_OUTPUT_BPF_OUTPUT},
David Ahern745f43e2011-03-09 22:23:26 -070091};
92
93/* default set to maintain compatibility with current format */
David Ahern2c9e45f72011-03-17 10:03:21 -060094static struct {
95 bool user_set;
David Ahern9cbdb702011-04-06 21:54:20 -060096 bool wildcard_set;
David Aherna6ffaf92013-08-07 22:50:51 -040097 unsigned int print_ip_opts;
David Ahern2c9e45f72011-03-17 10:03:21 -060098 u64 fields;
99 u64 invalid_fields;
100} output[PERF_TYPE_MAX] = {
David Ahern1424dc92011-03-09 22:23:28 -0700101
David Ahern2c9e45f72011-03-17 10:03:21 -0600102 [PERF_TYPE_HARDWARE] = {
103 .user_set = false,
David Ahern1424dc92011-03-09 22:23:28 -0700104
David Ahern2c9e45f72011-03-17 10:03:21 -0600105 .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
106 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
David Ahern787bef12011-05-27 14:28:43 -0600107 PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
Jiri Olsae8564b72014-08-25 16:45:43 +0200108 PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
109 PERF_OUTPUT_PERIOD,
David Ahern2c9e45f72011-03-17 10:03:21 -0600110
Wang Nan30372f02016-02-24 11:20:45 +0000111 .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
David Ahern2c9e45f72011-03-17 10:03:21 -0600112 },
113
114 [PERF_TYPE_SOFTWARE] = {
115 .user_set = false,
116
117 .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
118 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
David Ahern787bef12011-05-27 14:28:43 -0600119 PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
Jiri Olsae8564b72014-08-25 16:45:43 +0200120 PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
Wang Nan30372f02016-02-24 11:20:45 +0000121 PERF_OUTPUT_PERIOD | PERF_OUTPUT_BPF_OUTPUT,
David Ahern2c9e45f72011-03-17 10:03:21 -0600122
123 .invalid_fields = PERF_OUTPUT_TRACE,
124 },
125
126 [PERF_TYPE_TRACEPOINT] = {
127 .user_set = false,
128
129 .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
130 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
Wang Nan30372f02016-02-24 11:20:45 +0000131 PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE
David Ahern2c9e45f72011-03-17 10:03:21 -0600132 },
Arun Sharma0817a6a2011-04-14 10:38:18 -0700133
134 [PERF_TYPE_RAW] = {
135 .user_set = false,
136
137 .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
138 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
David Ahern787bef12011-05-27 14:28:43 -0600139 PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
Jiri Olsae8564b72014-08-25 16:45:43 +0200140 PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
Jiri Olsaff7b1912016-02-15 09:34:52 +0100141 PERF_OUTPUT_PERIOD | PERF_OUTPUT_ADDR |
142 PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT,
Arun Sharma0817a6a2011-04-14 10:38:18 -0700143
Wang Nan30372f02016-02-24 11:20:45 +0000144 .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
Arun Sharma0817a6a2011-04-14 10:38:18 -0700145 },
Wang Nan27cfef02015-12-08 02:25:43 +0000146
147 [PERF_TYPE_BREAKPOINT] = {
148 .user_set = false,
149
150 .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
151 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
152 PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
153 PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
154 PERF_OUTPUT_PERIOD,
155
Wang Nan30372f02016-02-24 11:20:45 +0000156 .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
Wang Nan27cfef02015-12-08 02:25:43 +0000157 },
David Ahern1424dc92011-03-09 22:23:28 -0700158};
David Ahern745f43e2011-03-09 22:23:26 -0700159
David Ahern2c9e45f72011-03-17 10:03:21 -0600160static bool output_set_by_user(void)
161{
162 int j;
163 for (j = 0; j < PERF_TYPE_MAX; ++j) {
164 if (output[j].user_set)
165 return true;
166 }
167 return false;
168}
David Ahern745f43e2011-03-09 22:23:26 -0700169
David Ahern9cbdb702011-04-06 21:54:20 -0600170static const char *output_field2str(enum perf_output_field field)
171{
172 int i, imax = ARRAY_SIZE(all_output_options);
173 const char *str = "";
174
175 for (i = 0; i < imax; ++i) {
176 if (all_output_options[i].field == field) {
177 str = all_output_options[i].str;
178 break;
179 }
180 }
181 return str;
182}
183
David Ahern2c9e45f72011-03-17 10:03:21 -0600184#define PRINT_FIELD(x) (output[attr->type].fields & PERF_OUTPUT_##x)
David Ahern1424dc92011-03-09 22:23:28 -0700185
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300186static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
187 u64 sample_type, const char *sample_msg,
188 enum perf_output_field field,
189 bool allow_user_set)
David Ahern1424dc92011-03-09 22:23:28 -0700190{
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300191 struct perf_event_attr *attr = &evsel->attr;
David Ahern9cbdb702011-04-06 21:54:20 -0600192 int type = attr->type;
193 const char *evname;
194
195 if (attr->sample_type & sample_type)
196 return 0;
197
198 if (output[type].user_set) {
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300199 if (allow_user_set)
200 return 0;
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300201 evname = perf_evsel__name(evsel);
David Ahern9cbdb702011-04-06 21:54:20 -0600202 pr_err("Samples for '%s' event do not have %s attribute set. "
203 "Cannot print '%s' field.\n",
204 evname, sample_msg, output_field2str(field));
205 return -1;
206 }
207
208 /* user did not ask for it explicitly so remove from the default list */
209 output[type].fields &= ~field;
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300210 evname = perf_evsel__name(evsel);
David Ahern9cbdb702011-04-06 21:54:20 -0600211 pr_debug("Samples for '%s' event do not have %s attribute set. "
212 "Skipping '%s' field.\n",
213 evname, sample_msg, output_field2str(field));
214
215 return 0;
216}
217
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300218static int perf_evsel__check_stype(struct perf_evsel *evsel,
219 u64 sample_type, const char *sample_msg,
220 enum perf_output_field field)
221{
222 return perf_evsel__do_check_stype(evsel, sample_type, sample_msg, field,
223 false);
224}
225
David Ahern9cbdb702011-04-06 21:54:20 -0600226static int perf_evsel__check_attr(struct perf_evsel *evsel,
227 struct perf_session *session)
228{
229 struct perf_event_attr *attr = &evsel->attr;
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300230 bool allow_user_set;
231
Jiri Olsae099eba2016-01-05 22:09:09 +0100232 if (perf_header__has_feat(&session->header, HEADER_STAT))
233 return 0;
234
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300235 allow_user_set = perf_header__has_feat(&session->header,
236 HEADER_AUXTRACE);
David Ahern9cbdb702011-04-06 21:54:20 -0600237
David Ahern1424dc92011-03-09 22:23:28 -0700238 if (PRINT_FIELD(TRACE) &&
239 !perf_session__has_traces(session, "record -R"))
240 return -EINVAL;
241
David Ahern787bef12011-05-27 14:28:43 -0600242 if (PRINT_FIELD(IP)) {
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300243 if (perf_evsel__check_stype(evsel, PERF_SAMPLE_IP, "IP",
244 PERF_OUTPUT_IP))
David Ahern1424dc92011-03-09 22:23:28 -0700245 return -EINVAL;
David Ahern1424dc92011-03-09 22:23:28 -0700246 }
David Ahern7cec0922011-05-30 13:08:23 -0600247
248 if (PRINT_FIELD(ADDR) &&
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300249 perf_evsel__do_check_stype(evsel, PERF_SAMPLE_ADDR, "ADDR",
250 PERF_OUTPUT_ADDR, allow_user_set))
David Ahern7cec0922011-05-30 13:08:23 -0600251 return -EINVAL;
252
Jiri Olsa94ddddf2016-02-15 09:34:51 +0100253 if (PRINT_FIELD(DATA_SRC) &&
254 perf_evsel__check_stype(evsel, PERF_SAMPLE_DATA_SRC, "DATA_SRC",
255 PERF_OUTPUT_DATA_SRC))
256 return -EINVAL;
257
258 if (PRINT_FIELD(WEIGHT) &&
259 perf_evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT, "WEIGHT",
260 PERF_OUTPUT_WEIGHT))
261 return -EINVAL;
262
David Ahern7cec0922011-05-30 13:08:23 -0600263 if (PRINT_FIELD(SYM) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
264 pr_err("Display of symbols requested but neither sample IP nor "
265 "sample address\nis selected. Hence, no addresses to convert "
266 "to symbols.\n");
David Ahern787bef12011-05-27 14:28:43 -0600267 return -EINVAL;
268 }
Akihiro Nagaia978f2a2012-01-30 13:43:15 +0900269 if (PRINT_FIELD(SYMOFFSET) && !PRINT_FIELD(SYM)) {
270 pr_err("Display of offsets requested but symbol is not"
271 "selected.\n");
272 return -EINVAL;
273 }
David Ahern7cec0922011-05-30 13:08:23 -0600274 if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
275 pr_err("Display of DSO requested but neither sample IP nor "
276 "sample address\nis selected. Hence, no addresses to convert "
277 "to DSO.\n");
David Ahern610723f2011-05-27 14:28:44 -0600278 return -EINVAL;
279 }
Adrian Huntercc8fae12013-12-06 09:42:57 +0200280 if (PRINT_FIELD(SRCLINE) && !PRINT_FIELD(IP)) {
281 pr_err("Display of source line number requested but sample IP is not\n"
282 "selected. Hence, no address to lookup the source line number.\n");
283 return -EINVAL;
284 }
David Ahern1424dc92011-03-09 22:23:28 -0700285
286 if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) &&
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300287 perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",
288 PERF_OUTPUT_TID|PERF_OUTPUT_PID))
David Ahern1424dc92011-03-09 22:23:28 -0700289 return -EINVAL;
David Ahern1424dc92011-03-09 22:23:28 -0700290
291 if (PRINT_FIELD(TIME) &&
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300292 perf_evsel__check_stype(evsel, PERF_SAMPLE_TIME, "TIME",
293 PERF_OUTPUT_TIME))
David Ahern1424dc92011-03-09 22:23:28 -0700294 return -EINVAL;
David Ahern1424dc92011-03-09 22:23:28 -0700295
296 if (PRINT_FIELD(CPU) &&
Adrian Hunter6d5cdd62015-04-24 22:29:44 +0300297 perf_evsel__do_check_stype(evsel, PERF_SAMPLE_CPU, "CPU",
298 PERF_OUTPUT_CPU, allow_user_set))
David Ahern1424dc92011-03-09 22:23:28 -0700299 return -EINVAL;
David Ahern9cbdb702011-04-06 21:54:20 -0600300
Jiri Olsa535aeaae2014-08-25 16:45:42 +0200301 if (PRINT_FIELD(PERIOD) &&
302 perf_evsel__check_stype(evsel, PERF_SAMPLE_PERIOD, "PERIOD",
303 PERF_OUTPUT_PERIOD))
304 return -EINVAL;
305
Stephane Eranianfc36f942015-08-31 18:41:10 +0200306 if (PRINT_FIELD(IREGS) &&
307 perf_evsel__check_stype(evsel, PERF_SAMPLE_REGS_INTR, "IREGS",
308 PERF_OUTPUT_IREGS))
309 return -EINVAL;
310
David Ahern9cbdb702011-04-06 21:54:20 -0600311 return 0;
312}
313
Adrian Hunter7ea95722013-11-01 15:51:30 +0200314static void set_print_ip_opts(struct perf_event_attr *attr)
315{
316 unsigned int type = attr->type;
317
318 output[type].print_ip_opts = 0;
319 if (PRINT_FIELD(IP))
320 output[type].print_ip_opts |= PRINT_IP_OPT_IP;
321
322 if (PRINT_FIELD(SYM))
323 output[type].print_ip_opts |= PRINT_IP_OPT_SYM;
324
325 if (PRINT_FIELD(DSO))
326 output[type].print_ip_opts |= PRINT_IP_OPT_DSO;
327
328 if (PRINT_FIELD(SYMOFFSET))
329 output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
Adrian Huntercc8fae12013-12-06 09:42:57 +0200330
331 if (PRINT_FIELD(SRCLINE))
332 output[type].print_ip_opts |= PRINT_IP_OPT_SRCLINE;
Adrian Hunter7ea95722013-11-01 15:51:30 +0200333}
334
David Ahern9cbdb702011-04-06 21:54:20 -0600335/*
336 * verify all user requested events exist and the samples
337 * have the expected data
338 */
339static int perf_session__check_output_opt(struct perf_session *session)
340{
341 int j;
342 struct perf_evsel *evsel;
343
344 for (j = 0; j < PERF_TYPE_MAX; ++j) {
345 evsel = perf_session__find_first_evtype(session, j);
346
347 /*
348 * even if fields is set to 0 (ie., show nothing) event must
349 * exist if user explicitly includes it on the command line
350 */
351 if (!evsel && output[j].user_set && !output[j].wildcard_set) {
352 pr_err("%s events do not exist. "
353 "Remove corresponding -f option to proceed.\n",
354 event_type(j));
355 return -1;
356 }
357
358 if (evsel && output[j].fields &&
359 perf_evsel__check_attr(evsel, session))
360 return -1;
David Aherna6ffaf92013-08-07 22:50:51 -0400361
362 if (evsel == NULL)
363 continue;
364
Adrian Hunter7ea95722013-11-01 15:51:30 +0200365 set_print_ip_opts(&evsel->attr);
David Ahern1424dc92011-03-09 22:23:28 -0700366 }
367
Adrian Hunter98526ee2014-07-31 09:00:59 +0300368 if (!no_callchain) {
369 bool use_callchain = false;
370
371 evlist__for_each(session->evlist, evsel) {
372 if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
373 use_callchain = true;
374 break;
375 }
376 }
377 if (!use_callchain)
378 symbol_conf.use_callchain = false;
379 }
380
David Ahern80b8b492013-11-19 21:07:37 -0700381 /*
382 * set default for tracepoints to print symbols only
383 * if callchains are present
384 */
385 if (symbol_conf.use_callchain &&
386 !output[PERF_TYPE_TRACEPOINT].user_set) {
387 struct perf_event_attr *attr;
388
389 j = PERF_TYPE_TRACEPOINT;
390 evsel = perf_session__find_first_evtype(session, j);
391 if (evsel == NULL)
392 goto out;
393
394 attr = &evsel->attr;
395
396 if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) {
397 output[j].fields |= PERF_OUTPUT_IP;
398 output[j].fields |= PERF_OUTPUT_SYM;
399 output[j].fields |= PERF_OUTPUT_DSO;
400 set_print_ip_opts(attr);
401 }
402 }
403
404out:
David Ahern1424dc92011-03-09 22:23:28 -0700405 return 0;
406}
David Ahern745f43e2011-03-09 22:23:26 -0700407
Stephane Eranianfc36f942015-08-31 18:41:10 +0200408static void print_sample_iregs(union perf_event *event __maybe_unused,
409 struct perf_sample *sample,
410 struct thread *thread __maybe_unused,
411 struct perf_event_attr *attr)
412{
413 struct regs_dump *regs = &sample->intr_regs;
414 uint64_t mask = attr->sample_regs_intr;
415 unsigned i = 0, r;
416
417 if (!regs)
418 return;
419
420 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
421 u64 val = regs->regs[i++];
422 printf("%5s:0x%"PRIx64" ", perf_reg_name(r), val);
423 }
424}
425
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300426static void print_sample_start(struct perf_sample *sample,
David Ahern1424dc92011-03-09 22:23:28 -0700427 struct thread *thread,
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300428 struct perf_evsel *evsel)
David Ahernc70c94b2011-03-09 22:23:25 -0700429{
Arnaldo Carvalho de Melo5bff01f2012-06-12 13:35:44 -0300430 struct perf_event_attr *attr = &evsel->attr;
David Ahernc70c94b2011-03-09 22:23:25 -0700431 unsigned long secs;
432 unsigned long usecs;
David Ahern745f43e2011-03-09 22:23:26 -0700433 unsigned long long nsecs;
David Ahernc70c94b2011-03-09 22:23:25 -0700434
David Ahern745f43e2011-03-09 22:23:26 -0700435 if (PRINT_FIELD(COMM)) {
436 if (latency_format)
Frederic Weisbeckerb9c51432013-09-11 14:46:56 +0200437 printf("%8.8s ", thread__comm_str(thread));
David Ahern787bef12011-05-27 14:28:43 -0600438 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain)
Frederic Weisbeckerb9c51432013-09-11 14:46:56 +0200439 printf("%s ", thread__comm_str(thread));
David Ahern745f43e2011-03-09 22:23:26 -0700440 else
Frederic Weisbeckerb9c51432013-09-11 14:46:56 +0200441 printf("%16s ", thread__comm_str(thread));
David Ahern745f43e2011-03-09 22:23:26 -0700442 }
David Ahernc70c94b2011-03-09 22:23:25 -0700443
David Ahern745f43e2011-03-09 22:23:26 -0700444 if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
445 printf("%5d/%-5d ", sample->pid, sample->tid);
446 else if (PRINT_FIELD(PID))
447 printf("%5d ", sample->pid);
448 else if (PRINT_FIELD(TID))
449 printf("%5d ", sample->tid);
David Ahernc70c94b2011-03-09 22:23:25 -0700450
David Ahern745f43e2011-03-09 22:23:26 -0700451 if (PRINT_FIELD(CPU)) {
452 if (latency_format)
453 printf("%3d ", sample->cpu);
454 else
455 printf("[%03d] ", sample->cpu);
456 }
David Ahernc70c94b2011-03-09 22:23:25 -0700457
David Ahern745f43e2011-03-09 22:23:26 -0700458 if (PRINT_FIELD(TIME)) {
459 nsecs = sample->time;
460 secs = nsecs / NSECS_PER_SEC;
461 nsecs -= secs * NSECS_PER_SEC;
462 usecs = nsecs / NSECS_PER_USEC;
Adrian Hunter83e19862015-09-25 16:15:36 +0300463 if (nanosecs)
464 printf("%5lu.%09llu: ", secs, nsecs);
465 else
466 printf("%5lu.%06lu: ", secs, usecs);
David Ahern745f43e2011-03-09 22:23:26 -0700467 }
David Ahernc70c94b2011-03-09 22:23:25 -0700468}
469
Stephane Eraniandc323ce2015-08-31 18:41:13 +0200470static inline char
471mispred_str(struct branch_entry *br)
472{
473 if (!(br->flags.mispred || br->flags.predicted))
474 return '-';
475
476 return br->flags.predicted ? 'P' : 'M';
477}
478
479static void print_sample_brstack(union perf_event *event __maybe_unused,
480 struct perf_sample *sample,
481 struct thread *thread __maybe_unused,
482 struct perf_event_attr *attr __maybe_unused)
483{
484 struct branch_stack *br = sample->branch_stack;
485 u64 i;
486
487 if (!(br && br->nr))
488 return;
489
490 for (i = 0; i < br->nr; i++) {
491 printf(" 0x%"PRIx64"/0x%"PRIx64"/%c/%c/%c/%d ",
492 br->entries[i].from,
493 br->entries[i].to,
494 mispred_str( br->entries + i),
495 br->entries[i].flags.in_tx? 'X' : '-',
496 br->entries[i].flags.abort? 'A' : '-',
497 br->entries[i].flags.cycles);
498 }
499}
500
501static void print_sample_brstacksym(union perf_event *event __maybe_unused,
502 struct perf_sample *sample,
503 struct thread *thread __maybe_unused,
504 struct perf_event_attr *attr __maybe_unused)
505{
506 struct branch_stack *br = sample->branch_stack;
507 struct addr_location alf, alt;
508 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
509 u64 i, from, to;
510
511 if (!(br && br->nr))
512 return;
513
514 for (i = 0; i < br->nr; i++) {
515
516 memset(&alf, 0, sizeof(alf));
517 memset(&alt, 0, sizeof(alt));
518 from = br->entries[i].from;
519 to = br->entries[i].to;
520
521 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, from, &alf);
522 if (alf.map)
523 alf.sym = map__find_symbol(alf.map, alf.addr, NULL);
524
525 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, to, &alt);
526 if (alt.map)
527 alt.sym = map__find_symbol(alt.map, alt.addr, NULL);
528
529 symbol__fprintf_symname_offs(alf.sym, &alf, stdout);
530 putchar('/');
531 symbol__fprintf_symname_offs(alt.sym, &alt, stdout);
532 printf("/%c/%c/%c/%d ",
533 mispred_str( br->entries + i),
534 br->entries[i].flags.in_tx? 'X' : '-',
535 br->entries[i].flags.abort? 'A' : '-',
536 br->entries[i].flags.cycles);
537 }
538}
539
540
David Ahern7cec0922011-05-30 13:08:23 -0600541static void print_sample_addr(union perf_event *event,
542 struct perf_sample *sample,
David Ahern7cec0922011-05-30 13:08:23 -0600543 struct thread *thread,
544 struct perf_event_attr *attr)
545{
546 struct addr_location al;
David Ahern7cec0922011-05-30 13:08:23 -0600547
548 printf("%16" PRIx64, sample->addr);
549
550 if (!sample_addr_correlates_sym(attr))
551 return;
552
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -0300553 perf_event__preprocess_sample_addr(event, sample, thread, &al);
David Ahern7cec0922011-05-30 13:08:23 -0600554
555 if (PRINT_FIELD(SYM)) {
Akihiro Nagai547a92e2012-01-30 13:42:57 +0900556 printf(" ");
Akihiro Nagaia978f2a2012-01-30 13:43:15 +0900557 if (PRINT_FIELD(SYMOFFSET))
558 symbol__fprintf_symname_offs(al.sym, &al, stdout);
559 else
560 symbol__fprintf_symname(al.sym, stdout);
David Ahern7cec0922011-05-30 13:08:23 -0600561 }
562
563 if (PRINT_FIELD(DSO)) {
Akihiro Nagai547a92e2012-01-30 13:42:57 +0900564 printf(" (");
565 map__fprintf_dsoname(al.map, stdout);
566 printf(")");
David Ahern7cec0922011-05-30 13:08:23 -0600567 }
568}
569
Akihiro Nagai95582592012-01-30 13:43:09 +0900570static void print_sample_bts(union perf_event *event,
571 struct perf_sample *sample,
572 struct perf_evsel *evsel,
Adrian Huntera2cb3cf2013-12-04 16:16:36 +0200573 struct thread *thread,
574 struct addr_location *al)
Akihiro Nagai95582592012-01-30 13:43:09 +0900575{
576 struct perf_event_attr *attr = &evsel->attr;
Adrian Hunter8066be5f2014-07-22 16:17:15 +0300577 bool print_srcline_last = false;
Akihiro Nagai95582592012-01-30 13:43:09 +0900578
579 /* print branch_from information */
580 if (PRINT_FIELD(IP)) {
Adrian Hunter8066be5f2014-07-22 16:17:15 +0300581 unsigned int print_opts = output[attr->type].print_ip_opts;
582
583 if (symbol_conf.use_callchain && sample->callchain) {
Akihiro Nagai95582592012-01-30 13:43:09 +0900584 printf("\n");
Adrian Hunter8066be5f2014-07-22 16:17:15 +0300585 } else {
586 printf(" ");
587 if (print_opts & PRINT_IP_OPT_SRCLINE) {
588 print_srcline_last = true;
589 print_opts &= ~PRINT_IP_OPT_SRCLINE;
590 }
591 }
592 perf_evsel__print_ip(evsel, sample, al, print_opts,
Adrian Hunter03cd1fe2015-09-25 16:15:49 +0300593 scripting_max_stack);
Akihiro Nagai95582592012-01-30 13:43:09 +0900594 }
595
Akihiro Nagai95582592012-01-30 13:43:09 +0900596 /* print branch_to information */
Adrian Hunter243be3d2013-10-18 15:29:14 +0300597 if (PRINT_FIELD(ADDR) ||
598 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
Adrian Hunter578bea42014-07-22 16:17:16 +0300599 !output[attr->type].user_set)) {
600 printf(" => ");
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -0300601 print_sample_addr(event, sample, thread, attr);
Adrian Hunter578bea42014-07-22 16:17:16 +0300602 }
Akihiro Nagai95582592012-01-30 13:43:09 +0900603
Adrian Hunter8066be5f2014-07-22 16:17:15 +0300604 if (print_srcline_last)
605 map__fprintf_srcline(al->map, al->addr, "\n ", stdout);
606
Akihiro Nagai95582592012-01-30 13:43:09 +0900607 printf("\n");
608}
609
Adrian Hunter400ea6d2015-04-09 18:54:05 +0300610static void print_sample_flags(u32 flags)
611{
612 const char *chars = PERF_IP_FLAG_CHARS;
613 const int n = strlen(PERF_IP_FLAG_CHARS);
614 char str[33];
615 int i, pos = 0;
616
617 for (i = 0; i < n; i++, flags >>= 1) {
618 if (flags & 1)
619 str[pos++] = chars[i];
620 }
621 for (; i < 32; i++, flags >>= 1) {
622 if (flags & 1)
623 str[pos++] = '?';
624 }
625 str[pos] = 0;
626 printf(" %-4s ", str);
627}
628
Wang Nan30372f02016-02-24 11:20:45 +0000629struct printer_data {
630 int line_no;
631 bool hit_nul;
632 bool is_printable;
633};
634
635static void
636print_sample_bpf_output_printer(enum binary_printer_ops op,
637 unsigned int val,
638 void *extra)
639{
640 unsigned char ch = (unsigned char)val;
641 struct printer_data *printer_data = extra;
642
643 switch (op) {
644 case BINARY_PRINT_DATA_BEGIN:
645 printf("\n");
646 break;
647 case BINARY_PRINT_LINE_BEGIN:
648 printf("%17s", !printer_data->line_no ? "BPF output:" :
649 " ");
650 break;
651 case BINARY_PRINT_ADDR:
652 printf(" %04x:", val);
653 break;
654 case BINARY_PRINT_NUM_DATA:
655 printf(" %02x", val);
656 break;
657 case BINARY_PRINT_NUM_PAD:
658 printf(" ");
659 break;
660 case BINARY_PRINT_SEP:
661 printf(" ");
662 break;
663 case BINARY_PRINT_CHAR_DATA:
664 if (printer_data->hit_nul && ch)
665 printer_data->is_printable = false;
666
667 if (!isprint(ch)) {
668 printf("%c", '.');
669
670 if (!printer_data->is_printable)
671 break;
672
673 if (ch == '\0')
674 printer_data->hit_nul = true;
675 else
676 printer_data->is_printable = false;
677 } else {
678 printf("%c", ch);
679 }
680 break;
681 case BINARY_PRINT_CHAR_PAD:
682 printf(" ");
683 break;
684 case BINARY_PRINT_LINE_END:
685 printf("\n");
686 printer_data->line_no++;
687 break;
688 case BINARY_PRINT_DATA_END:
689 default:
690 break;
691 }
692}
693
694static void print_sample_bpf_output(struct perf_sample *sample)
695{
696 unsigned int nr_bytes = sample->raw_size;
697 struct printer_data printer_data = {0, false, true};
698
699 print_binary(sample->raw_data, nr_bytes, 8,
700 print_sample_bpf_output_printer, &printer_data);
701
702 if (printer_data.is_printable && printer_data.hit_nul)
703 printf("%17s \"%s\"\n", "BPF string:",
704 (char *)(sample->raw_data));
705}
706
Jiri Olsa809e9422015-11-26 18:55:21 +0100707struct perf_script {
708 struct perf_tool tool;
709 struct perf_session *session;
710 bool show_task_events;
711 bool show_mmap_events;
712 bool show_switch_events;
Jiri Olsacfc88742016-01-05 22:09:06 +0100713 bool allocated;
714 struct cpu_map *cpus;
715 struct thread_map *threads;
Jiri Olsa9cdbc402016-01-07 10:14:05 +0100716 int name_width;
Jiri Olsa809e9422015-11-26 18:55:21 +0100717};
718
Jiri Olsa9cdbc402016-01-07 10:14:05 +0100719static int perf_evlist__max_name_len(struct perf_evlist *evlist)
720{
721 struct perf_evsel *evsel;
722 int max = 0;
723
724 evlist__for_each(evlist, evsel) {
725 int len = strlen(perf_evsel__name(evsel));
726
727 max = MAX(len, max);
728 }
729
730 return max;
731}
732
Jiri Olsac19ac912016-02-24 09:46:54 +0100733static size_t data_src__printf(u64 data_src)
734{
735 struct mem_info mi = { .data_src.val = data_src };
736 char decode[100];
737 char out[100];
738 static int maxlen;
739 int len;
740
741 perf_script__meminfo_scnprintf(decode, 100, &mi);
742
743 len = scnprintf(out, 100, "%16" PRIx64 " %s", data_src, decode);
744 if (maxlen < len)
745 maxlen = len;
746
747 return printf("%-*s", maxlen, out);
748}
749
Jiri Olsa9cdbc402016-01-07 10:14:05 +0100750static void process_event(struct perf_script *script, union perf_event *event,
Jiri Olsa809e9422015-11-26 18:55:21 +0100751 struct perf_sample *sample, struct perf_evsel *evsel,
752 struct addr_location *al)
David Ahernbe6d8422011-03-09 22:23:23 -0700753{
Arnaldo Carvalho de Melof9d5d542015-04-01 13:29:25 -0300754 struct thread *thread = al->thread;
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300755 struct perf_event_attr *attr = &evsel->attr;
David Ahern1424dc92011-03-09 22:23:28 -0700756
David Ahern2c9e45f72011-03-17 10:03:21 -0600757 if (output[attr->type].fields == 0)
David Ahern1424dc92011-03-09 22:23:28 -0700758 return;
759
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300760 print_sample_start(sample, thread, evsel);
David Ahern745f43e2011-03-09 22:23:26 -0700761
Jiri Olsa535aeaae2014-08-25 16:45:42 +0200762 if (PRINT_FIELD(PERIOD))
763 printf("%10" PRIu64 " ", sample->period);
764
Namhyung Kime944d3d2013-11-18 14:34:52 +0900765 if (PRINT_FIELD(EVNAME)) {
766 const char *evname = perf_evsel__name(evsel);
Jiri Olsa9cdbc402016-01-07 10:14:05 +0100767
768 if (!script->name_width)
769 script->name_width = perf_evlist__max_name_len(script->session->evlist);
770
771 printf("%*s: ", script->name_width,
772 evname ? evname : "[unknown]");
Namhyung Kime944d3d2013-11-18 14:34:52 +0900773 }
774
Adrian Hunter400ea6d2015-04-09 18:54:05 +0300775 if (print_flags)
776 print_sample_flags(sample->flags);
777
Akihiro Nagai95582592012-01-30 13:43:09 +0900778 if (is_bts_event(attr)) {
Arnaldo Carvalho de Melocc22e572013-12-19 17:20:06 -0300779 print_sample_bts(event, sample, evsel, thread, al);
Akihiro Nagai95582592012-01-30 13:43:09 +0900780 return;
781 }
782
David Ahern745f43e2011-03-09 22:23:26 -0700783 if (PRINT_FIELD(TRACE))
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -0300784 event_format__print(evsel->tp_format, sample->cpu,
785 sample->raw_data, sample->raw_size);
David Ahern7cec0922011-05-30 13:08:23 -0600786 if (PRINT_FIELD(ADDR))
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -0300787 print_sample_addr(event, sample, thread, attr);
David Ahern7cec0922011-05-30 13:08:23 -0600788
Jiri Olsa94ddddf2016-02-15 09:34:51 +0100789 if (PRINT_FIELD(DATA_SRC))
Jiri Olsac19ac912016-02-24 09:46:54 +0100790 data_src__printf(sample->data_src);
Jiri Olsa94ddddf2016-02-15 09:34:51 +0100791
792 if (PRINT_FIELD(WEIGHT))
793 printf("%16" PRIu64, sample->weight);
794
David Ahern787bef12011-05-27 14:28:43 -0600795 if (PRINT_FIELD(IP)) {
David Ahernc0230b22011-03-09 22:23:27 -0700796 if (!symbol_conf.use_callchain)
797 printf(" ");
798 else
799 printf("\n");
David Aherna6ffaf92013-08-07 22:50:51 -0400800
Arnaldo Carvalho de Melocc22e572013-12-19 17:20:06 -0300801 perf_evsel__print_ip(evsel, sample, al,
David Ahern307cbb92013-08-07 22:50:53 -0400802 output[attr->type].print_ip_opts,
Adrian Hunter03cd1fe2015-09-25 16:15:49 +0300803 scripting_max_stack);
David Ahernc0230b22011-03-09 22:23:27 -0700804 }
805
Stephane Eranianfc36f942015-08-31 18:41:10 +0200806 if (PRINT_FIELD(IREGS))
807 print_sample_iregs(event, sample, thread, attr);
808
Stephane Eraniandc323ce2015-08-31 18:41:13 +0200809 if (PRINT_FIELD(BRSTACK))
810 print_sample_brstack(event, sample, thread, attr);
811 else if (PRINT_FIELD(BRSTACKSYM))
812 print_sample_brstacksym(event, sample, thread, attr);
813
Wang Nan30372f02016-02-24 11:20:45 +0000814 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
815 print_sample_bpf_output(sample);
816
David Ahernc70c94b2011-03-09 22:23:25 -0700817 printf("\n");
David Ahernbe6d8422011-03-09 22:23:23 -0700818}
819
Tom Zanussi956ffd02009-11-25 01:15:46 -0600820static struct scripting_ops *scripting_ops;
821
Jiri Olsa36e33c52016-01-06 11:49:56 +0100822static void __process_stat(struct perf_evsel *counter, u64 tstamp)
823{
824 int nthreads = thread_map__nr(counter->threads);
825 int ncpus = perf_evsel__nr_cpus(counter);
826 int cpu, thread;
827 static int header_printed;
828
829 if (counter->system_wide)
830 nthreads = 1;
831
832 if (!header_printed) {
833 printf("%3s %8s %15s %15s %15s %15s %s\n",
834 "CPU", "THREAD", "VAL", "ENA", "RUN", "TIME", "EVENT");
835 header_printed = 1;
836 }
837
838 for (thread = 0; thread < nthreads; thread++) {
839 for (cpu = 0; cpu < ncpus; cpu++) {
840 struct perf_counts_values *counts;
841
842 counts = perf_counts(counter->counts, cpu, thread);
843
844 printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n",
845 counter->cpus->map[cpu],
846 thread_map__pid(counter->threads, thread),
847 counts->val,
848 counts->ena,
849 counts->run,
850 tstamp,
851 perf_evsel__name(counter));
852 }
853 }
854}
855
Jiri Olsae099eba2016-01-05 22:09:09 +0100856static void process_stat(struct perf_evsel *counter, u64 tstamp)
857{
858 if (scripting_ops && scripting_ops->process_stat)
859 scripting_ops->process_stat(&stat_config, counter, tstamp);
Jiri Olsa36e33c52016-01-06 11:49:56 +0100860 else
861 __process_stat(counter, tstamp);
Jiri Olsae099eba2016-01-05 22:09:09 +0100862}
863
864static void process_stat_interval(u64 tstamp)
865{
866 if (scripting_ops && scripting_ops->process_stat_interval)
867 scripting_ops->process_stat_interval(tstamp);
868}
869
Tom Zanussi956ffd02009-11-25 01:15:46 -0600870static void setup_scripting(void)
871{
Tom Zanussi16c632d2009-11-25 01:15:48 -0600872 setup_perl_scripting();
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600873 setup_python_scripting();
Tom Zanussi956ffd02009-11-25 01:15:46 -0600874}
875
Adrian Hunterd445dd22014-08-15 22:08:37 +0300876static int flush_scripting(void)
877{
Jiri Olsa2aaecfc2015-11-26 14:55:23 +0100878 return scripting_ops ? scripting_ops->flush_script() : 0;
Adrian Hunterd445dd22014-08-15 22:08:37 +0300879}
880
Tom Zanussi956ffd02009-11-25 01:15:46 -0600881static int cleanup_scripting(void)
882{
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100883 pr_debug("\nperf script stopped\n");
Tom Zanussi3824a4e2010-05-09 23:46:57 -0500884
Jiri Olsa2aaecfc2015-11-26 14:55:23 +0100885 return scripting_ops ? scripting_ops->stop_script() : 0;
Tom Zanussi956ffd02009-11-25 01:15:46 -0600886}
887
Jiri Olsa809e9422015-11-26 18:55:21 +0100888static int process_sample_event(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200889 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200890 struct perf_sample *sample,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300891 struct perf_evsel *evsel,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200892 struct machine *machine)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200893{
Jiri Olsa809e9422015-11-26 18:55:21 +0100894 struct perf_script *scr = container_of(tool, struct perf_script, tool);
David Aherne7984b72011-11-21 10:02:52 -0700895 struct addr_location al;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200896
David Ahern1424dc92011-03-09 22:23:28 -0700897 if (debug_mode) {
898 if (sample->time < last_timestamp) {
899 pr_err("Samples misordered, previous: %" PRIu64
900 " this: %" PRIu64 "\n", last_timestamp,
901 sample->time);
902 nr_unordered++;
Frederic Weisbeckere1889d72010-04-24 01:55:09 +0200903 }
David Ahern1424dc92011-03-09 22:23:28 -0700904 last_timestamp = sample->time;
905 return 0;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200906 }
Anton Blanchard5d67be92011-07-04 21:57:50 +1000907
Adrian Huntere44baa32013-08-08 14:32:25 +0300908 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
David Aherne7984b72011-11-21 10:02:52 -0700909 pr_err("problem processing %d event, skipping it.\n",
910 event->header.type);
911 return -1;
912 }
913
914 if (al.filtered)
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300915 goto out_put;
David Aherne7984b72011-11-21 10:02:52 -0700916
Anton Blanchard5d67be92011-07-04 21:57:50 +1000917 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300918 goto out_put;
Anton Blanchard5d67be92011-07-04 21:57:50 +1000919
Jiri Olsa2aaecfc2015-11-26 14:55:23 +0100920 if (scripting_ops)
921 scripting_ops->process_event(event, sample, evsel, &al);
922 else
Jiri Olsa809e9422015-11-26 18:55:21 +0100923 process_event(scr, event, sample, evsel, &al);
Jiri Olsa2aaecfc2015-11-26 14:55:23 +0100924
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300925out_put:
926 addr_location__put(&al);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200927 return 0;
928}
929
Adrian Hunter7ea95722013-11-01 15:51:30 +0200930static int process_attr(struct perf_tool *tool, union perf_event *event,
931 struct perf_evlist **pevlist)
932{
933 struct perf_script *scr = container_of(tool, struct perf_script, tool);
934 struct perf_evlist *evlist;
935 struct perf_evsel *evsel, *pos;
936 int err;
937
938 err = perf_event__process_attr(tool, event, pevlist);
939 if (err)
940 return err;
941
942 evlist = *pevlist;
943 evsel = perf_evlist__last(*pevlist);
944
945 if (evsel->attr.type >= PERF_TYPE_MAX)
946 return 0;
947
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -0300948 evlist__for_each(evlist, pos) {
Adrian Hunter7ea95722013-11-01 15:51:30 +0200949 if (pos->attr.type == evsel->attr.type && pos != evsel)
950 return 0;
951 }
952
953 set_print_ip_opts(&evsel->attr);
954
Jiri Olsad2b5a312015-10-16 12:41:25 +0200955 if (evsel->attr.sample_type)
956 err = perf_evsel__check_attr(evsel, scr->session);
957
958 return err;
Adrian Hunter7ea95722013-11-01 15:51:30 +0200959}
960
Namhyung Kimad7ebb92013-11-26 17:51:12 +0900961static int process_comm_event(struct perf_tool *tool,
962 union perf_event *event,
963 struct perf_sample *sample,
964 struct machine *machine)
965{
966 struct thread *thread;
967 struct perf_script *script = container_of(tool, struct perf_script, tool);
968 struct perf_session *session = script->session;
Adrian Hunter06b234e2015-07-21 12:44:05 +0300969 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
Namhyung Kimad7ebb92013-11-26 17:51:12 +0900970 int ret = -1;
971
972 thread = machine__findnew_thread(machine, event->comm.pid, event->comm.tid);
973 if (thread == NULL) {
974 pr_debug("problem processing COMM event, skipping it.\n");
975 return -1;
976 }
977
978 if (perf_event__process_comm(tool, event, sample, machine) < 0)
979 goto out;
980
981 if (!evsel->attr.sample_id_all) {
982 sample->cpu = 0;
983 sample->time = 0;
984 sample->tid = event->comm.tid;
985 sample->pid = event->comm.pid;
986 }
987 print_sample_start(sample, thread, evsel);
988 perf_event__fprintf(event, stdout);
989 ret = 0;
Namhyung Kimad7ebb92013-11-26 17:51:12 +0900990out:
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300991 thread__put(thread);
Namhyung Kimad7ebb92013-11-26 17:51:12 +0900992 return ret;
993}
994
995static int process_fork_event(struct perf_tool *tool,
996 union perf_event *event,
997 struct perf_sample *sample,
998 struct machine *machine)
999{
1000 struct thread *thread;
1001 struct perf_script *script = container_of(tool, struct perf_script, tool);
1002 struct perf_session *session = script->session;
Adrian Hunter06b234e2015-07-21 12:44:05 +03001003 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001004
1005 if (perf_event__process_fork(tool, event, sample, machine) < 0)
1006 return -1;
1007
1008 thread = machine__findnew_thread(machine, event->fork.pid, event->fork.tid);
1009 if (thread == NULL) {
1010 pr_debug("problem processing FORK event, skipping it.\n");
1011 return -1;
1012 }
1013
1014 if (!evsel->attr.sample_id_all) {
1015 sample->cpu = 0;
1016 sample->time = event->fork.time;
1017 sample->tid = event->fork.tid;
1018 sample->pid = event->fork.pid;
1019 }
1020 print_sample_start(sample, thread, evsel);
1021 perf_event__fprintf(event, stdout);
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -03001022 thread__put(thread);
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001023
1024 return 0;
1025}
1026static int process_exit_event(struct perf_tool *tool,
1027 union perf_event *event,
1028 struct perf_sample *sample,
1029 struct machine *machine)
1030{
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -03001031 int err = 0;
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001032 struct thread *thread;
1033 struct perf_script *script = container_of(tool, struct perf_script, tool);
1034 struct perf_session *session = script->session;
Adrian Hunter06b234e2015-07-21 12:44:05 +03001035 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001036
1037 thread = machine__findnew_thread(machine, event->fork.pid, event->fork.tid);
1038 if (thread == NULL) {
1039 pr_debug("problem processing EXIT event, skipping it.\n");
1040 return -1;
1041 }
1042
1043 if (!evsel->attr.sample_id_all) {
1044 sample->cpu = 0;
1045 sample->time = 0;
Adrian Hunter53ff6bc32015-08-18 12:07:05 +03001046 sample->tid = event->fork.tid;
1047 sample->pid = event->fork.pid;
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001048 }
1049 print_sample_start(sample, thread, evsel);
1050 perf_event__fprintf(event, stdout);
1051
1052 if (perf_event__process_exit(tool, event, sample, machine) < 0)
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -03001053 err = -1;
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001054
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -03001055 thread__put(thread);
1056 return err;
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001057}
1058
Namhyung Kimba1ddf42013-11-26 17:54:26 +09001059static int process_mmap_event(struct perf_tool *tool,
1060 union perf_event *event,
1061 struct perf_sample *sample,
1062 struct machine *machine)
1063{
1064 struct thread *thread;
1065 struct perf_script *script = container_of(tool, struct perf_script, tool);
1066 struct perf_session *session = script->session;
Adrian Hunter06b234e2015-07-21 12:44:05 +03001067 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
Namhyung Kimba1ddf42013-11-26 17:54:26 +09001068
1069 if (perf_event__process_mmap(tool, event, sample, machine) < 0)
1070 return -1;
1071
1072 thread = machine__findnew_thread(machine, event->mmap.pid, event->mmap.tid);
1073 if (thread == NULL) {
1074 pr_debug("problem processing MMAP event, skipping it.\n");
1075 return -1;
1076 }
1077
1078 if (!evsel->attr.sample_id_all) {
1079 sample->cpu = 0;
1080 sample->time = 0;
1081 sample->tid = event->mmap.tid;
1082 sample->pid = event->mmap.pid;
1083 }
1084 print_sample_start(sample, thread, evsel);
1085 perf_event__fprintf(event, stdout);
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -03001086 thread__put(thread);
Namhyung Kimba1ddf42013-11-26 17:54:26 +09001087 return 0;
1088}
1089
1090static int process_mmap2_event(struct perf_tool *tool,
1091 union perf_event *event,
1092 struct perf_sample *sample,
1093 struct machine *machine)
1094{
1095 struct thread *thread;
1096 struct perf_script *script = container_of(tool, struct perf_script, tool);
1097 struct perf_session *session = script->session;
Adrian Hunter06b234e2015-07-21 12:44:05 +03001098 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
Namhyung Kimba1ddf42013-11-26 17:54:26 +09001099
1100 if (perf_event__process_mmap2(tool, event, sample, machine) < 0)
1101 return -1;
1102
1103 thread = machine__findnew_thread(machine, event->mmap2.pid, event->mmap2.tid);
1104 if (thread == NULL) {
1105 pr_debug("problem processing MMAP2 event, skipping it.\n");
1106 return -1;
1107 }
1108
1109 if (!evsel->attr.sample_id_all) {
1110 sample->cpu = 0;
1111 sample->time = 0;
1112 sample->tid = event->mmap2.tid;
1113 sample->pid = event->mmap2.pid;
1114 }
1115 print_sample_start(sample, thread, evsel);
1116 perf_event__fprintf(event, stdout);
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -03001117 thread__put(thread);
Namhyung Kimba1ddf42013-11-26 17:54:26 +09001118 return 0;
1119}
1120
Adrian Hunter7c148982015-07-21 12:44:06 +03001121static int process_switch_event(struct perf_tool *tool,
1122 union perf_event *event,
1123 struct perf_sample *sample,
1124 struct machine *machine)
1125{
1126 struct thread *thread;
1127 struct perf_script *script = container_of(tool, struct perf_script, tool);
1128 struct perf_session *session = script->session;
1129 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
1130
1131 if (perf_event__process_switch(tool, event, sample, machine) < 0)
1132 return -1;
1133
1134 thread = machine__findnew_thread(machine, sample->pid,
1135 sample->tid);
1136 if (thread == NULL) {
1137 pr_debug("problem processing SWITCH event, skipping it.\n");
1138 return -1;
1139 }
1140
1141 print_sample_start(sample, thread, evsel);
1142 perf_event__fprintf(event, stdout);
1143 thread__put(thread);
1144 return 0;
1145}
1146
Irina Tirdea1d037ca2012-09-11 01:15:03 +03001147static void sig_handler(int sig __maybe_unused)
Tom Zanussic239da32010-04-01 23:59:18 -05001148{
1149 session_done = 1;
1150}
1151
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03001152static int __cmd_script(struct perf_script *script)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001153{
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +02001154 int ret;
1155
Tom Zanussic239da32010-04-01 23:59:18 -05001156 signal(SIGINT, sig_handler);
1157
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001158 /* override event processing functions */
1159 if (script->show_task_events) {
1160 script->tool.comm = process_comm_event;
1161 script->tool.fork = process_fork_event;
1162 script->tool.exit = process_exit_event;
1163 }
Namhyung Kimba1ddf42013-11-26 17:54:26 +09001164 if (script->show_mmap_events) {
1165 script->tool.mmap = process_mmap_event;
1166 script->tool.mmap2 = process_mmap2_event;
1167 }
Adrian Hunter7c148982015-07-21 12:44:06 +03001168 if (script->show_switch_events)
1169 script->tool.context_switch = process_switch_event;
Namhyung Kimad7ebb92013-11-26 17:51:12 +09001170
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -03001171 ret = perf_session__process_events(script->session);
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +02001172
Arnaldo Carvalho de Melo6d8afb52011-01-04 16:27:30 -02001173 if (debug_mode)
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -02001174 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +02001175
1176 return ret;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001177}
1178
Tom Zanussi956ffd02009-11-25 01:15:46 -06001179struct script_spec {
1180 struct list_head node;
1181 struct scripting_ops *ops;
1182 char spec[0];
1183};
1184
Arnaldo Carvalho de Meloeccdfe22011-01-04 16:32:52 -02001185static LIST_HEAD(script_specs);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001186
1187static struct script_spec *script_spec__new(const char *spec,
1188 struct scripting_ops *ops)
1189{
1190 struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
1191
1192 if (s != NULL) {
1193 strcpy(s->spec, spec);
1194 s->ops = ops;
1195 }
1196
1197 return s;
1198}
1199
Tom Zanussi956ffd02009-11-25 01:15:46 -06001200static void script_spec__add(struct script_spec *s)
1201{
1202 list_add_tail(&s->node, &script_specs);
1203}
1204
1205static struct script_spec *script_spec__find(const char *spec)
1206{
1207 struct script_spec *s;
1208
1209 list_for_each_entry(s, &script_specs, node)
1210 if (strcasecmp(s->spec, spec) == 0)
1211 return s;
1212 return NULL;
1213}
1214
1215static struct script_spec *script_spec__findnew(const char *spec,
1216 struct scripting_ops *ops)
1217{
1218 struct script_spec *s = script_spec__find(spec);
1219
1220 if (s)
1221 return s;
1222
1223 s = script_spec__new(spec, ops);
1224 if (!s)
Namhyung Kim466e2872011-12-28 00:35:51 +09001225 return NULL;
Tom Zanussi956ffd02009-11-25 01:15:46 -06001226
1227 script_spec__add(s);
1228
1229 return s;
Tom Zanussi956ffd02009-11-25 01:15:46 -06001230}
1231
1232int script_spec_register(const char *spec, struct scripting_ops *ops)
1233{
1234 struct script_spec *s;
1235
1236 s = script_spec__find(spec);
1237 if (s)
1238 return -1;
1239
1240 s = script_spec__findnew(spec, ops);
1241 if (!s)
1242 return -1;
1243
1244 return 0;
1245}
1246
1247static struct scripting_ops *script_spec__lookup(const char *spec)
1248{
1249 struct script_spec *s = script_spec__find(spec);
1250 if (!s)
1251 return NULL;
1252
1253 return s->ops;
1254}
1255
1256static void list_available_languages(void)
1257{
1258 struct script_spec *s;
1259
1260 fprintf(stderr, "\n");
1261 fprintf(stderr, "Scripting language extensions (used in "
Ingo Molnar133dc4c2010-11-16 18:45:39 +01001262 "perf script -s [spec:]script.[spec]):\n\n");
Tom Zanussi956ffd02009-11-25 01:15:46 -06001263
1264 list_for_each_entry(s, &script_specs, node)
1265 fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name);
1266
1267 fprintf(stderr, "\n");
1268}
1269
Irina Tirdea1d037ca2012-09-11 01:15:03 +03001270static int parse_scriptname(const struct option *opt __maybe_unused,
1271 const char *str, int unset __maybe_unused)
Tom Zanussi956ffd02009-11-25 01:15:46 -06001272{
1273 char spec[PATH_MAX];
1274 const char *script, *ext;
1275 int len;
1276
Tom Zanussif526d682010-01-27 02:27:52 -06001277 if (strcmp(str, "lang") == 0) {
Tom Zanussi956ffd02009-11-25 01:15:46 -06001278 list_available_languages();
Tom Zanussif526d682010-01-27 02:27:52 -06001279 exit(0);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001280 }
1281
1282 script = strchr(str, ':');
1283 if (script) {
1284 len = script - str;
1285 if (len >= PATH_MAX) {
1286 fprintf(stderr, "invalid language specifier");
1287 return -1;
1288 }
1289 strncpy(spec, str, len);
1290 spec[len] = '\0';
1291 scripting_ops = script_spec__lookup(spec);
1292 if (!scripting_ops) {
1293 fprintf(stderr, "invalid language specifier");
1294 return -1;
1295 }
1296 script++;
1297 } else {
1298 script = str;
Ben Hutchingsd1e95bb2010-10-10 16:11:02 +01001299 ext = strrchr(script, '.');
Tom Zanussi956ffd02009-11-25 01:15:46 -06001300 if (!ext) {
1301 fprintf(stderr, "invalid script extension");
1302 return -1;
1303 }
1304 scripting_ops = script_spec__lookup(++ext);
1305 if (!scripting_ops) {
1306 fprintf(stderr, "invalid script extension");
1307 return -1;
1308 }
1309 }
1310
1311 script_name = strdup(script);
1312
1313 return 0;
1314}
1315
Irina Tirdea1d037ca2012-09-11 01:15:03 +03001316static int parse_output_fields(const struct option *opt __maybe_unused,
1317 const char *arg, int unset __maybe_unused)
David Ahern745f43e2011-03-09 22:23:26 -07001318{
1319 char *tok;
Sasha Levin50ca19a2012-12-20 14:11:19 -05001320 int i, imax = ARRAY_SIZE(all_output_options);
David Ahern2c9e45f72011-03-17 10:03:21 -06001321 int j;
David Ahern745f43e2011-03-09 22:23:26 -07001322 int rc = 0;
1323 char *str = strdup(arg);
David Ahern1424dc92011-03-09 22:23:28 -07001324 int type = -1;
David Ahern745f43e2011-03-09 22:23:26 -07001325
1326 if (!str)
1327 return -ENOMEM;
1328
David Ahern2c9e45f72011-03-17 10:03:21 -06001329 /* first word can state for which event type the user is specifying
1330 * the fields. If no type exists, the specified fields apply to all
1331 * event types found in the file minus the invalid fields for a type.
David Ahern1424dc92011-03-09 22:23:28 -07001332 */
David Ahern2c9e45f72011-03-17 10:03:21 -06001333 tok = strchr(str, ':');
1334 if (tok) {
1335 *tok = '\0';
1336 tok++;
1337 if (!strcmp(str, "hw"))
1338 type = PERF_TYPE_HARDWARE;
1339 else if (!strcmp(str, "sw"))
1340 type = PERF_TYPE_SOFTWARE;
1341 else if (!strcmp(str, "trace"))
1342 type = PERF_TYPE_TRACEPOINT;
Arun Sharma0817a6a2011-04-14 10:38:18 -07001343 else if (!strcmp(str, "raw"))
1344 type = PERF_TYPE_RAW;
Wang Nan27cfef02015-12-08 02:25:43 +00001345 else if (!strcmp(str, "break"))
1346 type = PERF_TYPE_BREAKPOINT;
David Ahern2c9e45f72011-03-17 10:03:21 -06001347 else {
1348 fprintf(stderr, "Invalid event type in field string.\n");
Robert Richter38efb532011-11-25 11:38:40 +01001349 rc = -EINVAL;
1350 goto out;
David Ahern2c9e45f72011-03-17 10:03:21 -06001351 }
1352
1353 if (output[type].user_set)
1354 pr_warning("Overriding previous field request for %s events.\n",
1355 event_type(type));
1356
1357 output[type].fields = 0;
1358 output[type].user_set = true;
David Ahern9cbdb702011-04-06 21:54:20 -06001359 output[type].wildcard_set = false;
David Ahern2c9e45f72011-03-17 10:03:21 -06001360
1361 } else {
1362 tok = str;
1363 if (strlen(str) == 0) {
1364 fprintf(stderr,
1365 "Cannot set fields to 'none' for all event types.\n");
1366 rc = -EINVAL;
1367 goto out;
1368 }
1369
1370 if (output_set_by_user())
1371 pr_warning("Overriding previous field request for all events.\n");
1372
1373 for (j = 0; j < PERF_TYPE_MAX; ++j) {
1374 output[j].fields = 0;
1375 output[j].user_set = true;
David Ahern9cbdb702011-04-06 21:54:20 -06001376 output[j].wildcard_set = true;
David Ahern2c9e45f72011-03-17 10:03:21 -06001377 }
David Ahern1424dc92011-03-09 22:23:28 -07001378 }
1379
Adrian Hunter400ea6d2015-04-09 18:54:05 +03001380 for (tok = strtok(tok, ","); tok; tok = strtok(NULL, ",")) {
David Ahern745f43e2011-03-09 22:23:26 -07001381 for (i = 0; i < imax; ++i) {
David Ahern2c9e45f72011-03-17 10:03:21 -06001382 if (strcmp(tok, all_output_options[i].str) == 0)
David Ahern745f43e2011-03-09 22:23:26 -07001383 break;
David Ahern745f43e2011-03-09 22:23:26 -07001384 }
Adrian Hunter400ea6d2015-04-09 18:54:05 +03001385 if (i == imax && strcmp(tok, "flags") == 0) {
1386 print_flags = true;
1387 continue;
1388 }
David Ahern745f43e2011-03-09 22:23:26 -07001389 if (i == imax) {
David Ahern2c9e45f72011-03-17 10:03:21 -06001390 fprintf(stderr, "Invalid field requested.\n");
David Ahern745f43e2011-03-09 22:23:26 -07001391 rc = -EINVAL;
David Ahern2c9e45f72011-03-17 10:03:21 -06001392 goto out;
1393 }
1394
1395 if (type == -1) {
1396 /* add user option to all events types for
1397 * which it is valid
1398 */
1399 for (j = 0; j < PERF_TYPE_MAX; ++j) {
1400 if (output[j].invalid_fields & all_output_options[i].field) {
1401 pr_warning("\'%s\' not valid for %s events. Ignoring.\n",
1402 all_output_options[i].str, event_type(j));
1403 } else
1404 output[j].fields |= all_output_options[i].field;
1405 }
1406 } else {
1407 if (output[type].invalid_fields & all_output_options[i].field) {
1408 fprintf(stderr, "\'%s\' not valid for %s events.\n",
1409 all_output_options[i].str, event_type(type));
1410
1411 rc = -EINVAL;
1412 goto out;
1413 }
1414 output[type].fields |= all_output_options[i].field;
1415 }
David Ahern2c9e45f72011-03-17 10:03:21 -06001416 }
1417
1418 if (type >= 0) {
1419 if (output[type].fields == 0) {
1420 pr_debug("No fields requested for %s type. "
1421 "Events will not be displayed.\n", event_type(type));
David Ahern745f43e2011-03-09 22:23:26 -07001422 }
David Ahern1424dc92011-03-09 22:23:28 -07001423 }
David Ahern745f43e2011-03-09 22:23:26 -07001424
David Ahern2c9e45f72011-03-17 10:03:21 -06001425out:
David Ahern745f43e2011-03-09 22:23:26 -07001426 free(str);
1427 return rc;
1428}
1429
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001430/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
1431static int is_directory(const char *base_path, const struct dirent *dent)
1432{
1433 char path[PATH_MAX];
1434 struct stat st;
1435
1436 sprintf(path, "%s/%s", base_path, dent->d_name);
1437 if (stat(path, &st))
1438 return 0;
1439
1440 return S_ISDIR(st.st_mode);
1441}
1442
1443#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001444 while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
1445 lang_next) \
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001446 if ((lang_dirent.d_type == DT_DIR || \
1447 (lang_dirent.d_type == DT_UNKNOWN && \
1448 is_directory(scripts_path, &lang_dirent))) && \
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001449 (strcmp(lang_dirent.d_name, ".")) && \
1450 (strcmp(lang_dirent.d_name, "..")))
1451
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001452#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001453 while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
1454 script_next) \
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001455 if (script_dirent.d_type != DT_DIR && \
1456 (script_dirent.d_type != DT_UNKNOWN || \
1457 !is_directory(lang_path, &script_dirent)))
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001458
1459
1460#define RECORD_SUFFIX "-record"
1461#define REPORT_SUFFIX "-report"
1462
1463struct script_desc {
1464 struct list_head node;
1465 char *name;
1466 char *half_liner;
1467 char *args;
1468};
1469
Arnaldo Carvalho de Meloeccdfe22011-01-04 16:32:52 -02001470static LIST_HEAD(script_descs);
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001471
1472static struct script_desc *script_desc__new(const char *name)
1473{
1474 struct script_desc *s = zalloc(sizeof(*s));
1475
Tom Zanussib5b87312010-11-10 08:16:51 -06001476 if (s != NULL && name)
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001477 s->name = strdup(name);
1478
1479 return s;
1480}
1481
1482static void script_desc__delete(struct script_desc *s)
1483{
Arnaldo Carvalho de Melo74cf2492013-12-27 16:55:14 -03001484 zfree(&s->name);
1485 zfree(&s->half_liner);
1486 zfree(&s->args);
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001487 free(s);
1488}
1489
1490static void script_desc__add(struct script_desc *s)
1491{
1492 list_add_tail(&s->node, &script_descs);
1493}
1494
1495static struct script_desc *script_desc__find(const char *name)
1496{
1497 struct script_desc *s;
1498
1499 list_for_each_entry(s, &script_descs, node)
1500 if (strcasecmp(s->name, name) == 0)
1501 return s;
1502 return NULL;
1503}
1504
1505static struct script_desc *script_desc__findnew(const char *name)
1506{
1507 struct script_desc *s = script_desc__find(name);
1508
1509 if (s)
1510 return s;
1511
1512 s = script_desc__new(name);
1513 if (!s)
1514 goto out_delete_desc;
1515
1516 script_desc__add(s);
1517
1518 return s;
1519
1520out_delete_desc:
1521 script_desc__delete(s);
1522
1523 return NULL;
1524}
1525
Stephane Eranian965bb6b2010-12-03 17:52:01 +02001526static const char *ends_with(const char *str, const char *suffix)
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001527{
1528 size_t suffix_len = strlen(suffix);
Stephane Eranian965bb6b2010-12-03 17:52:01 +02001529 const char *p = str;
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001530
1531 if (strlen(str) > suffix_len) {
1532 p = str + strlen(str) - suffix_len;
1533 if (!strncmp(p, suffix, suffix_len))
1534 return p;
1535 }
1536
1537 return NULL;
1538}
1539
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001540static int read_script_info(struct script_desc *desc, const char *filename)
1541{
1542 char line[BUFSIZ], *p;
1543 FILE *fp;
1544
1545 fp = fopen(filename, "r");
1546 if (!fp)
1547 return -1;
1548
1549 while (fgets(line, sizeof(line), fp)) {
1550 p = ltrim(line);
1551 if (strlen(p) == 0)
1552 continue;
1553 if (*p != '#')
1554 continue;
1555 p++;
1556 if (strlen(p) && *p == '!')
1557 continue;
1558
1559 p = ltrim(p);
1560 if (strlen(p) && p[strlen(p) - 1] == '\n')
1561 p[strlen(p) - 1] = '\0';
1562
1563 if (!strncmp(p, "description:", strlen("description:"))) {
1564 p += strlen("description:");
1565 desc->half_liner = strdup(ltrim(p));
1566 continue;
1567 }
1568
1569 if (!strncmp(p, "args:", strlen("args:"))) {
1570 p += strlen("args:");
1571 desc->args = strdup(ltrim(p));
1572 continue;
1573 }
1574 }
1575
1576 fclose(fp);
1577
1578 return 0;
1579}
1580
Robert Richter38efb532011-11-25 11:38:40 +01001581static char *get_script_root(struct dirent *script_dirent, const char *suffix)
1582{
1583 char *script_root, *str;
1584
1585 script_root = strdup(script_dirent->d_name);
1586 if (!script_root)
1587 return NULL;
1588
1589 str = (char *)ends_with(script_root, suffix);
1590 if (!str) {
1591 free(script_root);
1592 return NULL;
1593 }
1594
1595 *str = '\0';
1596 return script_root;
1597}
1598
Irina Tirdea1d037ca2012-09-11 01:15:03 +03001599static int list_available_scripts(const struct option *opt __maybe_unused,
1600 const char *s __maybe_unused,
1601 int unset __maybe_unused)
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001602{
1603 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
1604 char scripts_path[MAXPATHLEN];
1605 DIR *scripts_dir, *lang_dir;
1606 char script_path[MAXPATHLEN];
1607 char lang_path[MAXPATHLEN];
1608 struct script_desc *desc;
1609 char first_half[BUFSIZ];
1610 char *script_root;
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001611
Josh Poimboeuf46113a52015-12-15 09:39:37 -06001612 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001613
1614 scripts_dir = opendir(scripts_path);
1615 if (!scripts_dir)
1616 return -1;
1617
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001618 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001619 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
1620 lang_dirent.d_name);
1621 lang_dir = opendir(lang_path);
1622 if (!lang_dir)
1623 continue;
1624
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001625 for_each_script(lang_path, lang_dir, script_dirent, script_next) {
Robert Richter38efb532011-11-25 11:38:40 +01001626 script_root = get_script_root(&script_dirent, REPORT_SUFFIX);
1627 if (script_root) {
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001628 desc = script_desc__findnew(script_root);
1629 snprintf(script_path, MAXPATHLEN, "%s/%s",
1630 lang_path, script_dirent.d_name);
1631 read_script_info(desc, script_path);
Robert Richter38efb532011-11-25 11:38:40 +01001632 free(script_root);
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001633 }
Tom Zanussi4b9c0c52009-12-15 02:53:38 -06001634 }
1635 }
1636
1637 fprintf(stdout, "List of available trace scripts:\n");
1638 list_for_each_entry(desc, &script_descs, node) {
1639 sprintf(first_half, "%s %s", desc->name,
1640 desc->args ? desc->args : "");
1641 fprintf(stdout, " %-36s %s\n", first_half,
1642 desc->half_liner ? desc->half_liner : "");
1643 }
1644
1645 exit(0);
1646}
1647
Feng Tange5f37052012-09-07 16:42:26 +08001648/*
Feng Tang49e639e2012-10-30 11:56:03 +08001649 * Some scripts specify the required events in their "xxx-record" file,
1650 * this function will check if the events in perf.data match those
1651 * mentioned in the "xxx-record".
1652 *
1653 * Fixme: All existing "xxx-record" are all in good formats "-e event ",
1654 * which is covered well now. And new parsing code should be added to
1655 * cover the future complexing formats like event groups etc.
1656 */
1657static int check_ev_match(char *dir_name, char *scriptname,
1658 struct perf_session *session)
1659{
1660 char filename[MAXPATHLEN], evname[128];
1661 char line[BUFSIZ], *p;
1662 struct perf_evsel *pos;
1663 int match, len;
1664 FILE *fp;
1665
1666 sprintf(filename, "%s/bin/%s-record", dir_name, scriptname);
1667
1668 fp = fopen(filename, "r");
1669 if (!fp)
1670 return -1;
1671
1672 while (fgets(line, sizeof(line), fp)) {
1673 p = ltrim(line);
1674 if (*p == '#')
1675 continue;
1676
1677 while (strlen(p)) {
1678 p = strstr(p, "-e");
1679 if (!p)
1680 break;
1681
1682 p += 2;
1683 p = ltrim(p);
1684 len = strcspn(p, " \t");
1685 if (!len)
1686 break;
1687
1688 snprintf(evname, len + 1, "%s", p);
1689
1690 match = 0;
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -03001691 evlist__for_each(session->evlist, pos) {
Feng Tang49e639e2012-10-30 11:56:03 +08001692 if (!strcmp(perf_evsel__name(pos), evname)) {
1693 match = 1;
1694 break;
1695 }
1696 }
1697
1698 if (!match) {
1699 fclose(fp);
1700 return -1;
1701 }
1702 }
1703 }
1704
1705 fclose(fp);
1706 return 0;
1707}
1708
1709/*
Feng Tange5f37052012-09-07 16:42:26 +08001710 * Return -1 if none is found, otherwise the actual scripts number.
1711 *
1712 * Currently the only user of this function is the script browser, which
1713 * will list all statically runnable scripts, select one, execute it and
1714 * show the output in a perf browser.
1715 */
1716int find_scripts(char **scripts_array, char **scripts_path_array)
1717{
1718 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
Feng Tang49e639e2012-10-30 11:56:03 +08001719 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
Feng Tange5f37052012-09-07 16:42:26 +08001720 DIR *scripts_dir, *lang_dir;
Feng Tang49e639e2012-10-30 11:56:03 +08001721 struct perf_session *session;
Jiri Olsaf5fc14122013-10-15 16:27:32 +02001722 struct perf_data_file file = {
1723 .path = input_name,
1724 .mode = PERF_DATA_MODE_READ,
1725 };
Feng Tange5f37052012-09-07 16:42:26 +08001726 char *temp;
1727 int i = 0;
1728
Jiri Olsaf5fc14122013-10-15 16:27:32 +02001729 session = perf_session__new(&file, false, NULL);
Feng Tang49e639e2012-10-30 11:56:03 +08001730 if (!session)
1731 return -1;
1732
Josh Poimboeuf46113a52015-12-15 09:39:37 -06001733 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
Feng Tange5f37052012-09-07 16:42:26 +08001734
1735 scripts_dir = opendir(scripts_path);
Feng Tang49e639e2012-10-30 11:56:03 +08001736 if (!scripts_dir) {
1737 perf_session__delete(session);
Feng Tange5f37052012-09-07 16:42:26 +08001738 return -1;
Feng Tang49e639e2012-10-30 11:56:03 +08001739 }
Feng Tange5f37052012-09-07 16:42:26 +08001740
1741 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
1742 snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
1743 lang_dirent.d_name);
1744#ifdef NO_LIBPERL
1745 if (strstr(lang_path, "perl"))
1746 continue;
1747#endif
1748#ifdef NO_LIBPYTHON
1749 if (strstr(lang_path, "python"))
1750 continue;
1751#endif
1752
1753 lang_dir = opendir(lang_path);
1754 if (!lang_dir)
1755 continue;
1756
1757 for_each_script(lang_path, lang_dir, script_dirent, script_next) {
1758 /* Skip those real time scripts: xxxtop.p[yl] */
1759 if (strstr(script_dirent.d_name, "top."))
1760 continue;
1761 sprintf(scripts_path_array[i], "%s/%s", lang_path,
1762 script_dirent.d_name);
1763 temp = strchr(script_dirent.d_name, '.');
1764 snprintf(scripts_array[i],
1765 (temp - script_dirent.d_name) + 1,
1766 "%s", script_dirent.d_name);
Feng Tang49e639e2012-10-30 11:56:03 +08001767
1768 if (check_ev_match(lang_path,
1769 scripts_array[i], session))
1770 continue;
1771
Feng Tange5f37052012-09-07 16:42:26 +08001772 i++;
1773 }
Feng Tang49e639e2012-10-30 11:56:03 +08001774 closedir(lang_dir);
Feng Tange5f37052012-09-07 16:42:26 +08001775 }
1776
Feng Tang49e639e2012-10-30 11:56:03 +08001777 closedir(scripts_dir);
1778 perf_session__delete(session);
Feng Tange5f37052012-09-07 16:42:26 +08001779 return i;
1780}
1781
Tom Zanussi38752942009-12-15 02:53:39 -06001782static char *get_script_path(const char *script_root, const char *suffix)
1783{
1784 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
1785 char scripts_path[MAXPATHLEN];
1786 char script_path[MAXPATHLEN];
1787 DIR *scripts_dir, *lang_dir;
1788 char lang_path[MAXPATHLEN];
Robert Richter38efb532011-11-25 11:38:40 +01001789 char *__script_root;
Tom Zanussi38752942009-12-15 02:53:39 -06001790
Josh Poimboeuf46113a52015-12-15 09:39:37 -06001791 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
Tom Zanussi38752942009-12-15 02:53:39 -06001792
1793 scripts_dir = opendir(scripts_path);
1794 if (!scripts_dir)
1795 return NULL;
1796
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001797 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
Tom Zanussi38752942009-12-15 02:53:39 -06001798 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
1799 lang_dirent.d_name);
1800 lang_dir = opendir(lang_path);
1801 if (!lang_dir)
1802 continue;
1803
Shawn Bohrer008f29d2010-11-21 10:09:39 -06001804 for_each_script(lang_path, lang_dir, script_dirent, script_next) {
Robert Richter38efb532011-11-25 11:38:40 +01001805 __script_root = get_script_root(&script_dirent, suffix);
1806 if (__script_root && !strcmp(script_root, __script_root)) {
1807 free(__script_root);
Namhyung Kim946ef2a2012-01-08 02:25:25 +09001808 closedir(lang_dir);
1809 closedir(scripts_dir);
Tom Zanussi38752942009-12-15 02:53:39 -06001810 snprintf(script_path, MAXPATHLEN, "%s/%s",
1811 lang_path, script_dirent.d_name);
Robert Richter38efb532011-11-25 11:38:40 +01001812 return strdup(script_path);
Tom Zanussi38752942009-12-15 02:53:39 -06001813 }
1814 free(__script_root);
1815 }
Namhyung Kim946ef2a2012-01-08 02:25:25 +09001816 closedir(lang_dir);
Tom Zanussi38752942009-12-15 02:53:39 -06001817 }
Namhyung Kim946ef2a2012-01-08 02:25:25 +09001818 closedir(scripts_dir);
Tom Zanussi38752942009-12-15 02:53:39 -06001819
Robert Richter38efb532011-11-25 11:38:40 +01001820 return NULL;
Tom Zanussi38752942009-12-15 02:53:39 -06001821}
1822
Tom Zanussib5b87312010-11-10 08:16:51 -06001823static bool is_top_script(const char *script_path)
1824{
Stephane Eranian965bb6b2010-12-03 17:52:01 +02001825 return ends_with(script_path, "top") == NULL ? false : true;
Tom Zanussib5b87312010-11-10 08:16:51 -06001826}
1827
1828static int has_required_arg(char *script_path)
1829{
1830 struct script_desc *desc;
1831 int n_args = 0;
1832 char *p;
1833
1834 desc = script_desc__new(NULL);
1835
1836 if (read_script_info(desc, script_path))
1837 goto out;
1838
1839 if (!desc->args)
1840 goto out;
1841
1842 for (p = desc->args; *p; p++)
1843 if (*p == '<')
1844 n_args++;
1845out:
1846 script_desc__delete(desc);
1847
1848 return n_args;
1849}
1850
David Ahernd54b1a92012-08-26 12:24:46 -06001851static int have_cmd(int argc, const char **argv)
Tom Zanussi34c86ea2010-11-10 08:15:43 -06001852{
1853 char **__argv = malloc(sizeof(const char *) * argc);
1854
David Ahernd54b1a92012-08-26 12:24:46 -06001855 if (!__argv) {
1856 pr_err("malloc failed\n");
1857 return -1;
1858 }
1859
Tom Zanussi34c86ea2010-11-10 08:15:43 -06001860 memcpy(__argv, argv, sizeof(const char *) * argc);
1861 argc = parse_options(argc, (const char **)__argv, record_options,
1862 NULL, PARSE_OPT_STOP_AT_NON_OPTION);
1863 free(__argv);
1864
David Ahernd54b1a92012-08-26 12:24:46 -06001865 system_wide = (argc == 0);
1866
1867 return 0;
Tom Zanussi34c86ea2010-11-10 08:15:43 -06001868}
1869
Jiri Olsa7322d6c2015-08-13 09:17:24 +02001870static void script__setup_sample_type(struct perf_script *script)
1871{
1872 struct perf_session *session = script->session;
1873 u64 sample_type = perf_evlist__combined_sample_type(session->evlist);
1874
1875 if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) {
1876 if ((sample_type & PERF_SAMPLE_REGS_USER) &&
1877 (sample_type & PERF_SAMPLE_STACK_USER))
1878 callchain_param.record_mode = CALLCHAIN_DWARF;
1879 else if (sample_type & PERF_SAMPLE_BRANCH_STACK)
1880 callchain_param.record_mode = CALLCHAIN_LBR;
1881 else
1882 callchain_param.record_mode = CALLCHAIN_FP;
1883 }
1884}
1885
Jiri Olsae099eba2016-01-05 22:09:09 +01001886static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
1887 union perf_event *event,
1888 struct perf_session *session)
1889{
1890 struct stat_round_event *round = &event->stat_round;
1891 struct perf_evsel *counter;
1892
1893 evlist__for_each(session->evlist, counter) {
1894 perf_stat_process_counter(&stat_config, counter);
1895 process_stat(counter, round->time);
1896 }
1897
1898 process_stat_interval(round->time);
1899 return 0;
1900}
1901
Jiri Olsa91a2c3d2016-01-05 22:09:07 +01001902static int process_stat_config_event(struct perf_tool *tool __maybe_unused,
1903 union perf_event *event,
1904 struct perf_session *session __maybe_unused)
1905{
1906 perf_event__read_stat_config(&stat_config, &event->stat_config);
1907 return 0;
1908}
1909
Jiri Olsacfc88742016-01-05 22:09:06 +01001910static int set_maps(struct perf_script *script)
1911{
1912 struct perf_evlist *evlist = script->session->evlist;
1913
1914 if (!script->cpus || !script->threads)
1915 return 0;
1916
1917 if (WARN_ONCE(script->allocated, "stats double allocation\n"))
1918 return -EINVAL;
1919
1920 perf_evlist__set_maps(evlist, script->cpus, script->threads);
1921
1922 if (perf_evlist__alloc_stats(evlist, true))
1923 return -ENOMEM;
1924
1925 script->allocated = true;
1926 return 0;
1927}
1928
1929static
1930int process_thread_map_event(struct perf_tool *tool,
1931 union perf_event *event,
1932 struct perf_session *session __maybe_unused)
1933{
1934 struct perf_script *script = container_of(tool, struct perf_script, tool);
1935
1936 if (script->threads) {
1937 pr_warning("Extra thread map event, ignoring.\n");
1938 return 0;
1939 }
1940
1941 script->threads = thread_map__new_event(&event->thread_map);
1942 if (!script->threads)
1943 return -ENOMEM;
1944
1945 return set_maps(script);
1946}
1947
1948static
1949int process_cpu_map_event(struct perf_tool *tool __maybe_unused,
1950 union perf_event *event,
1951 struct perf_session *session __maybe_unused)
1952{
1953 struct perf_script *script = container_of(tool, struct perf_script, tool);
1954
1955 if (script->cpus) {
1956 pr_warning("Extra cpu map event, ignoring.\n");
1957 return 0;
1958 }
1959
1960 script->cpus = cpu_map__new_data(&event->cpu_map.data);
1961 if (!script->cpus)
1962 return -ENOMEM;
1963
1964 return set_maps(script);
1965}
1966
Irina Tirdea1d037ca2012-09-11 01:15:03 +03001967int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001968{
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03001969 bool show_full_info = false;
Jiri Olsae90debd2013-12-09 11:02:50 +01001970 bool header = false;
1971 bool header_only = false;
Namhyung Kim6cc870f2014-08-12 15:40:33 +09001972 bool script_started = false;
Tom Zanussib5b87312010-11-10 08:16:51 -06001973 char *rec_script_path = NULL;
1974 char *rep_script_path = NULL;
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -02001975 struct perf_session *session;
Adrian Hunter7a680eb2015-04-09 18:53:56 +03001976 struct itrace_synth_opts itrace_synth_opts = { .set = false, };
Tom Zanussib5b87312010-11-10 08:16:51 -06001977 char *script_path = NULL;
Tom Zanussi38752942009-12-15 02:53:39 -06001978 const char **__argv;
Namhyung Kim6cc870f2014-08-12 15:40:33 +09001979 int i, j, err = 0;
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03001980 struct perf_script script = {
1981 .tool = {
1982 .sample = process_sample_event,
1983 .mmap = perf_event__process_mmap,
1984 .mmap2 = perf_event__process_mmap2,
1985 .comm = perf_event__process_comm,
1986 .exit = perf_event__process_exit,
1987 .fork = perf_event__process_fork,
Adrian Hunter7ea95722013-11-01 15:51:30 +02001988 .attr = process_attr,
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03001989 .tracing_data = perf_event__process_tracing_data,
1990 .build_id = perf_event__process_build_id,
Adrian Hunter7a680eb2015-04-09 18:53:56 +03001991 .id_index = perf_event__process_id_index,
1992 .auxtrace_info = perf_event__process_auxtrace_info,
1993 .auxtrace = perf_event__process_auxtrace,
1994 .auxtrace_error = perf_event__process_auxtrace_error,
Jiri Olsae099eba2016-01-05 22:09:09 +01001995 .stat = perf_event__process_stat_event,
1996 .stat_round = process_stat_round_event,
Jiri Olsa91a2c3d2016-01-05 22:09:07 +01001997 .stat_config = process_stat_config_event,
Jiri Olsacfc88742016-01-05 22:09:06 +01001998 .thread_map = process_thread_map_event,
1999 .cpu_map = process_cpu_map_event,
Jiri Olsa0a8cb852014-07-06 14:18:21 +02002000 .ordered_events = true,
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03002001 .ordering_requires_timestamps = true,
2002 },
2003 };
Yunlong Song06af0f22015-04-02 21:47:16 +08002004 struct perf_data_file file = {
2005 .mode = PERF_DATA_MODE_READ,
2006 };
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002007 const struct option options[] = {
2008 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
2009 "dump raw trace in ASCII"),
2010 OPT_INCR('v', "verbose", &verbose,
2011 "be more verbose (show symbol address, etc)"),
2012 OPT_BOOLEAN('L', "Latency", &latency_format,
2013 "show latency attributes (irqs/preemption disabled, etc)"),
2014 OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
2015 list_available_scripts),
2016 OPT_CALLBACK('s', "script", NULL, "name",
2017 "script file name (lang:script name, script name, or *)",
2018 parse_scriptname),
2019 OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
2020 "generate perf-script.xx script in specified language"),
2021 OPT_STRING('i', "input", &input_name, "file", "input file name"),
2022 OPT_BOOLEAN('d', "debug-mode", &debug_mode,
2023 "do various checks like samples ordering and lost events"),
Jiri Olsae90debd2013-12-09 11:02:50 +01002024 OPT_BOOLEAN(0, "header", &header, "Show data header."),
2025 OPT_BOOLEAN(0, "header-only", &header_only, "Show only data header."),
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002026 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
2027 "file", "vmlinux pathname"),
2028 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
2029 "file", "kallsyms pathname"),
2030 OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
2031 "When printing symbols do not display call chain"),
2032 OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
2033 "Look for files with symbols relative to this directory"),
Yunlong Song06af0f22015-04-02 21:47:16 +08002034 OPT_CALLBACK('F', "fields", NULL, "str",
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002035 "comma separated output fields prepend with 'type:'. "
2036 "Valid types: hw,sw,trace,raw. "
2037 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
Stephane Eraniandc323ce2015-08-31 18:41:13 +02002038 "addr,symoff,period,iregs,brstack,brstacksym,flags", parse_output_fields),
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002039 OPT_BOOLEAN('a', "all-cpus", &system_wide,
2040 "system-wide collection from all CPUs"),
2041 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
2042 "only consider these symbols"),
2043 OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
2044 OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
2045 "only display events for these comms"),
David Aherne03eaa42015-03-24 09:52:41 -06002046 OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
2047 "only consider symbols in these pids"),
2048 OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
2049 "only consider symbols in these tids"),
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002050 OPT_BOOLEAN('I', "show-info", &show_full_info,
2051 "display extended information from perf.data file"),
2052 OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
2053 "Show the path of [kernel.kallsyms]"),
Namhyung Kimad7ebb92013-11-26 17:51:12 +09002054 OPT_BOOLEAN('\0', "show-task-events", &script.show_task_events,
2055 "Show the fork/comm/exit events"),
Namhyung Kimba1ddf42013-11-26 17:54:26 +09002056 OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events,
2057 "Show the mmap events"),
Adrian Hunter7c148982015-07-21 12:44:06 +03002058 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events,
2059 "Show context switch events (if recorded)"),
Yunlong Song06af0f22015-04-02 21:47:16 +08002060 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
Adrian Hunter83e19862015-09-25 16:15:36 +03002061 OPT_BOOLEAN(0, "ns", &nanosecs,
2062 "Use 9 decimal places when displaying time"),
Adrian Hunter7a680eb2015-04-09 18:53:56 +03002063 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
2064 "Instruction Tracing options",
2065 itrace_parse_synth_opts),
Andi Kleena9710ba2015-08-07 15:24:05 -07002066 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
2067 "Show full source file name path for source lines"),
Mark Drayton77e00702015-08-26 12:18:15 -07002068 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
2069 "Enable symbol demangling"),
2070 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
2071 "Enable kernel symbol demangling"),
2072
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002073 OPT_END()
2074 };
Yunlong Song40cae2b2015-03-18 21:35:54 +08002075 const char * const script_subcommands[] = { "record", "report", NULL };
2076 const char *script_usage[] = {
Arnaldo Carvalho de Melo69b64702012-10-01 15:20:58 -03002077 "perf script [<options>]",
2078 "perf script [<options>] record <script> [<record-options>] <command>",
2079 "perf script [<options>] report <script> [script-args]",
2080 "perf script [<options>] <script> [<record-options>] <command>",
2081 "perf script [<options>] <top-script> [script-args]",
2082 NULL
2083 };
Tom Zanussi38752942009-12-15 02:53:39 -06002084
Tom Zanussib5b87312010-11-10 08:16:51 -06002085 setup_scripting();
2086
Yunlong Song40cae2b2015-03-18 21:35:54 +08002087 argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
Tom Zanussib5b87312010-11-10 08:16:51 -06002088 PARSE_OPT_STOP_AT_NON_OPTION);
2089
Jiri Olsaf5fc14122013-10-15 16:27:32 +02002090 file.path = input_name;
2091
Tom Zanussib5b87312010-11-10 08:16:51 -06002092 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
2093 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
2094 if (!rec_script_path)
2095 return cmd_record(argc, argv, NULL);
Tom Zanussi38752942009-12-15 02:53:39 -06002096 }
2097
Tom Zanussib5b87312010-11-10 08:16:51 -06002098 if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
2099 rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
2100 if (!rep_script_path) {
Tom Zanussi38752942009-12-15 02:53:39 -06002101 fprintf(stderr,
Tom Zanussib5b87312010-11-10 08:16:51 -06002102 "Please specify a valid report script"
Ingo Molnar133dc4c2010-11-16 18:45:39 +01002103 "(see 'perf script -l' for listing)\n");
Tom Zanussi38752942009-12-15 02:53:39 -06002104 return -1;
2105 }
Tom Zanussi38752942009-12-15 02:53:39 -06002106 }
2107
Adrian Hunter3c5b6452015-09-25 16:15:51 +03002108 if (itrace_synth_opts.callchain &&
2109 itrace_synth_opts.callchain_sz > scripting_max_stack)
2110 scripting_max_stack = itrace_synth_opts.callchain_sz;
2111
Ben Hutchings44e668c2010-10-10 16:10:03 +01002112 /* make sure PERF_EXEC_PATH is set for scripts */
Josh Poimboeuf46113a52015-12-15 09:39:37 -06002113 set_argv_exec_path(get_argv_exec_path());
Ben Hutchings44e668c2010-10-10 16:10:03 +01002114
Tom Zanussib5b87312010-11-10 08:16:51 -06002115 if (argc && !script_name && !rec_script_path && !rep_script_path) {
Tom Zanussia0cccc22010-04-01 23:59:25 -05002116 int live_pipe[2];
Tom Zanussib5b87312010-11-10 08:16:51 -06002117 int rep_args;
Tom Zanussia0cccc22010-04-01 23:59:25 -05002118 pid_t pid;
2119
Tom Zanussib5b87312010-11-10 08:16:51 -06002120 rec_script_path = get_script_path(argv[0], RECORD_SUFFIX);
2121 rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);
2122
2123 if (!rec_script_path && !rep_script_path) {
Namhyung Kimc7118362015-10-25 00:49:27 +09002124 usage_with_options_msg(script_usage, options,
2125 "Couldn't find script `%s'\n\n See perf"
Ingo Molnar133dc4c2010-11-16 18:45:39 +01002126 " script -l for available scripts.\n", argv[0]);
Tom Zanussia0cccc22010-04-01 23:59:25 -05002127 }
2128
Tom Zanussib5b87312010-11-10 08:16:51 -06002129 if (is_top_script(argv[0])) {
2130 rep_args = argc - 1;
2131 } else {
2132 int rec_args;
2133
2134 rep_args = has_required_arg(rep_script_path);
2135 rec_args = (argc - 1) - rep_args;
2136 if (rec_args < 0) {
Namhyung Kimc7118362015-10-25 00:49:27 +09002137 usage_with_options_msg(script_usage, options,
2138 "`%s' script requires options."
Ingo Molnar133dc4c2010-11-16 18:45:39 +01002139 "\n\n See perf script -l for available "
Tom Zanussib5b87312010-11-10 08:16:51 -06002140 "scripts and options.\n", argv[0]);
Tom Zanussib5b87312010-11-10 08:16:51 -06002141 }
Tom Zanussia0cccc22010-04-01 23:59:25 -05002142 }
2143
2144 if (pipe(live_pipe) < 0) {
2145 perror("failed to create pipe");
David Ahernd54b1a92012-08-26 12:24:46 -06002146 return -1;
Tom Zanussia0cccc22010-04-01 23:59:25 -05002147 }
2148
2149 pid = fork();
2150 if (pid < 0) {
2151 perror("failed to fork");
David Ahernd54b1a92012-08-26 12:24:46 -06002152 return -1;
Tom Zanussia0cccc22010-04-01 23:59:25 -05002153 }
2154
2155 if (!pid) {
Tom Zanussib5b87312010-11-10 08:16:51 -06002156 j = 0;
2157
Tom Zanussia0cccc22010-04-01 23:59:25 -05002158 dup2(live_pipe[1], 1);
2159 close(live_pipe[0]);
2160
Robert Richter317df652011-11-25 15:05:25 +01002161 if (is_top_script(argv[0])) {
2162 system_wide = true;
2163 } else if (!system_wide) {
David Ahernd54b1a92012-08-26 12:24:46 -06002164 if (have_cmd(argc - rep_args, &argv[rep_args]) != 0) {
2165 err = -1;
2166 goto out;
2167 }
Robert Richter317df652011-11-25 15:05:25 +01002168 }
Tom Zanussib5b87312010-11-10 08:16:51 -06002169
2170 __argv = malloc((argc + 6) * sizeof(const char *));
David Ahernd54b1a92012-08-26 12:24:46 -06002171 if (!__argv) {
2172 pr_err("malloc failed\n");
2173 err = -ENOMEM;
2174 goto out;
2175 }
Tom Zanussie8719ad2010-11-10 07:52:32 -06002176
Tom Zanussib5b87312010-11-10 08:16:51 -06002177 __argv[j++] = "/bin/sh";
2178 __argv[j++] = rec_script_path;
2179 if (system_wide)
2180 __argv[j++] = "-a";
2181 __argv[j++] = "-q";
2182 __argv[j++] = "-o";
2183 __argv[j++] = "-";
2184 for (i = rep_args + 1; i < argc; i++)
2185 __argv[j++] = argv[i];
2186 __argv[j++] = NULL;
Tom Zanussia0cccc22010-04-01 23:59:25 -05002187
2188 execvp("/bin/sh", (char **)__argv);
Tom Zanussie8719ad2010-11-10 07:52:32 -06002189 free(__argv);
Tom Zanussia0cccc22010-04-01 23:59:25 -05002190 exit(-1);
2191 }
2192
2193 dup2(live_pipe[0], 0);
2194 close(live_pipe[1]);
2195
Tom Zanussib5b87312010-11-10 08:16:51 -06002196 __argv = malloc((argc + 4) * sizeof(const char *));
David Ahernd54b1a92012-08-26 12:24:46 -06002197 if (!__argv) {
2198 pr_err("malloc failed\n");
2199 err = -ENOMEM;
2200 goto out;
2201 }
2202
Tom Zanussib5b87312010-11-10 08:16:51 -06002203 j = 0;
Tom Zanussi34c86ea2010-11-10 08:15:43 -06002204 __argv[j++] = "/bin/sh";
Tom Zanussib5b87312010-11-10 08:16:51 -06002205 __argv[j++] = rep_script_path;
2206 for (i = 1; i < rep_args + 1; i++)
Tom Zanussi34c86ea2010-11-10 08:15:43 -06002207 __argv[j++] = argv[i];
Tom Zanussib5b87312010-11-10 08:16:51 -06002208 __argv[j++] = "-i";
2209 __argv[j++] = "-";
Tom Zanussi34c86ea2010-11-10 08:15:43 -06002210 __argv[j++] = NULL;
Tom Zanussi38752942009-12-15 02:53:39 -06002211
2212 execvp("/bin/sh", (char **)__argv);
Tom Zanussie8719ad2010-11-10 07:52:32 -06002213 free(__argv);
Tom Zanussi38752942009-12-15 02:53:39 -06002214 exit(-1);
2215 }
Tom Zanussi956ffd02009-11-25 01:15:46 -06002216
Tom Zanussib5b87312010-11-10 08:16:51 -06002217 if (rec_script_path)
2218 script_path = rec_script_path;
2219 if (rep_script_path)
2220 script_path = rep_script_path;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002221
Tom Zanussib5b87312010-11-10 08:16:51 -06002222 if (script_path) {
Tom Zanussib5b87312010-11-10 08:16:51 -06002223 j = 0;
2224
Robert Richter317df652011-11-25 15:05:25 +01002225 if (!rec_script_path)
2226 system_wide = false;
David Ahernd54b1a92012-08-26 12:24:46 -06002227 else if (!system_wide) {
2228 if (have_cmd(argc - 1, &argv[1]) != 0) {
2229 err = -1;
2230 goto out;
2231 }
2232 }
Tom Zanussib5b87312010-11-10 08:16:51 -06002233
2234 __argv = malloc((argc + 2) * sizeof(const char *));
David Ahernd54b1a92012-08-26 12:24:46 -06002235 if (!__argv) {
2236 pr_err("malloc failed\n");
2237 err = -ENOMEM;
2238 goto out;
2239 }
2240
Tom Zanussib5b87312010-11-10 08:16:51 -06002241 __argv[j++] = "/bin/sh";
2242 __argv[j++] = script_path;
2243 if (system_wide)
2244 __argv[j++] = "-a";
2245 for (i = 2; i < argc; i++)
2246 __argv[j++] = argv[i];
2247 __argv[j++] = NULL;
2248
2249 execvp("/bin/sh", (char **)__argv);
2250 free(__argv);
2251 exit(-1);
2252 }
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02002253
Tom Zanussicf4fee52010-03-03 01:04:33 -06002254 if (!script_name)
2255 setup_pager();
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02002256
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03002257 session = perf_session__new(&file, false, &script.tool);
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -02002258 if (session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +09002259 return -1;
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -02002260
Jiri Olsae90debd2013-12-09 11:02:50 +01002261 if (header || header_only) {
2262 perf_session__fprintf_info(session, stdout, show_full_info);
2263 if (header_only)
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002264 goto out_delete;
Jiri Olsae90debd2013-12-09 11:02:50 +01002265 }
2266
Namhyung Kim0a7e6d12014-08-12 15:40:45 +09002267 if (symbol__init(&session->header.env) < 0)
Namhyung Kim38520dc2014-08-12 15:40:42 +09002268 goto out_delete;
2269
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03002270 script.session = session;
Jiri Olsa7322d6c2015-08-13 09:17:24 +02002271 script__setup_sample_type(&script);
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03002272
Adrian Hunter7a680eb2015-04-09 18:53:56 +03002273 session->itrace_synth_opts = &itrace_synth_opts;
2274
Anton Blanchard5d67be92011-07-04 21:57:50 +10002275 if (cpu_list) {
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002276 err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
2277 if (err < 0)
2278 goto out_delete;
Anton Blanchard5d67be92011-07-04 21:57:50 +10002279 }
2280
David Ahern1424dc92011-03-09 22:23:28 -07002281 if (!no_callchain)
David Ahernc0230b22011-03-09 22:23:27 -07002282 symbol_conf.use_callchain = true;
2283 else
2284 symbol_conf.use_callchain = false;
2285
Arnaldo Carvalho de Melo9ee67422015-08-03 16:27:40 -03002286 if (session->tevent.pevent &&
2287 pevent_set_function_resolver(session->tevent.pevent,
Arnaldo Carvalho de Meloccb3a822015-07-22 16:43:37 -03002288 machine__resolve_kernel_addr,
2289 &session->machines.host) < 0) {
2290 pr_err("%s: failed to set libtraceevent function resolver\n", __func__);
2291 return -1;
2292 }
2293
Tom Zanussi956ffd02009-11-25 01:15:46 -06002294 if (generate_script_lang) {
2295 struct stat perf_stat;
David Ahern745f43e2011-03-09 22:23:26 -07002296 int input;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002297
David Ahern2c9e45f72011-03-17 10:03:21 -06002298 if (output_set_by_user()) {
David Ahern745f43e2011-03-09 22:23:26 -07002299 fprintf(stderr,
2300 "custom fields not supported for generated scripts");
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002301 err = -EINVAL;
2302 goto out_delete;
David Ahern745f43e2011-03-09 22:23:26 -07002303 }
2304
Jiri Olsacc9784bd2013-10-15 16:27:34 +02002305 input = open(file.path, O_RDONLY); /* input_name */
Tom Zanussi956ffd02009-11-25 01:15:46 -06002306 if (input < 0) {
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002307 err = -errno;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002308 perror("failed to open file");
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002309 goto out_delete;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002310 }
2311
2312 err = fstat(input, &perf_stat);
2313 if (err < 0) {
2314 perror("failed to stat file");
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002315 goto out_delete;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002316 }
2317
2318 if (!perf_stat.st_size) {
2319 fprintf(stderr, "zero-sized file, nothing to do!\n");
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002320 goto out_delete;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002321 }
2322
2323 scripting_ops = script_spec__lookup(generate_script_lang);
2324 if (!scripting_ops) {
2325 fprintf(stderr, "invalid language specifier");
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002326 err = -ENOENT;
2327 goto out_delete;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002328 }
2329
Jiri Olsa29f5ffd2013-12-03 14:09:23 +01002330 err = scripting_ops->generate_script(session->tevent.pevent,
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -03002331 "perf-script");
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002332 goto out_delete;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002333 }
2334
2335 if (script_name) {
Tom Zanussi586bc5c2009-12-15 02:53:35 -06002336 err = scripting_ops->start_script(script_name, argc, argv);
Tom Zanussi956ffd02009-11-25 01:15:46 -06002337 if (err)
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002338 goto out_delete;
Ingo Molnar133dc4c2010-11-16 18:45:39 +01002339 pr_debug("perf script started with script %s\n\n", script_name);
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002340 script_started = true;
Tom Zanussi956ffd02009-11-25 01:15:46 -06002341 }
2342
David Ahern9cbdb702011-04-06 21:54:20 -06002343
2344 err = perf_session__check_output_opt(session);
2345 if (err < 0)
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002346 goto out_delete;
David Ahern9cbdb702011-04-06 21:54:20 -06002347
Adrian Hunter6f3e5ed2013-10-22 10:34:07 +03002348 err = __cmd_script(&script);
Tom Zanussi956ffd02009-11-25 01:15:46 -06002349
Adrian Hunterd445dd22014-08-15 22:08:37 +03002350 flush_scripting();
2351
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002352out_delete:
Jiri Olsacfc88742016-01-05 22:09:06 +01002353 perf_evlist__free_stats(session->evlist);
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -02002354 perf_session__delete(session);
Namhyung Kim6cc870f2014-08-12 15:40:33 +09002355
2356 if (script_started)
2357 cleanup_scripting();
Tom Zanussi956ffd02009-11-25 01:15:46 -06002358out:
2359 return err;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02002360}