blob: 9f5fc54921413af3b783ffef688f6c1177afa941 [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"
6#include "util/exec_cmd.h"
7#include "util/header.h"
8#include "util/parse-options.h"
9#include "util/session.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020010#include "util/symbol.h"
11#include "util/thread.h"
Ingo Molnarcf723442009-11-28 10:11:00 +010012#include "util/trace-event.h"
Tom Zanussi34c86ea2010-11-10 08:15:43 -060013#include "util/parse-options.h"
Andrea Gelminib7eead82010-08-05 15:51:38 +020014#include "util/util.h"
David Ahern1424dc92011-03-09 22:23:28 -070015#include "util/evlist.h"
16#include "util/evsel.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020017
Tom Zanussi956ffd02009-11-25 01:15:46 -060018static char const *script_name;
19static char const *generate_script_lang;
Frederic Weisbeckerffabd992010-05-27 16:27:47 +020020static bool debug_mode;
Frederic Weisbeckere1889d72010-04-24 01:55:09 +020021static u64 last_timestamp;
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +020022static u64 nr_unordered;
Tom Zanussi34c86ea2010-11-10 08:15:43 -060023extern const struct option record_options[];
David Ahernc0230b22011-03-09 22:23:27 -070024static bool no_callchain;
Tom Zanussi956ffd02009-11-25 01:15:46 -060025
David Ahern745f43e2011-03-09 22:23:26 -070026enum perf_output_field {
27 PERF_OUTPUT_COMM = 1U << 0,
28 PERF_OUTPUT_TID = 1U << 1,
29 PERF_OUTPUT_PID = 1U << 2,
30 PERF_OUTPUT_TIME = 1U << 3,
31 PERF_OUTPUT_CPU = 1U << 4,
32 PERF_OUTPUT_EVNAME = 1U << 5,
33 PERF_OUTPUT_TRACE = 1U << 6,
David Ahernc0230b22011-03-09 22:23:27 -070034 PERF_OUTPUT_SYM = 1U << 7,
David Ahern745f43e2011-03-09 22:23:26 -070035};
36
37struct output_option {
38 const char *str;
39 enum perf_output_field field;
40} all_output_options[] = {
41 {.str = "comm", .field = PERF_OUTPUT_COMM},
42 {.str = "tid", .field = PERF_OUTPUT_TID},
43 {.str = "pid", .field = PERF_OUTPUT_PID},
44 {.str = "time", .field = PERF_OUTPUT_TIME},
45 {.str = "cpu", .field = PERF_OUTPUT_CPU},
46 {.str = "event", .field = PERF_OUTPUT_EVNAME},
47 {.str = "trace", .field = PERF_OUTPUT_TRACE},
David Ahernc0230b22011-03-09 22:23:27 -070048 {.str = "sym", .field = PERF_OUTPUT_SYM},
David Ahern745f43e2011-03-09 22:23:26 -070049};
50
51/* default set to maintain compatibility with current format */
David Ahern1424dc92011-03-09 22:23:28 -070052static u64 output_fields[PERF_TYPE_MAX] = {
53 [PERF_TYPE_HARDWARE] = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | \
54 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | \
55 PERF_OUTPUT_EVNAME | PERF_OUTPUT_SYM,
56
57 [PERF_TYPE_SOFTWARE] = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | \
58 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | \
59 PERF_OUTPUT_EVNAME | PERF_OUTPUT_SYM,
60
61 [PERF_TYPE_TRACEPOINT] = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | \
62 PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | \
63 PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE,
64};
David Ahern745f43e2011-03-09 22:23:26 -070065
66static bool output_set_by_user;
67
David Ahern1424dc92011-03-09 22:23:28 -070068#define PRINT_FIELD(x) (output_fields[attr->type] & PERF_OUTPUT_##x)
69
70static int perf_session__check_attr(struct perf_session *session,
71 struct perf_event_attr *attr)
72{
73 if (PRINT_FIELD(TRACE) &&
74 !perf_session__has_traces(session, "record -R"))
75 return -EINVAL;
76
77 if (PRINT_FIELD(SYM)) {
78 if (!(session->sample_type & PERF_SAMPLE_IP)) {
79 pr_err("Samples do not contain IP data.\n");
80 return -EINVAL;
81 }
82 if (!no_callchain &&
83 !(session->sample_type & PERF_SAMPLE_CALLCHAIN))
84 symbol_conf.use_callchain = false;
85 }
86
87 if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) &&
88 !(session->sample_type & PERF_SAMPLE_TID)) {
89 pr_err("Samples do not contain TID/PID data.\n");
90 return -EINVAL;
91 }
92
93 if (PRINT_FIELD(TIME) &&
94 !(session->sample_type & PERF_SAMPLE_TIME)) {
95 pr_err("Samples do not contain timestamps.\n");
96 return -EINVAL;
97 }
98
99 if (PRINT_FIELD(CPU) &&
100 !(session->sample_type & PERF_SAMPLE_CPU)) {
101 pr_err("Samples do not contain cpu.\n");
102 return -EINVAL;
103 }
104
105 return 0;
106}
David Ahern745f43e2011-03-09 22:23:26 -0700107
David Ahernc70c94b2011-03-09 22:23:25 -0700108static void print_sample_start(struct perf_sample *sample,
David Ahern1424dc92011-03-09 22:23:28 -0700109 struct thread *thread,
110 struct perf_event_attr *attr)
David Ahernc70c94b2011-03-09 22:23:25 -0700111{
112 int type;
113 struct event *event;
114 const char *evname = NULL;
115 unsigned long secs;
116 unsigned long usecs;
David Ahern745f43e2011-03-09 22:23:26 -0700117 unsigned long long nsecs;
David Ahernc70c94b2011-03-09 22:23:25 -0700118
David Ahern745f43e2011-03-09 22:23:26 -0700119 if (PRINT_FIELD(COMM)) {
120 if (latency_format)
121 printf("%8.8s ", thread->comm);
David Ahernc0230b22011-03-09 22:23:27 -0700122 else if (PRINT_FIELD(SYM) && symbol_conf.use_callchain)
123 printf("%s ", thread->comm);
David Ahern745f43e2011-03-09 22:23:26 -0700124 else
125 printf("%16s ", thread->comm);
126 }
David Ahernc70c94b2011-03-09 22:23:25 -0700127
David Ahern745f43e2011-03-09 22:23:26 -0700128 if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
129 printf("%5d/%-5d ", sample->pid, sample->tid);
130 else if (PRINT_FIELD(PID))
131 printf("%5d ", sample->pid);
132 else if (PRINT_FIELD(TID))
133 printf("%5d ", sample->tid);
David Ahernc70c94b2011-03-09 22:23:25 -0700134
David Ahern745f43e2011-03-09 22:23:26 -0700135 if (PRINT_FIELD(CPU)) {
136 if (latency_format)
137 printf("%3d ", sample->cpu);
138 else
139 printf("[%03d] ", sample->cpu);
140 }
David Ahernc70c94b2011-03-09 22:23:25 -0700141
David Ahern745f43e2011-03-09 22:23:26 -0700142 if (PRINT_FIELD(TIME)) {
143 nsecs = sample->time;
144 secs = nsecs / NSECS_PER_SEC;
145 nsecs -= secs * NSECS_PER_SEC;
146 usecs = nsecs / NSECS_PER_USEC;
147 printf("%5lu.%06lu: ", secs, usecs);
148 }
149
150 if (PRINT_FIELD(EVNAME)) {
David Ahern1424dc92011-03-09 22:23:28 -0700151 if (attr->type == PERF_TYPE_TRACEPOINT) {
152 type = trace_parse_common_type(sample->raw_data);
153 event = trace_find_event(type);
154 if (event)
155 evname = event->name;
156 } else
157 evname = __event_name(attr->type, attr->config);
David Ahern745f43e2011-03-09 22:23:26 -0700158
159 printf("%s: ", evname ? evname : "(unknown)");
160 }
David Ahernc70c94b2011-03-09 22:23:25 -0700161}
162
David Ahernbe6d8422011-03-09 22:23:23 -0700163static void process_event(union perf_event *event __unused,
164 struct perf_sample *sample,
David Ahern1424dc92011-03-09 22:23:28 -0700165 struct perf_session *session,
David Ahernbe6d8422011-03-09 22:23:23 -0700166 struct thread *thread)
167{
David Ahern1424dc92011-03-09 22:23:28 -0700168 struct perf_event_attr *attr;
169 struct perf_evsel *evsel;
170
171 evsel = perf_evlist__id2evsel(session->evlist, sample->id);
172 if (evsel == NULL) {
173 pr_err("Invalid data. Contains samples with id not in "
174 "its header!\n");
175 return;
176 }
177 attr = &evsel->attr;
178
179 if (output_fields[attr->type] == 0)
180 return;
181
182 if (perf_session__check_attr(session, attr) < 0)
183 return;
184
185 print_sample_start(sample, thread, attr);
David Ahern745f43e2011-03-09 22:23:26 -0700186
187 if (PRINT_FIELD(TRACE))
188 print_trace_event(sample->cpu, sample->raw_data,
189 sample->raw_size);
190
David Ahernc0230b22011-03-09 22:23:27 -0700191 if (PRINT_FIELD(SYM)) {
192 if (!symbol_conf.use_callchain)
193 printf(" ");
194 else
195 printf("\n");
196 perf_session__print_symbols(event, sample, session);
197 }
198
David Ahernc70c94b2011-03-09 22:23:25 -0700199 printf("\n");
David Ahernbe6d8422011-03-09 22:23:23 -0700200}
201
Tom Zanussi586bc5c2009-12-15 02:53:35 -0600202static int default_start_script(const char *script __unused,
203 int argc __unused,
204 const char **argv __unused)
Tom Zanussi956ffd02009-11-25 01:15:46 -0600205{
206 return 0;
207}
208
209static int default_stop_script(void)
210{
211 return 0;
212}
213
Tom Zanussi586bc5c2009-12-15 02:53:35 -0600214static int default_generate_script(const char *outfile __unused)
Tom Zanussi956ffd02009-11-25 01:15:46 -0600215{
216 return 0;
217}
218
219static struct scripting_ops default_scripting_ops = {
220 .start_script = default_start_script,
221 .stop_script = default_stop_script,
David Ahernbe6d8422011-03-09 22:23:23 -0700222 .process_event = process_event,
Tom Zanussi956ffd02009-11-25 01:15:46 -0600223 .generate_script = default_generate_script,
224};
225
226static struct scripting_ops *scripting_ops;
227
228static void setup_scripting(void)
229{
Tom Zanussi16c632d2009-11-25 01:15:48 -0600230 setup_perl_scripting();
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600231 setup_python_scripting();
Tom Zanussi16c632d2009-11-25 01:15:48 -0600232
Tom Zanussi956ffd02009-11-25 01:15:46 -0600233 scripting_ops = &default_scripting_ops;
234}
235
236static int cleanup_scripting(void)
237{
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100238 pr_debug("\nperf script stopped\n");
Tom Zanussi3824a4e2010-05-09 23:46:57 -0500239
Tom Zanussi956ffd02009-11-25 01:15:46 -0600240 return scripting_ops->stop_script();
241}
242
Tom Zanussi956ffd02009-11-25 01:15:46 -0600243static char const *input_name = "perf.data";
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200244
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200245static int process_sample_event(union perf_event *event,
246 struct perf_sample *sample,
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200247 struct perf_session *session)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200248{
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200249 struct thread *thread = perf_session__findnew(session, event->ip.pid);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200250
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200251 if (thread == NULL) {
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -0200252 pr_debug("problem processing %d event, skipping it.\n",
253 event->header.type);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200254 return -1;
255 }
256
David Ahern1424dc92011-03-09 22:23:28 -0700257 if (debug_mode) {
258 if (sample->time < last_timestamp) {
259 pr_err("Samples misordered, previous: %" PRIu64
260 " this: %" PRIu64 "\n", last_timestamp,
261 sample->time);
262 nr_unordered++;
Frederic Weisbeckere1889d72010-04-24 01:55:09 +0200263 }
David Ahern1424dc92011-03-09 22:23:28 -0700264 last_timestamp = sample->time;
265 return 0;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200266 }
David Ahern1424dc92011-03-09 22:23:28 -0700267 scripting_ops->process_event(event, sample, session, thread);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200268
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200269 session->hists.stats.total_period += sample->period;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200270 return 0;
271}
272
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -0200273static struct perf_event_ops event_ops = {
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200274 .sample = process_sample_event,
David Ahernc0230b22011-03-09 22:23:27 -0700275 .mmap = perf_event__process_mmap,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200276 .comm = perf_event__process_comm,
David Ahernc0230b22011-03-09 22:23:27 -0700277 .exit = perf_event__process_task,
278 .fork = perf_event__process_task,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200279 .attr = perf_event__process_attr,
280 .event_type = perf_event__process_event_type,
281 .tracing_data = perf_event__process_tracing_data,
282 .build_id = perf_event__process_build_id,
Frederic Weisbeckere0a808c2010-04-24 00:38:33 +0200283 .ordered_samples = true,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200284 .ordering_requires_timestamps = true,
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200285};
286
Tom Zanussic239da32010-04-01 23:59:18 -0500287extern volatile int session_done;
288
289static void sig_handler(int sig __unused)
290{
291 session_done = 1;
292}
293
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100294static int __cmd_script(struct perf_session *session)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200295{
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +0200296 int ret;
297
Tom Zanussic239da32010-04-01 23:59:18 -0500298 signal(SIGINT, sig_handler);
299
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +0200300 ret = perf_session__process_events(session, &event_ops);
301
Arnaldo Carvalho de Melo6d8afb52011-01-04 16:27:30 -0200302 if (debug_mode)
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200303 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
Frederic Weisbecker6fcf7dd2010-05-27 15:46:25 +0200304
305 return ret;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200306}
307
Tom Zanussi956ffd02009-11-25 01:15:46 -0600308struct script_spec {
309 struct list_head node;
310 struct scripting_ops *ops;
311 char spec[0];
312};
313
Arnaldo Carvalho de Meloeccdfe22011-01-04 16:32:52 -0200314static LIST_HEAD(script_specs);
Tom Zanussi956ffd02009-11-25 01:15:46 -0600315
316static struct script_spec *script_spec__new(const char *spec,
317 struct scripting_ops *ops)
318{
319 struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
320
321 if (s != NULL) {
322 strcpy(s->spec, spec);
323 s->ops = ops;
324 }
325
326 return s;
327}
328
329static void script_spec__delete(struct script_spec *s)
330{
331 free(s->spec);
332 free(s);
333}
334
335static void script_spec__add(struct script_spec *s)
336{
337 list_add_tail(&s->node, &script_specs);
338}
339
340static struct script_spec *script_spec__find(const char *spec)
341{
342 struct script_spec *s;
343
344 list_for_each_entry(s, &script_specs, node)
345 if (strcasecmp(s->spec, spec) == 0)
346 return s;
347 return NULL;
348}
349
350static struct script_spec *script_spec__findnew(const char *spec,
351 struct scripting_ops *ops)
352{
353 struct script_spec *s = script_spec__find(spec);
354
355 if (s)
356 return s;
357
358 s = script_spec__new(spec, ops);
359 if (!s)
360 goto out_delete_spec;
361
362 script_spec__add(s);
363
364 return s;
365
366out_delete_spec:
367 script_spec__delete(s);
368
369 return NULL;
370}
371
372int script_spec_register(const char *spec, struct scripting_ops *ops)
373{
374 struct script_spec *s;
375
376 s = script_spec__find(spec);
377 if (s)
378 return -1;
379
380 s = script_spec__findnew(spec, ops);
381 if (!s)
382 return -1;
383
384 return 0;
385}
386
387static struct scripting_ops *script_spec__lookup(const char *spec)
388{
389 struct script_spec *s = script_spec__find(spec);
390 if (!s)
391 return NULL;
392
393 return s->ops;
394}
395
396static void list_available_languages(void)
397{
398 struct script_spec *s;
399
400 fprintf(stderr, "\n");
401 fprintf(stderr, "Scripting language extensions (used in "
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100402 "perf script -s [spec:]script.[spec]):\n\n");
Tom Zanussi956ffd02009-11-25 01:15:46 -0600403
404 list_for_each_entry(s, &script_specs, node)
405 fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name);
406
407 fprintf(stderr, "\n");
408}
409
410static int parse_scriptname(const struct option *opt __used,
411 const char *str, int unset __used)
412{
413 char spec[PATH_MAX];
414 const char *script, *ext;
415 int len;
416
Tom Zanussif526d682010-01-27 02:27:52 -0600417 if (strcmp(str, "lang") == 0) {
Tom Zanussi956ffd02009-11-25 01:15:46 -0600418 list_available_languages();
Tom Zanussif526d682010-01-27 02:27:52 -0600419 exit(0);
Tom Zanussi956ffd02009-11-25 01:15:46 -0600420 }
421
422 script = strchr(str, ':');
423 if (script) {
424 len = script - str;
425 if (len >= PATH_MAX) {
426 fprintf(stderr, "invalid language specifier");
427 return -1;
428 }
429 strncpy(spec, str, len);
430 spec[len] = '\0';
431 scripting_ops = script_spec__lookup(spec);
432 if (!scripting_ops) {
433 fprintf(stderr, "invalid language specifier");
434 return -1;
435 }
436 script++;
437 } else {
438 script = str;
Ben Hutchingsd1e95bb2010-10-10 16:11:02 +0100439 ext = strrchr(script, '.');
Tom Zanussi956ffd02009-11-25 01:15:46 -0600440 if (!ext) {
441 fprintf(stderr, "invalid script extension");
442 return -1;
443 }
444 scripting_ops = script_spec__lookup(++ext);
445 if (!scripting_ops) {
446 fprintf(stderr, "invalid script extension");
447 return -1;
448 }
449 }
450
451 script_name = strdup(script);
452
453 return 0;
454}
455
David Ahern745f43e2011-03-09 22:23:26 -0700456static int parse_output_fields(const struct option *opt __used,
457 const char *arg, int unset __used)
458{
459 char *tok;
460 int i, imax = sizeof(all_output_options) / sizeof(struct output_option);
461 int rc = 0;
462 char *str = strdup(arg);
David Ahern1424dc92011-03-09 22:23:28 -0700463 int type = -1;
David Ahern745f43e2011-03-09 22:23:26 -0700464
465 if (!str)
466 return -ENOMEM;
467
David Ahern1424dc92011-03-09 22:23:28 -0700468 tok = strtok(str, ":");
David Ahern745f43e2011-03-09 22:23:26 -0700469 if (!tok) {
David Ahern1424dc92011-03-09 22:23:28 -0700470 fprintf(stderr,
471 "Invalid field string - not prepended with type.");
David Ahern745f43e2011-03-09 22:23:26 -0700472 return -EINVAL;
473 }
474
David Ahern1424dc92011-03-09 22:23:28 -0700475 /* first word should state which event type user
476 * is specifying the fields
477 */
478 if (!strcmp(tok, "hw"))
479 type = PERF_TYPE_HARDWARE;
480 else if (!strcmp(tok, "sw"))
481 type = PERF_TYPE_SOFTWARE;
482 else if (!strcmp(tok, "trace"))
483 type = PERF_TYPE_TRACEPOINT;
484 else {
485 fprintf(stderr, "Invalid event type in field string.");
486 return -EINVAL;
487 }
488
489 output_fields[type] = 0;
David Ahern745f43e2011-03-09 22:23:26 -0700490 while (1) {
David Ahern1424dc92011-03-09 22:23:28 -0700491 tok = strtok(NULL, ",");
492 if (!tok)
493 break;
David Ahern745f43e2011-03-09 22:23:26 -0700494 for (i = 0; i < imax; ++i) {
495 if (strcmp(tok, all_output_options[i].str) == 0) {
David Ahern1424dc92011-03-09 22:23:28 -0700496 output_fields[type] |= all_output_options[i].field;
David Ahern745f43e2011-03-09 22:23:26 -0700497 break;
498 }
499 }
500 if (i == imax) {
501 fprintf(stderr, "Invalid field requested.");
502 rc = -EINVAL;
503 break;
504 }
David Ahern1424dc92011-03-09 22:23:28 -0700505 }
David Ahern745f43e2011-03-09 22:23:26 -0700506
David Ahern1424dc92011-03-09 22:23:28 -0700507 if (output_fields[type] == 0) {
508 pr_debug("No fields requested for %s type. "
509 "Events will not be displayed\n", event_type(type));
David Ahern745f43e2011-03-09 22:23:26 -0700510 }
511
512 output_set_by_user = true;
513
514 free(str);
515 return rc;
516}
517
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600518/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
519static int is_directory(const char *base_path, const struct dirent *dent)
520{
521 char path[PATH_MAX];
522 struct stat st;
523
524 sprintf(path, "%s/%s", base_path, dent->d_name);
525 if (stat(path, &st))
526 return 0;
527
528 return S_ISDIR(st.st_mode);
529}
530
531#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600532 while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
533 lang_next) \
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600534 if ((lang_dirent.d_type == DT_DIR || \
535 (lang_dirent.d_type == DT_UNKNOWN && \
536 is_directory(scripts_path, &lang_dirent))) && \
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600537 (strcmp(lang_dirent.d_name, ".")) && \
538 (strcmp(lang_dirent.d_name, "..")))
539
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600540#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600541 while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
542 script_next) \
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600543 if (script_dirent.d_type != DT_DIR && \
544 (script_dirent.d_type != DT_UNKNOWN || \
545 !is_directory(lang_path, &script_dirent)))
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600546
547
548#define RECORD_SUFFIX "-record"
549#define REPORT_SUFFIX "-report"
550
551struct script_desc {
552 struct list_head node;
553 char *name;
554 char *half_liner;
555 char *args;
556};
557
Arnaldo Carvalho de Meloeccdfe22011-01-04 16:32:52 -0200558static LIST_HEAD(script_descs);
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600559
560static struct script_desc *script_desc__new(const char *name)
561{
562 struct script_desc *s = zalloc(sizeof(*s));
563
Tom Zanussib5b87312010-11-10 08:16:51 -0600564 if (s != NULL && name)
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600565 s->name = strdup(name);
566
567 return s;
568}
569
570static void script_desc__delete(struct script_desc *s)
571{
572 free(s->name);
Tom Zanussie8719ad2010-11-10 07:52:32 -0600573 free(s->half_liner);
574 free(s->args);
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600575 free(s);
576}
577
578static void script_desc__add(struct script_desc *s)
579{
580 list_add_tail(&s->node, &script_descs);
581}
582
583static struct script_desc *script_desc__find(const char *name)
584{
585 struct script_desc *s;
586
587 list_for_each_entry(s, &script_descs, node)
588 if (strcasecmp(s->name, name) == 0)
589 return s;
590 return NULL;
591}
592
593static struct script_desc *script_desc__findnew(const char *name)
594{
595 struct script_desc *s = script_desc__find(name);
596
597 if (s)
598 return s;
599
600 s = script_desc__new(name);
601 if (!s)
602 goto out_delete_desc;
603
604 script_desc__add(s);
605
606 return s;
607
608out_delete_desc:
609 script_desc__delete(s);
610
611 return NULL;
612}
613
Stephane Eranian965bb6b2010-12-03 17:52:01 +0200614static const char *ends_with(const char *str, const char *suffix)
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600615{
616 size_t suffix_len = strlen(suffix);
Stephane Eranian965bb6b2010-12-03 17:52:01 +0200617 const char *p = str;
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600618
619 if (strlen(str) > suffix_len) {
620 p = str + strlen(str) - suffix_len;
621 if (!strncmp(p, suffix, suffix_len))
622 return p;
623 }
624
625 return NULL;
626}
627
628static char *ltrim(char *str)
629{
630 int len = strlen(str);
631
632 while (len && isspace(*str)) {
633 len--;
634 str++;
635 }
636
637 return str;
638}
639
640static int read_script_info(struct script_desc *desc, const char *filename)
641{
642 char line[BUFSIZ], *p;
643 FILE *fp;
644
645 fp = fopen(filename, "r");
646 if (!fp)
647 return -1;
648
649 while (fgets(line, sizeof(line), fp)) {
650 p = ltrim(line);
651 if (strlen(p) == 0)
652 continue;
653 if (*p != '#')
654 continue;
655 p++;
656 if (strlen(p) && *p == '!')
657 continue;
658
659 p = ltrim(p);
660 if (strlen(p) && p[strlen(p) - 1] == '\n')
661 p[strlen(p) - 1] = '\0';
662
663 if (!strncmp(p, "description:", strlen("description:"))) {
664 p += strlen("description:");
665 desc->half_liner = strdup(ltrim(p));
666 continue;
667 }
668
669 if (!strncmp(p, "args:", strlen("args:"))) {
670 p += strlen("args:");
671 desc->args = strdup(ltrim(p));
672 continue;
673 }
674 }
675
676 fclose(fp);
677
678 return 0;
679}
680
681static int list_available_scripts(const struct option *opt __used,
682 const char *s __used, int unset __used)
683{
684 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
685 char scripts_path[MAXPATHLEN];
686 DIR *scripts_dir, *lang_dir;
687 char script_path[MAXPATHLEN];
688 char lang_path[MAXPATHLEN];
689 struct script_desc *desc;
690 char first_half[BUFSIZ];
691 char *script_root;
692 char *str;
693
694 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
695
696 scripts_dir = opendir(scripts_path);
697 if (!scripts_dir)
698 return -1;
699
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600700 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600701 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
702 lang_dirent.d_name);
703 lang_dir = opendir(lang_path);
704 if (!lang_dir)
705 continue;
706
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600707 for_each_script(lang_path, lang_dir, script_dirent, script_next) {
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600708 script_root = strdup(script_dirent.d_name);
Stephane Eranian965bb6b2010-12-03 17:52:01 +0200709 str = (char *)ends_with(script_root, REPORT_SUFFIX);
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600710 if (str) {
711 *str = '\0';
712 desc = script_desc__findnew(script_root);
713 snprintf(script_path, MAXPATHLEN, "%s/%s",
714 lang_path, script_dirent.d_name);
715 read_script_info(desc, script_path);
716 }
717 free(script_root);
718 }
719 }
720
721 fprintf(stdout, "List of available trace scripts:\n");
722 list_for_each_entry(desc, &script_descs, node) {
723 sprintf(first_half, "%s %s", desc->name,
724 desc->args ? desc->args : "");
725 fprintf(stdout, " %-36s %s\n", first_half,
726 desc->half_liner ? desc->half_liner : "");
727 }
728
729 exit(0);
730}
731
Tom Zanussi38752942009-12-15 02:53:39 -0600732static char *get_script_path(const char *script_root, const char *suffix)
733{
734 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
735 char scripts_path[MAXPATHLEN];
736 char script_path[MAXPATHLEN];
737 DIR *scripts_dir, *lang_dir;
738 char lang_path[MAXPATHLEN];
739 char *str, *__script_root;
740 char *path = NULL;
741
742 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
743
744 scripts_dir = opendir(scripts_path);
745 if (!scripts_dir)
746 return NULL;
747
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600748 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
Tom Zanussi38752942009-12-15 02:53:39 -0600749 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
750 lang_dirent.d_name);
751 lang_dir = opendir(lang_path);
752 if (!lang_dir)
753 continue;
754
Shawn Bohrer008f29d2010-11-21 10:09:39 -0600755 for_each_script(lang_path, lang_dir, script_dirent, script_next) {
Tom Zanussi38752942009-12-15 02:53:39 -0600756 __script_root = strdup(script_dirent.d_name);
Stephane Eranian965bb6b2010-12-03 17:52:01 +0200757 str = (char *)ends_with(__script_root, suffix);
Tom Zanussi38752942009-12-15 02:53:39 -0600758 if (str) {
759 *str = '\0';
760 if (strcmp(__script_root, script_root))
761 continue;
762 snprintf(script_path, MAXPATHLEN, "%s/%s",
763 lang_path, script_dirent.d_name);
764 path = strdup(script_path);
765 free(__script_root);
766 break;
767 }
768 free(__script_root);
769 }
770 }
771
772 return path;
773}
774
Tom Zanussib5b87312010-11-10 08:16:51 -0600775static bool is_top_script(const char *script_path)
776{
Stephane Eranian965bb6b2010-12-03 17:52:01 +0200777 return ends_with(script_path, "top") == NULL ? false : true;
Tom Zanussib5b87312010-11-10 08:16:51 -0600778}
779
780static int has_required_arg(char *script_path)
781{
782 struct script_desc *desc;
783 int n_args = 0;
784 char *p;
785
786 desc = script_desc__new(NULL);
787
788 if (read_script_info(desc, script_path))
789 goto out;
790
791 if (!desc->args)
792 goto out;
793
794 for (p = desc->args; *p; p++)
795 if (*p == '<')
796 n_args++;
797out:
798 script_desc__delete(desc);
799
800 return n_args;
801}
802
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100803static const char * const script_usage[] = {
804 "perf script [<options>]",
805 "perf script [<options>] record <script> [<record-options>] <command>",
806 "perf script [<options>] report <script> [script-args]",
807 "perf script [<options>] <script> [<record-options>] <command>",
808 "perf script [<options>] <top-script> [script-args]",
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200809 NULL
810};
811
812static const struct option options[] = {
813 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
814 "dump raw trace in ASCII"),
Ian Munsiec0555642010-04-13 18:37:33 +1000815 OPT_INCR('v', "verbose", &verbose,
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200816 "be more verbose (show symbol address, etc)"),
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600817 OPT_BOOLEAN('L', "Latency", &latency_format,
Steven Rostedtcda48462009-10-14 15:43:42 -0400818 "show latency attributes (irqs/preemption disabled, etc)"),
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600819 OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
820 list_available_scripts),
Tom Zanussi956ffd02009-11-25 01:15:46 -0600821 OPT_CALLBACK('s', "script", NULL, "name",
822 "script file name (lang:script name, script name, or *)",
823 parse_scriptname),
824 OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100825 "generate perf-script.xx script in specified language"),
Hitoshi Mitake408f0d12010-01-22 22:45:29 +0900826 OPT_STRING('i', "input", &input_name, "file",
827 "input file name"),
Frederic Weisbeckerffabd992010-05-27 16:27:47 +0200828 OPT_BOOLEAN('d', "debug-mode", &debug_mode,
829 "do various checks like samples ordering and lost events"),
David Ahernc0230b22011-03-09 22:23:27 -0700830 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
831 "file", "vmlinux pathname"),
832 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
833 "file", "kallsyms pathname"),
834 OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
835 "When printing symbols do not display call chain"),
836 OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
837 "Look for files with symbols relative to this directory"),
David Ahern745f43e2011-03-09 22:23:26 -0700838 OPT_CALLBACK('f', "fields", NULL, "str",
David Ahern1424dc92011-03-09 22:23:28 -0700839 "comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace. Fields: comm,tid,pid,time,cpu,event,trace,sym",
David Ahern745f43e2011-03-09 22:23:26 -0700840 parse_output_fields),
Tom Zanussi956ffd02009-11-25 01:15:46 -0600841
Masami Hiramatsu19096292009-08-21 14:56:03 -0400842 OPT_END()
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200843};
844
Tom Zanussi34c86ea2010-11-10 08:15:43 -0600845static bool have_cmd(int argc, const char **argv)
846{
847 char **__argv = malloc(sizeof(const char *) * argc);
848
849 if (!__argv)
850 die("malloc");
851 memcpy(__argv, argv, sizeof(const char *) * argc);
852 argc = parse_options(argc, (const char **)__argv, record_options,
853 NULL, PARSE_OPT_STOP_AT_NON_OPTION);
854 free(__argv);
855
856 return argc != 0;
857}
858
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100859int cmd_script(int argc, const char **argv, const char *prefix __used)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200860{
Tom Zanussib5b87312010-11-10 08:16:51 -0600861 char *rec_script_path = NULL;
862 char *rep_script_path = NULL;
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200863 struct perf_session *session;
Tom Zanussib5b87312010-11-10 08:16:51 -0600864 char *script_path = NULL;
Tom Zanussi38752942009-12-15 02:53:39 -0600865 const char **__argv;
Tom Zanussib5b87312010-11-10 08:16:51 -0600866 bool system_wide;
867 int i, j, err;
Tom Zanussi38752942009-12-15 02:53:39 -0600868
Tom Zanussib5b87312010-11-10 08:16:51 -0600869 setup_scripting();
870
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100871 argc = parse_options(argc, argv, options, script_usage,
Tom Zanussib5b87312010-11-10 08:16:51 -0600872 PARSE_OPT_STOP_AT_NON_OPTION);
873
874 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
875 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
876 if (!rec_script_path)
877 return cmd_record(argc, argv, NULL);
Tom Zanussi38752942009-12-15 02:53:39 -0600878 }
879
Tom Zanussib5b87312010-11-10 08:16:51 -0600880 if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
881 rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
882 if (!rep_script_path) {
Tom Zanussi38752942009-12-15 02:53:39 -0600883 fprintf(stderr,
Tom Zanussib5b87312010-11-10 08:16:51 -0600884 "Please specify a valid report script"
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100885 "(see 'perf script -l' for listing)\n");
Tom Zanussi38752942009-12-15 02:53:39 -0600886 return -1;
887 }
Tom Zanussi38752942009-12-15 02:53:39 -0600888 }
889
Ben Hutchings44e668c2010-10-10 16:10:03 +0100890 /* make sure PERF_EXEC_PATH is set for scripts */
891 perf_set_argv_exec_path(perf_exec_path());
892
Tom Zanussib5b87312010-11-10 08:16:51 -0600893 if (argc && !script_name && !rec_script_path && !rep_script_path) {
Tom Zanussia0cccc22010-04-01 23:59:25 -0500894 int live_pipe[2];
Tom Zanussib5b87312010-11-10 08:16:51 -0600895 int rep_args;
Tom Zanussia0cccc22010-04-01 23:59:25 -0500896 pid_t pid;
897
Tom Zanussib5b87312010-11-10 08:16:51 -0600898 rec_script_path = get_script_path(argv[0], RECORD_SUFFIX);
899 rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);
900
901 if (!rec_script_path && !rep_script_path) {
902 fprintf(stderr, " Couldn't find script %s\n\n See perf"
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100903 " script -l for available scripts.\n", argv[0]);
904 usage_with_options(script_usage, options);
Tom Zanussia0cccc22010-04-01 23:59:25 -0500905 }
906
Tom Zanussib5b87312010-11-10 08:16:51 -0600907 if (is_top_script(argv[0])) {
908 rep_args = argc - 1;
909 } else {
910 int rec_args;
911
912 rep_args = has_required_arg(rep_script_path);
913 rec_args = (argc - 1) - rep_args;
914 if (rec_args < 0) {
915 fprintf(stderr, " %s script requires options."
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100916 "\n\n See perf script -l for available "
Tom Zanussib5b87312010-11-10 08:16:51 -0600917 "scripts and options.\n", argv[0]);
Ingo Molnar133dc4c2010-11-16 18:45:39 +0100918 usage_with_options(script_usage, options);
Tom Zanussib5b87312010-11-10 08:16:51 -0600919 }
Tom Zanussia0cccc22010-04-01 23:59:25 -0500920 }
921
922 if (pipe(live_pipe) < 0) {
923 perror("failed to create pipe");
924 exit(-1);
925 }
926
927 pid = fork();
928 if (pid < 0) {
929 perror("failed to fork");
930 exit(-1);
931 }
932
933 if (!pid) {
Tom Zanussib5b87312010-11-10 08:16:51 -0600934 system_wide = true;
935 j = 0;
936
Tom Zanussia0cccc22010-04-01 23:59:25 -0500937 dup2(live_pipe[1], 1);
938 close(live_pipe[0]);
939
Tom Zanussib5b87312010-11-10 08:16:51 -0600940 if (!is_top_script(argv[0]))
941 system_wide = !have_cmd(argc - rep_args,
942 &argv[rep_args]);
943
944 __argv = malloc((argc + 6) * sizeof(const char *));
Tom Zanussie8719ad2010-11-10 07:52:32 -0600945 if (!__argv)
946 die("malloc");
947
Tom Zanussib5b87312010-11-10 08:16:51 -0600948 __argv[j++] = "/bin/sh";
949 __argv[j++] = rec_script_path;
950 if (system_wide)
951 __argv[j++] = "-a";
952 __argv[j++] = "-q";
953 __argv[j++] = "-o";
954 __argv[j++] = "-";
955 for (i = rep_args + 1; i < argc; i++)
956 __argv[j++] = argv[i];
957 __argv[j++] = NULL;
Tom Zanussia0cccc22010-04-01 23:59:25 -0500958
959 execvp("/bin/sh", (char **)__argv);
Tom Zanussie8719ad2010-11-10 07:52:32 -0600960 free(__argv);
Tom Zanussia0cccc22010-04-01 23:59:25 -0500961 exit(-1);
962 }
963
964 dup2(live_pipe[0], 0);
965 close(live_pipe[1]);
966
Tom Zanussib5b87312010-11-10 08:16:51 -0600967 __argv = malloc((argc + 4) * sizeof(const char *));
Tom Zanussie8719ad2010-11-10 07:52:32 -0600968 if (!__argv)
969 die("malloc");
Tom Zanussib5b87312010-11-10 08:16:51 -0600970 j = 0;
Tom Zanussi34c86ea2010-11-10 08:15:43 -0600971 __argv[j++] = "/bin/sh";
Tom Zanussib5b87312010-11-10 08:16:51 -0600972 __argv[j++] = rep_script_path;
973 for (i = 1; i < rep_args + 1; i++)
Tom Zanussi34c86ea2010-11-10 08:15:43 -0600974 __argv[j++] = argv[i];
Tom Zanussib5b87312010-11-10 08:16:51 -0600975 __argv[j++] = "-i";
976 __argv[j++] = "-";
Tom Zanussi34c86ea2010-11-10 08:15:43 -0600977 __argv[j++] = NULL;
Tom Zanussi38752942009-12-15 02:53:39 -0600978
979 execvp("/bin/sh", (char **)__argv);
Tom Zanussie8719ad2010-11-10 07:52:32 -0600980 free(__argv);
Tom Zanussi38752942009-12-15 02:53:39 -0600981 exit(-1);
982 }
Tom Zanussi956ffd02009-11-25 01:15:46 -0600983
Tom Zanussib5b87312010-11-10 08:16:51 -0600984 if (rec_script_path)
985 script_path = rec_script_path;
986 if (rep_script_path)
987 script_path = rep_script_path;
Tom Zanussi956ffd02009-11-25 01:15:46 -0600988
Tom Zanussib5b87312010-11-10 08:16:51 -0600989 if (script_path) {
990 system_wide = false;
991 j = 0;
992
993 if (rec_script_path)
994 system_wide = !have_cmd(argc - 1, &argv[1]);
995
996 __argv = malloc((argc + 2) * sizeof(const char *));
997 if (!__argv)
998 die("malloc");
999 __argv[j++] = "/bin/sh";
1000 __argv[j++] = script_path;
1001 if (system_wide)
1002 __argv[j++] = "-a";
1003 for (i = 2; i < argc; i++)
1004 __argv[j++] = argv[i];
1005 __argv[j++] = NULL;
1006
1007 execvp("/bin/sh", (char **)__argv);
1008 free(__argv);
1009 exit(-1);
1010 }
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001011
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -02001012 if (symbol__init() < 0)
1013 return -1;
Tom Zanussicf4fee52010-03-03 01:04:33 -06001014 if (!script_name)
1015 setup_pager();
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001016
Ian Munsie21ef97f2010-12-10 14:09:16 +11001017 session = perf_session__new(input_name, O_RDONLY, 0, false, &event_ops);
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -02001018 if (session == NULL)
1019 return -ENOMEM;
1020
David Ahern1424dc92011-03-09 22:23:28 -07001021 if (!no_callchain)
David Ahernc0230b22011-03-09 22:23:27 -07001022 symbol_conf.use_callchain = true;
1023 else
1024 symbol_conf.use_callchain = false;
1025
Tom Zanussi956ffd02009-11-25 01:15:46 -06001026 if (generate_script_lang) {
1027 struct stat perf_stat;
David Ahern745f43e2011-03-09 22:23:26 -07001028 int input;
Tom Zanussi956ffd02009-11-25 01:15:46 -06001029
David Ahern745f43e2011-03-09 22:23:26 -07001030 if (output_set_by_user) {
1031 fprintf(stderr,
1032 "custom fields not supported for generated scripts");
1033 return -1;
1034 }
1035
1036 input = open(input_name, O_RDONLY);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001037 if (input < 0) {
1038 perror("failed to open file");
1039 exit(-1);
1040 }
1041
1042 err = fstat(input, &perf_stat);
1043 if (err < 0) {
1044 perror("failed to stat file");
1045 exit(-1);
1046 }
1047
1048 if (!perf_stat.st_size) {
1049 fprintf(stderr, "zero-sized file, nothing to do!\n");
1050 exit(0);
1051 }
1052
1053 scripting_ops = script_spec__lookup(generate_script_lang);
1054 if (!scripting_ops) {
1055 fprintf(stderr, "invalid language specifier");
1056 return -1;
1057 }
1058
Ingo Molnar133dc4c2010-11-16 18:45:39 +01001059 err = scripting_ops->generate_script("perf-script");
Tom Zanussi956ffd02009-11-25 01:15:46 -06001060 goto out;
1061 }
1062
1063 if (script_name) {
Tom Zanussi586bc5c2009-12-15 02:53:35 -06001064 err = scripting_ops->start_script(script_name, argc, argv);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001065 if (err)
1066 goto out;
Ingo Molnar133dc4c2010-11-16 18:45:39 +01001067 pr_debug("perf script started with script %s\n\n", script_name);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001068 }
1069
Ingo Molnar133dc4c2010-11-16 18:45:39 +01001070 err = __cmd_script(session);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001071
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -02001072 perf_session__delete(session);
Tom Zanussi956ffd02009-11-25 01:15:46 -06001073 cleanup_scripting();
1074out:
1075 return err;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001076}