blob: 2eefb33c9679c004120e871c072255b9bcb4c872 [file] [log] [blame]
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +02001#include "builtin.h"
2
3#include "util/util.h"
4#include "util/cache.h"
5#include "util/symbol.h"
6#include "util/thread.h"
7#include "util/header.h"
Ingo Molnarcf723442009-11-28 10:11:00 +01008#include "util/exec_cmd.h"
9#include "util/trace-event.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020010#include "util/session.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020011
Tom Zanussi956ffd02009-11-25 01:15:46 -060012static char const *script_name;
13static char const *generate_script_lang;
14
Tom Zanussi586bc5c2009-12-15 02:53:35 -060015static int default_start_script(const char *script __unused,
16 int argc __unused,
17 const char **argv __unused)
Tom Zanussi956ffd02009-11-25 01:15:46 -060018{
19 return 0;
20}
21
22static int default_stop_script(void)
23{
24 return 0;
25}
26
Tom Zanussi586bc5c2009-12-15 02:53:35 -060027static int default_generate_script(const char *outfile __unused)
Tom Zanussi956ffd02009-11-25 01:15:46 -060028{
29 return 0;
30}
31
32static struct scripting_ops default_scripting_ops = {
33 .start_script = default_start_script,
34 .stop_script = default_stop_script,
35 .process_event = print_event,
36 .generate_script = default_generate_script,
37};
38
39static struct scripting_ops *scripting_ops;
40
41static void setup_scripting(void)
42{
43 /* make sure PERF_EXEC_PATH is set for scripts */
44 perf_set_argv_exec_path(perf_exec_path());
45
Tom Zanussi16c632d2009-11-25 01:15:48 -060046 setup_perl_scripting();
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060047 setup_python_scripting();
Tom Zanussi16c632d2009-11-25 01:15:48 -060048
Tom Zanussi956ffd02009-11-25 01:15:46 -060049 scripting_ops = &default_scripting_ops;
50}
51
52static int cleanup_scripting(void)
53{
54 return scripting_ops->stop_script();
55}
56
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020057#include "util/parse-options.h"
58
59#include "perf.h"
60#include "util/debug.h"
61
62#include "util/trace-event.h"
Tom Zanussi956ffd02009-11-25 01:15:46 -060063#include "util/exec_cmd.h"
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020064
Tom Zanussi956ffd02009-11-25 01:15:46 -060065static char const *input_name = "perf.data";
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020066
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020067static int process_sample_event(event_t *event, struct perf_session *session)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020068{
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090069 struct sample_data data;
70 struct thread *thread;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020071
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090072 memset(&data, 0, sizeof(data));
73 data.time = -1;
74 data.cpu = -1;
75 data.period = 1;
Ingo Molnar6ddf2592009-09-03 12:00:22 +020076
Arnaldo Carvalho de Meloc0198792009-12-14 14:23:00 -020077 event__parse_sample(event, session->sample_type, &data);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020078
Arnaldo Carvalho de Melo0d755032010-01-14 12:23:09 -020079 dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
80 data.pid, data.tid, data.ip, data.period);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020081
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020082 thread = perf_session__findnew(session, event->ip.pid);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020083 if (thread == NULL) {
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020084 pr_debug("problem processing %d event, skipping it.\n",
85 event->header.type);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020086 return -1;
87 }
88
Arnaldo Carvalho de Meloc0198792009-12-14 14:23:00 -020089 if (session->sample_type & PERF_SAMPLE_RAW) {
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020090 /*
91 * FIXME: better resolve from pid from the struct trace_entry
92 * field, although it should be the same than this perf
93 * event pid
94 */
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090095 scripting_ops->process_event(data.cpu, data.raw_data,
96 data.raw_size,
97 data.time, thread->comm);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020098 }
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +020099
Arnaldo Carvalho de Melof823e442009-12-14 15:06:01 -0200100 session->events_stats.total += data.period;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200101 return 0;
102}
103
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -0200104static struct perf_event_ops event_ops = {
Arnaldo Carvalho de Melo55aa640f2009-12-27 21:37:05 -0200105 .sample = process_sample_event,
106 .comm = event__process_comm,
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500107 .attr = event__process_attr,
Tom Zanussicd19a032010-04-01 23:59:20 -0500108 .event_type = event__process_event_type,
Tom Zanussi92155452010-04-01 23:59:21 -0500109 .tracing_data = event__process_tracing_data,
Tom Zanussic7929e42010-04-01 23:59:22 -0500110 .build_id = event__process_build_id,
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200111};
112
Tom Zanussic239da32010-04-01 23:59:18 -0500113extern volatile int session_done;
114
115static void sig_handler(int sig __unused)
116{
117 session_done = 1;
118}
119
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200120static int __cmd_trace(struct perf_session *session)
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200121{
Tom Zanussic239da32010-04-01 23:59:18 -0500122 signal(SIGINT, sig_handler);
123
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -0200124 return perf_session__process_events(session, &event_ops);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200125}
126
Tom Zanussi956ffd02009-11-25 01:15:46 -0600127struct script_spec {
128 struct list_head node;
129 struct scripting_ops *ops;
130 char spec[0];
131};
132
133LIST_HEAD(script_specs);
134
135static struct script_spec *script_spec__new(const char *spec,
136 struct scripting_ops *ops)
137{
138 struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1);
139
140 if (s != NULL) {
141 strcpy(s->spec, spec);
142 s->ops = ops;
143 }
144
145 return s;
146}
147
148static void script_spec__delete(struct script_spec *s)
149{
150 free(s->spec);
151 free(s);
152}
153
154static void script_spec__add(struct script_spec *s)
155{
156 list_add_tail(&s->node, &script_specs);
157}
158
159static struct script_spec *script_spec__find(const char *spec)
160{
161 struct script_spec *s;
162
163 list_for_each_entry(s, &script_specs, node)
164 if (strcasecmp(s->spec, spec) == 0)
165 return s;
166 return NULL;
167}
168
169static struct script_spec *script_spec__findnew(const char *spec,
170 struct scripting_ops *ops)
171{
172 struct script_spec *s = script_spec__find(spec);
173
174 if (s)
175 return s;
176
177 s = script_spec__new(spec, ops);
178 if (!s)
179 goto out_delete_spec;
180
181 script_spec__add(s);
182
183 return s;
184
185out_delete_spec:
186 script_spec__delete(s);
187
188 return NULL;
189}
190
191int script_spec_register(const char *spec, struct scripting_ops *ops)
192{
193 struct script_spec *s;
194
195 s = script_spec__find(spec);
196 if (s)
197 return -1;
198
199 s = script_spec__findnew(spec, ops);
200 if (!s)
201 return -1;
202
203 return 0;
204}
205
206static struct scripting_ops *script_spec__lookup(const char *spec)
207{
208 struct script_spec *s = script_spec__find(spec);
209 if (!s)
210 return NULL;
211
212 return s->ops;
213}
214
215static void list_available_languages(void)
216{
217 struct script_spec *s;
218
219 fprintf(stderr, "\n");
220 fprintf(stderr, "Scripting language extensions (used in "
221 "perf trace -s [spec:]script.[spec]):\n\n");
222
223 list_for_each_entry(s, &script_specs, node)
224 fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name);
225
226 fprintf(stderr, "\n");
227}
228
229static int parse_scriptname(const struct option *opt __used,
230 const char *str, int unset __used)
231{
232 char spec[PATH_MAX];
233 const char *script, *ext;
234 int len;
235
Tom Zanussif526d682010-01-27 02:27:52 -0600236 if (strcmp(str, "lang") == 0) {
Tom Zanussi956ffd02009-11-25 01:15:46 -0600237 list_available_languages();
Tom Zanussif526d682010-01-27 02:27:52 -0600238 exit(0);
Tom Zanussi956ffd02009-11-25 01:15:46 -0600239 }
240
241 script = strchr(str, ':');
242 if (script) {
243 len = script - str;
244 if (len >= PATH_MAX) {
245 fprintf(stderr, "invalid language specifier");
246 return -1;
247 }
248 strncpy(spec, str, len);
249 spec[len] = '\0';
250 scripting_ops = script_spec__lookup(spec);
251 if (!scripting_ops) {
252 fprintf(stderr, "invalid language specifier");
253 return -1;
254 }
255 script++;
256 } else {
257 script = str;
258 ext = strchr(script, '.');
259 if (!ext) {
260 fprintf(stderr, "invalid script extension");
261 return -1;
262 }
263 scripting_ops = script_spec__lookup(++ext);
264 if (!scripting_ops) {
265 fprintf(stderr, "invalid script extension");
266 return -1;
267 }
268 }
269
270 script_name = strdup(script);
271
272 return 0;
273}
274
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600275#define for_each_lang(scripts_dir, lang_dirent, lang_next) \
276 while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
277 lang_next) \
278 if (lang_dirent.d_type == DT_DIR && \
279 (strcmp(lang_dirent.d_name, ".")) && \
280 (strcmp(lang_dirent.d_name, "..")))
281
282#define for_each_script(lang_dir, script_dirent, script_next) \
283 while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
284 script_next) \
285 if (script_dirent.d_type != DT_DIR)
286
287
288#define RECORD_SUFFIX "-record"
289#define REPORT_SUFFIX "-report"
290
291struct script_desc {
292 struct list_head node;
293 char *name;
294 char *half_liner;
295 char *args;
296};
297
298LIST_HEAD(script_descs);
299
300static struct script_desc *script_desc__new(const char *name)
301{
302 struct script_desc *s = zalloc(sizeof(*s));
303
304 if (s != NULL)
305 s->name = strdup(name);
306
307 return s;
308}
309
310static void script_desc__delete(struct script_desc *s)
311{
312 free(s->name);
313 free(s);
314}
315
316static void script_desc__add(struct script_desc *s)
317{
318 list_add_tail(&s->node, &script_descs);
319}
320
321static struct script_desc *script_desc__find(const char *name)
322{
323 struct script_desc *s;
324
325 list_for_each_entry(s, &script_descs, node)
326 if (strcasecmp(s->name, name) == 0)
327 return s;
328 return NULL;
329}
330
331static struct script_desc *script_desc__findnew(const char *name)
332{
333 struct script_desc *s = script_desc__find(name);
334
335 if (s)
336 return s;
337
338 s = script_desc__new(name);
339 if (!s)
340 goto out_delete_desc;
341
342 script_desc__add(s);
343
344 return s;
345
346out_delete_desc:
347 script_desc__delete(s);
348
349 return NULL;
350}
351
352static char *ends_with(char *str, const char *suffix)
353{
354 size_t suffix_len = strlen(suffix);
355 char *p = str;
356
357 if (strlen(str) > suffix_len) {
358 p = str + strlen(str) - suffix_len;
359 if (!strncmp(p, suffix, suffix_len))
360 return p;
361 }
362
363 return NULL;
364}
365
366static char *ltrim(char *str)
367{
368 int len = strlen(str);
369
370 while (len && isspace(*str)) {
371 len--;
372 str++;
373 }
374
375 return str;
376}
377
378static int read_script_info(struct script_desc *desc, const char *filename)
379{
380 char line[BUFSIZ], *p;
381 FILE *fp;
382
383 fp = fopen(filename, "r");
384 if (!fp)
385 return -1;
386
387 while (fgets(line, sizeof(line), fp)) {
388 p = ltrim(line);
389 if (strlen(p) == 0)
390 continue;
391 if (*p != '#')
392 continue;
393 p++;
394 if (strlen(p) && *p == '!')
395 continue;
396
397 p = ltrim(p);
398 if (strlen(p) && p[strlen(p) - 1] == '\n')
399 p[strlen(p) - 1] = '\0';
400
401 if (!strncmp(p, "description:", strlen("description:"))) {
402 p += strlen("description:");
403 desc->half_liner = strdup(ltrim(p));
404 continue;
405 }
406
407 if (!strncmp(p, "args:", strlen("args:"))) {
408 p += strlen("args:");
409 desc->args = strdup(ltrim(p));
410 continue;
411 }
412 }
413
414 fclose(fp);
415
416 return 0;
417}
418
419static int list_available_scripts(const struct option *opt __used,
420 const char *s __used, int unset __used)
421{
422 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
423 char scripts_path[MAXPATHLEN];
424 DIR *scripts_dir, *lang_dir;
425 char script_path[MAXPATHLEN];
426 char lang_path[MAXPATHLEN];
427 struct script_desc *desc;
428 char first_half[BUFSIZ];
429 char *script_root;
430 char *str;
431
432 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
433
434 scripts_dir = opendir(scripts_path);
435 if (!scripts_dir)
436 return -1;
437
438 for_each_lang(scripts_dir, lang_dirent, lang_next) {
439 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
440 lang_dirent.d_name);
441 lang_dir = opendir(lang_path);
442 if (!lang_dir)
443 continue;
444
445 for_each_script(lang_dir, script_dirent, script_next) {
446 script_root = strdup(script_dirent.d_name);
447 str = ends_with(script_root, REPORT_SUFFIX);
448 if (str) {
449 *str = '\0';
450 desc = script_desc__findnew(script_root);
451 snprintf(script_path, MAXPATHLEN, "%s/%s",
452 lang_path, script_dirent.d_name);
453 read_script_info(desc, script_path);
454 }
455 free(script_root);
456 }
457 }
458
459 fprintf(stdout, "List of available trace scripts:\n");
460 list_for_each_entry(desc, &script_descs, node) {
461 sprintf(first_half, "%s %s", desc->name,
462 desc->args ? desc->args : "");
463 fprintf(stdout, " %-36s %s\n", first_half,
464 desc->half_liner ? desc->half_liner : "");
465 }
466
467 exit(0);
468}
469
Tom Zanussi38752942009-12-15 02:53:39 -0600470static char *get_script_path(const char *script_root, const char *suffix)
471{
472 struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
473 char scripts_path[MAXPATHLEN];
474 char script_path[MAXPATHLEN];
475 DIR *scripts_dir, *lang_dir;
476 char lang_path[MAXPATHLEN];
477 char *str, *__script_root;
478 char *path = NULL;
479
480 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
481
482 scripts_dir = opendir(scripts_path);
483 if (!scripts_dir)
484 return NULL;
485
486 for_each_lang(scripts_dir, lang_dirent, lang_next) {
487 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
488 lang_dirent.d_name);
489 lang_dir = opendir(lang_path);
490 if (!lang_dir)
491 continue;
492
493 for_each_script(lang_dir, script_dirent, script_next) {
494 __script_root = strdup(script_dirent.d_name);
495 str = ends_with(__script_root, suffix);
496 if (str) {
497 *str = '\0';
498 if (strcmp(__script_root, script_root))
499 continue;
500 snprintf(script_path, MAXPATHLEN, "%s/%s",
501 lang_path, script_dirent.d_name);
502 path = strdup(script_path);
503 free(__script_root);
504 break;
505 }
506 free(__script_root);
507 }
508 }
509
510 return path;
511}
512
Arnaldo Carvalho de Melo0422a4f2009-12-18 16:35:58 -0200513static const char * const trace_usage[] = {
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200514 "perf trace [<options>] <command>",
515 NULL
516};
517
518static const struct option options[] = {
519 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
520 "dump raw trace in ASCII"),
Ian Munsiec0555642010-04-13 18:37:33 +1000521 OPT_INCR('v', "verbose", &verbose,
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200522 "be more verbose (show symbol address, etc)"),
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600523 OPT_BOOLEAN('L', "Latency", &latency_format,
Steven Rostedtcda48462009-10-14 15:43:42 -0400524 "show latency attributes (irqs/preemption disabled, etc)"),
Tom Zanussi4b9c0c52009-12-15 02:53:38 -0600525 OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
526 list_available_scripts),
Tom Zanussi956ffd02009-11-25 01:15:46 -0600527 OPT_CALLBACK('s', "script", NULL, "name",
528 "script file name (lang:script name, script name, or *)",
529 parse_scriptname),
530 OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
531 "generate perf-trace.xx script in specified language"),
Hitoshi Mitake408f0d12010-01-22 22:45:29 +0900532 OPT_STRING('i', "input", &input_name, "file",
533 "input file name"),
Tom Zanussi956ffd02009-11-25 01:15:46 -0600534
Masami Hiramatsu19096292009-08-21 14:56:03 -0400535 OPT_END()
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200536};
537
538int cmd_trace(int argc, const char **argv, const char *prefix __used)
539{
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200540 struct perf_session *session;
Tom Zanussi38752942009-12-15 02:53:39 -0600541 const char *suffix = NULL;
542 const char **__argv;
543 char *script_path;
544 int i, err;
545
546 if (argc >= 2 && strncmp(argv[1], "rec", strlen("rec")) == 0) {
547 if (argc < 3) {
548 fprintf(stderr,
549 "Please specify a record script\n");
550 return -1;
551 }
552 suffix = RECORD_SUFFIX;
553 }
554
555 if (argc >= 2 && strncmp(argv[1], "rep", strlen("rep")) == 0) {
556 if (argc < 3) {
557 fprintf(stderr,
558 "Please specify a report script\n");
559 return -1;
560 }
561 suffix = REPORT_SUFFIX;
562 }
563
Tom Zanussia0cccc22010-04-01 23:59:25 -0500564 if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) {
565 char *record_script_path, *report_script_path;
566 int live_pipe[2];
567 pid_t pid;
568
569 record_script_path = get_script_path(argv[1], RECORD_SUFFIX);
570 if (!record_script_path) {
571 fprintf(stderr, "record script not found\n");
572 return -1;
573 }
574
575 report_script_path = get_script_path(argv[1], REPORT_SUFFIX);
576 if (!report_script_path) {
577 fprintf(stderr, "report script not found\n");
578 return -1;
579 }
580
581 if (pipe(live_pipe) < 0) {
582 perror("failed to create pipe");
583 exit(-1);
584 }
585
586 pid = fork();
587 if (pid < 0) {
588 perror("failed to fork");
589 exit(-1);
590 }
591
592 if (!pid) {
593 dup2(live_pipe[1], 1);
594 close(live_pipe[0]);
595
596 __argv = malloc(5 * sizeof(const char *));
597 __argv[0] = "/bin/sh";
598 __argv[1] = record_script_path;
599 __argv[2] = "-o";
600 __argv[3] = "-";
601 __argv[4] = NULL;
602
603 execvp("/bin/sh", (char **)__argv);
604 exit(-1);
605 }
606
607 dup2(live_pipe[0], 0);
608 close(live_pipe[1]);
609
610 __argv = malloc((argc + 3) * sizeof(const char *));
611 __argv[0] = "/bin/sh";
612 __argv[1] = report_script_path;
613 for (i = 2; i < argc; i++)
614 __argv[i] = argv[i];
615 __argv[i++] = "-i";
616 __argv[i++] = "-";
617 __argv[i++] = NULL;
618
619 execvp("/bin/sh", (char **)__argv);
620 exit(-1);
621 }
622
Tom Zanussi38752942009-12-15 02:53:39 -0600623 if (suffix) {
624 script_path = get_script_path(argv[2], suffix);
625 if (!script_path) {
626 fprintf(stderr, "script not found\n");
627 return -1;
628 }
629
630 __argv = malloc((argc + 1) * sizeof(const char *));
631 __argv[0] = "/bin/sh";
632 __argv[1] = script_path;
633 for (i = 3; i < argc; i++)
634 __argv[i - 1] = argv[i];
635 __argv[argc - 1] = NULL;
636
637 execvp("/bin/sh", (char **)__argv);
638 exit(-1);
639 }
Tom Zanussi956ffd02009-11-25 01:15:46 -0600640
Tom Zanussi956ffd02009-11-25 01:15:46 -0600641 setup_scripting();
642
Arnaldo Carvalho de Melo0422a4f2009-12-18 16:35:58 -0200643 argc = parse_options(argc, argv, options, trace_usage,
Tom Zanussi586bc5c2009-12-15 02:53:35 -0600644 PARSE_OPT_STOP_AT_NON_OPTION);
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200645
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200646 if (symbol__init() < 0)
647 return -1;
Tom Zanussicf4fee52010-03-03 01:04:33 -0600648 if (!script_name)
649 setup_pager();
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200650
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200651 session = perf_session__new(input_name, O_RDONLY, 0);
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200652 if (session == NULL)
653 return -ENOMEM;
654
Tom Zanussic239da32010-04-01 23:59:18 -0500655 if (strcmp(input_name, "-") &&
656 !perf_session__has_traces(session, "record -R"))
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -0200657 return -EINVAL;
658
Tom Zanussi956ffd02009-11-25 01:15:46 -0600659 if (generate_script_lang) {
660 struct stat perf_stat;
661
662 int input = open(input_name, O_RDONLY);
663 if (input < 0) {
664 perror("failed to open file");
665 exit(-1);
666 }
667
668 err = fstat(input, &perf_stat);
669 if (err < 0) {
670 perror("failed to stat file");
671 exit(-1);
672 }
673
674 if (!perf_stat.st_size) {
675 fprintf(stderr, "zero-sized file, nothing to do!\n");
676 exit(0);
677 }
678
679 scripting_ops = script_spec__lookup(generate_script_lang);
680 if (!scripting_ops) {
681 fprintf(stderr, "invalid language specifier");
682 return -1;
683 }
684
Tom Zanussi956ffd02009-11-25 01:15:46 -0600685 err = scripting_ops->generate_script("perf-trace");
686 goto out;
687 }
688
689 if (script_name) {
Tom Zanussi586bc5c2009-12-15 02:53:35 -0600690 err = scripting_ops->start_script(script_name, argc, argv);
Tom Zanussi956ffd02009-11-25 01:15:46 -0600691 if (err)
692 goto out;
693 }
694
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200695 err = __cmd_trace(session);
Tom Zanussi956ffd02009-11-25 01:15:46 -0600696
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200697 perf_session__delete(session);
Tom Zanussi956ffd02009-11-25 01:15:46 -0600698 cleanup_scripting();
699out:
700 return err;
Frederic Weisbecker5f9c39d2009-08-17 16:18:08 +0200701}