perf ftrace: Add support for tracing option 'irq-info'
[linux-2.6-microblaze.git] / tools / perf / builtin-ftrace.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * builtin-ftrace.c
4  *
5  * Copyright (c) 2013  LG Electronics,  Namhyung Kim <namhyung@kernel.org>
6  */
7
8 #include "builtin.h"
9
10 #include <errno.h>
11 #include <unistd.h>
12 #include <signal.h>
13 #include <stdlib.h>
14 #include <fcntl.h>
15 #include <poll.h>
16 #include <linux/capability.h>
17 #include <linux/string.h>
18
19 #include "debug.h"
20 #include <subcmd/pager.h>
21 #include <subcmd/parse-options.h>
22 #include <api/fs/tracing_path.h>
23 #include "evlist.h"
24 #include "target.h"
25 #include "cpumap.h"
26 #include "thread_map.h"
27 #include "util/cap.h"
28 #include "util/config.h"
29 #include "util/units.h"
30 #include "util/parse-sublevel-options.h"
31
32 #define DEFAULT_TRACER  "function_graph"
33
34 struct perf_ftrace {
35         struct evlist           *evlist;
36         struct target           target;
37         const char              *tracer;
38         bool                    list_avail_functions;
39         struct list_head        filters;
40         struct list_head        notrace;
41         struct list_head        graph_funcs;
42         struct list_head        nograph_funcs;
43         int                     graph_depth;
44         unsigned long           percpu_buffer_size;
45         bool                    inherit;
46         int                     func_stack_trace;
47         int                     func_irq_info;
48         int                     graph_nosleep_time;
49         int                     graph_noirqs;
50 };
51
52 struct filter_entry {
53         struct list_head        list;
54         char                    name[];
55 };
56
57 static volatile int workload_exec_errno;
58 static bool done;
59
60 static void sig_handler(int sig __maybe_unused)
61 {
62         done = true;
63 }
64
65 /*
66  * perf_evlist__prepare_workload will send a SIGUSR1 if the fork fails, since
67  * we asked by setting its exec_error to the function below,
68  * ftrace__workload_exec_failed_signal.
69  *
70  * XXX We need to handle this more appropriately, emitting an error, etc.
71  */
72 static void ftrace__workload_exec_failed_signal(int signo __maybe_unused,
73                                                 siginfo_t *info __maybe_unused,
74                                                 void *ucontext __maybe_unused)
75 {
76         workload_exec_errno = info->si_value.sival_int;
77         done = true;
78 }
79
80 static int __write_tracing_file(const char *name, const char *val, bool append)
81 {
82         char *file;
83         int fd, ret = -1;
84         ssize_t size = strlen(val);
85         int flags = O_WRONLY;
86         char errbuf[512];
87         char *val_copy;
88
89         file = get_tracing_file(name);
90         if (!file) {
91                 pr_debug("cannot get tracing file: %s\n", name);
92                 return -1;
93         }
94
95         if (append)
96                 flags |= O_APPEND;
97         else
98                 flags |= O_TRUNC;
99
100         fd = open(file, flags);
101         if (fd < 0) {
102                 pr_debug("cannot open tracing file: %s: %s\n",
103                          name, str_error_r(errno, errbuf, sizeof(errbuf)));
104                 goto out;
105         }
106
107         /*
108          * Copy the original value and append a '\n'. Without this,
109          * the kernel can hide possible errors.
110          */
111         val_copy = strdup(val);
112         if (!val_copy)
113                 goto out_close;
114         val_copy[size] = '\n';
115
116         if (write(fd, val_copy, size + 1) == size + 1)
117                 ret = 0;
118         else
119                 pr_debug("write '%s' to tracing/%s failed: %s\n",
120                          val, name, str_error_r(errno, errbuf, sizeof(errbuf)));
121
122         free(val_copy);
123 out_close:
124         close(fd);
125 out:
126         put_tracing_file(file);
127         return ret;
128 }
129
130 static int write_tracing_file(const char *name, const char *val)
131 {
132         return __write_tracing_file(name, val, false);
133 }
134
135 static int append_tracing_file(const char *name, const char *val)
136 {
137         return __write_tracing_file(name, val, true);
138 }
139
140 static int read_tracing_file_to_stdout(const char *name)
141 {
142         char buf[4096];
143         char *file;
144         int fd;
145         int ret = -1;
146
147         file = get_tracing_file(name);
148         if (!file) {
149                 pr_debug("cannot get tracing file: %s\n", name);
150                 return -1;
151         }
152
153         fd = open(file, O_RDONLY);
154         if (fd < 0) {
155                 pr_debug("cannot open tracing file: %s: %s\n",
156                          name, str_error_r(errno, buf, sizeof(buf)));
157                 goto out;
158         }
159
160         /* read contents to stdout */
161         while (true) {
162                 int n = read(fd, buf, sizeof(buf));
163                 if (n == 0)
164                         break;
165                 else if (n < 0)
166                         goto out_close;
167
168                 if (fwrite(buf, n, 1, stdout) != 1)
169                         goto out_close;
170         }
171         ret = 0;
172
173 out_close:
174         close(fd);
175 out:
176         put_tracing_file(file);
177         return ret;
178 }
179
180 static int write_tracing_file_int(const char *name, int value)
181 {
182         char buf[16];
183
184         snprintf(buf, sizeof(buf), "%d", value);
185         if (write_tracing_file(name, buf) < 0)
186                 return -1;
187
188         return 0;
189 }
190
191 static int write_tracing_option_file(const char *name, const char *val)
192 {
193         char *file;
194         int ret;
195
196         if (asprintf(&file, "options/%s", name) < 0)
197                 return -1;
198
199         ret = __write_tracing_file(file, val, false);
200         free(file);
201         return ret;
202 }
203
204 static int reset_tracing_cpu(void);
205 static void reset_tracing_filters(void);
206
207 static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
208 {
209         write_tracing_option_file("function-fork", "0");
210         write_tracing_option_file("func_stack_trace", "0");
211         write_tracing_option_file("sleep-time", "1");
212         write_tracing_option_file("funcgraph-irqs", "1");
213         write_tracing_option_file("irq-info", "0");
214 }
215
216 static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
217 {
218         if (write_tracing_file("tracing_on", "0") < 0)
219                 return -1;
220
221         if (write_tracing_file("current_tracer", "nop") < 0)
222                 return -1;
223
224         if (write_tracing_file("set_ftrace_pid", " ") < 0)
225                 return -1;
226
227         if (reset_tracing_cpu() < 0)
228                 return -1;
229
230         if (write_tracing_file("max_graph_depth", "0") < 0)
231                 return -1;
232
233         reset_tracing_filters();
234         reset_tracing_options(ftrace);
235         return 0;
236 }
237
238 static int set_tracing_pid(struct perf_ftrace *ftrace)
239 {
240         int i;
241         char buf[16];
242
243         if (target__has_cpu(&ftrace->target))
244                 return 0;
245
246         for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) {
247                 scnprintf(buf, sizeof(buf), "%d",
248                           ftrace->evlist->core.threads->map[i]);
249                 if (append_tracing_file("set_ftrace_pid", buf) < 0)
250                         return -1;
251         }
252         return 0;
253 }
254
255 static int set_tracing_cpumask(struct perf_cpu_map *cpumap)
256 {
257         char *cpumask;
258         size_t mask_size;
259         int ret;
260         int last_cpu;
261
262         last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1);
263         mask_size = last_cpu / 4 + 2; /* one more byte for EOS */
264         mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
265
266         cpumask = malloc(mask_size);
267         if (cpumask == NULL) {
268                 pr_debug("failed to allocate cpu mask\n");
269                 return -1;
270         }
271
272         cpu_map__snprint_mask(cpumap, cpumask, mask_size);
273
274         ret = write_tracing_file("tracing_cpumask", cpumask);
275
276         free(cpumask);
277         return ret;
278 }
279
280 static int set_tracing_cpu(struct perf_ftrace *ftrace)
281 {
282         struct perf_cpu_map *cpumap = ftrace->evlist->core.cpus;
283
284         if (!target__has_cpu(&ftrace->target))
285                 return 0;
286
287         return set_tracing_cpumask(cpumap);
288 }
289
290 static int set_tracing_func_stack_trace(struct perf_ftrace *ftrace)
291 {
292         if (!ftrace->func_stack_trace)
293                 return 0;
294
295         if (write_tracing_option_file("func_stack_trace", "1") < 0)
296                 return -1;
297
298         return 0;
299 }
300
301 static int set_tracing_func_irqinfo(struct perf_ftrace *ftrace)
302 {
303         if (!ftrace->func_irq_info)
304                 return 0;
305
306         if (write_tracing_option_file("irq-info", "1") < 0)
307                 return -1;
308
309         return 0;
310 }
311
312 static int reset_tracing_cpu(void)
313 {
314         struct perf_cpu_map *cpumap = perf_cpu_map__new(NULL);
315         int ret;
316
317         ret = set_tracing_cpumask(cpumap);
318         perf_cpu_map__put(cpumap);
319         return ret;
320 }
321
322 static int __set_tracing_filter(const char *filter_file, struct list_head *funcs)
323 {
324         struct filter_entry *pos;
325
326         list_for_each_entry(pos, funcs, list) {
327                 if (append_tracing_file(filter_file, pos->name) < 0)
328                         return -1;
329         }
330
331         return 0;
332 }
333
334 static int set_tracing_filters(struct perf_ftrace *ftrace)
335 {
336         int ret;
337
338         ret = __set_tracing_filter("set_ftrace_filter", &ftrace->filters);
339         if (ret < 0)
340                 return ret;
341
342         ret = __set_tracing_filter("set_ftrace_notrace", &ftrace->notrace);
343         if (ret < 0)
344                 return ret;
345
346         ret = __set_tracing_filter("set_graph_function", &ftrace->graph_funcs);
347         if (ret < 0)
348                 return ret;
349
350         /* old kernels do not have this filter */
351         __set_tracing_filter("set_graph_notrace", &ftrace->nograph_funcs);
352
353         return ret;
354 }
355
356 static void reset_tracing_filters(void)
357 {
358         write_tracing_file("set_ftrace_filter", " ");
359         write_tracing_file("set_ftrace_notrace", " ");
360         write_tracing_file("set_graph_function", " ");
361         write_tracing_file("set_graph_notrace", " ");
362 }
363
364 static int set_tracing_depth(struct perf_ftrace *ftrace)
365 {
366         if (ftrace->graph_depth == 0)
367                 return 0;
368
369         if (ftrace->graph_depth < 0) {
370                 pr_err("invalid graph depth: %d\n", ftrace->graph_depth);
371                 return -1;
372         }
373
374         if (write_tracing_file_int("max_graph_depth", ftrace->graph_depth) < 0)
375                 return -1;
376
377         return 0;
378 }
379
380 static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace)
381 {
382         int ret;
383
384         if (ftrace->percpu_buffer_size == 0)
385                 return 0;
386
387         ret = write_tracing_file_int("buffer_size_kb",
388                                      ftrace->percpu_buffer_size / 1024);
389         if (ret < 0)
390                 return ret;
391
392         return 0;
393 }
394
395 static int set_tracing_trace_inherit(struct perf_ftrace *ftrace)
396 {
397         if (!ftrace->inherit)
398                 return 0;
399
400         if (write_tracing_option_file("function-fork", "1") < 0)
401                 return -1;
402
403         return 0;
404 }
405
406 static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
407 {
408         if (!ftrace->graph_nosleep_time)
409                 return 0;
410
411         if (write_tracing_option_file("sleep-time", "0") < 0)
412                 return -1;
413
414         return 0;
415 }
416
417 static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
418 {
419         if (!ftrace->graph_noirqs)
420                 return 0;
421
422         if (write_tracing_option_file("funcgraph-irqs", "0") < 0)
423                 return -1;
424
425         return 0;
426 }
427
428 static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
429 {
430         char *trace_file;
431         int trace_fd;
432         char buf[4096];
433         struct pollfd pollfd = {
434                 .events = POLLIN,
435         };
436
437         if (!(perf_cap__capable(CAP_PERFMON) ||
438               perf_cap__capable(CAP_SYS_ADMIN))) {
439                 pr_err("ftrace only works for %s!\n",
440 #ifdef HAVE_LIBCAP_SUPPORT
441                 "users with the CAP_PERFMON or CAP_SYS_ADMIN capability"
442 #else
443                 "root"
444 #endif
445                 );
446                 return -1;
447         }
448
449         signal(SIGINT, sig_handler);
450         signal(SIGUSR1, sig_handler);
451         signal(SIGCHLD, sig_handler);
452         signal(SIGPIPE, sig_handler);
453
454         if (ftrace->list_avail_functions)
455                 return read_tracing_file_to_stdout("available_filter_functions");
456
457         if (reset_tracing_files(ftrace) < 0) {
458                 pr_err("failed to reset ftrace\n");
459                 goto out;
460         }
461
462         /* reset ftrace buffer */
463         if (write_tracing_file("trace", "0") < 0)
464                 goto out;
465
466         if (argc && perf_evlist__prepare_workload(ftrace->evlist,
467                                 &ftrace->target, argv, false,
468                                 ftrace__workload_exec_failed_signal) < 0) {
469                 goto out;
470         }
471
472         if (set_tracing_pid(ftrace) < 0) {
473                 pr_err("failed to set ftrace pid\n");
474                 goto out_reset;
475         }
476
477         if (set_tracing_cpu(ftrace) < 0) {
478                 pr_err("failed to set tracing cpumask\n");
479                 goto out_reset;
480         }
481
482         if (set_tracing_func_stack_trace(ftrace) < 0) {
483                 pr_err("failed to set tracing option func_stack_trace\n");
484                 goto out_reset;
485         }
486
487         if (set_tracing_func_irqinfo(ftrace) < 0) {
488                 pr_err("failed to set tracing option irq-info\n");
489                 goto out_reset;
490         }
491
492         if (set_tracing_filters(ftrace) < 0) {
493                 pr_err("failed to set tracing filters\n");
494                 goto out_reset;
495         }
496
497         if (set_tracing_depth(ftrace) < 0) {
498                 pr_err("failed to set graph depth\n");
499                 goto out_reset;
500         }
501
502         if (set_tracing_percpu_buffer_size(ftrace) < 0) {
503                 pr_err("failed to set tracing per-cpu buffer size\n");
504                 goto out_reset;
505         }
506
507         if (set_tracing_trace_inherit(ftrace) < 0) {
508                 pr_err("failed to set tracing option function-fork\n");
509                 goto out_reset;
510         }
511
512         if (set_tracing_sleep_time(ftrace) < 0) {
513                 pr_err("failed to set tracing option sleep-time\n");
514                 goto out_reset;
515         }
516
517         if (set_tracing_funcgraph_irqs(ftrace) < 0) {
518                 pr_err("failed to set tracing option funcgraph-irqs\n");
519                 goto out_reset;
520         }
521
522         if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
523                 pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
524                 goto out_reset;
525         }
526
527         setup_pager();
528
529         trace_file = get_tracing_file("trace_pipe");
530         if (!trace_file) {
531                 pr_err("failed to open trace_pipe\n");
532                 goto out_reset;
533         }
534
535         trace_fd = open(trace_file, O_RDONLY);
536
537         put_tracing_file(trace_file);
538
539         if (trace_fd < 0) {
540                 pr_err("failed to open trace_pipe\n");
541                 goto out_reset;
542         }
543
544         fcntl(trace_fd, F_SETFL, O_NONBLOCK);
545         pollfd.fd = trace_fd;
546
547         /* display column headers */
548         read_tracing_file_to_stdout("trace");
549
550         if (write_tracing_file("tracing_on", "1") < 0) {
551                 pr_err("can't enable tracing\n");
552                 goto out_close_fd;
553         }
554
555         perf_evlist__start_workload(ftrace->evlist);
556
557         while (!done) {
558                 if (poll(&pollfd, 1, -1) < 0)
559                         break;
560
561                 if (pollfd.revents & POLLIN) {
562                         int n = read(trace_fd, buf, sizeof(buf));
563                         if (n < 0)
564                                 break;
565                         if (fwrite(buf, n, 1, stdout) != 1)
566                                 break;
567                 }
568         }
569
570         write_tracing_file("tracing_on", "0");
571
572         if (workload_exec_errno) {
573                 const char *emsg = str_error_r(workload_exec_errno, buf, sizeof(buf));
574                 /* flush stdout first so below error msg appears at the end. */
575                 fflush(stdout);
576                 pr_err("workload failed: %s\n", emsg);
577                 goto out_close_fd;
578         }
579
580         /* read remaining buffer contents */
581         while (true) {
582                 int n = read(trace_fd, buf, sizeof(buf));
583                 if (n <= 0)
584                         break;
585                 if (fwrite(buf, n, 1, stdout) != 1)
586                         break;
587         }
588
589 out_close_fd:
590         close(trace_fd);
591 out_reset:
592         reset_tracing_files(ftrace);
593 out:
594         return (done && !workload_exec_errno) ? 0 : -1;
595 }
596
597 static int perf_ftrace_config(const char *var, const char *value, void *cb)
598 {
599         struct perf_ftrace *ftrace = cb;
600
601         if (!strstarts(var, "ftrace."))
602                 return 0;
603
604         if (strcmp(var, "ftrace.tracer"))
605                 return -1;
606
607         if (!strcmp(value, "function_graph") ||
608             !strcmp(value, "function")) {
609                 ftrace->tracer = value;
610                 return 0;
611         }
612
613         pr_err("Please select \"function_graph\" (default) or \"function\"\n");
614         return -1;
615 }
616
617 static int parse_filter_func(const struct option *opt, const char *str,
618                              int unset __maybe_unused)
619 {
620         struct list_head *head = opt->value;
621         struct filter_entry *entry;
622
623         entry = malloc(sizeof(*entry) + strlen(str) + 1);
624         if (entry == NULL)
625                 return -ENOMEM;
626
627         strcpy(entry->name, str);
628         list_add_tail(&entry->list, head);
629
630         return 0;
631 }
632
633 static void delete_filter_func(struct list_head *head)
634 {
635         struct filter_entry *pos, *tmp;
636
637         list_for_each_entry_safe(pos, tmp, head, list) {
638                 list_del_init(&pos->list);
639                 free(pos);
640         }
641 }
642
643 static int parse_buffer_size(const struct option *opt,
644                              const char *str, int unset)
645 {
646         unsigned long *s = (unsigned long *)opt->value;
647         static struct parse_tag tags_size[] = {
648                 { .tag  = 'B', .mult = 1       },
649                 { .tag  = 'K', .mult = 1 << 10 },
650                 { .tag  = 'M', .mult = 1 << 20 },
651                 { .tag  = 'G', .mult = 1 << 30 },
652                 { .tag  = 0 },
653         };
654         unsigned long val;
655
656         if (unset) {
657                 *s = 0;
658                 return 0;
659         }
660
661         val = parse_tag_value(str, tags_size);
662         if (val != (unsigned long) -1) {
663                 if (val < 1024) {
664                         pr_err("buffer size too small, must larger than 1KB.");
665                         return -1;
666                 }
667                 *s = val;
668                 return 0;
669         }
670
671         return -1;
672 }
673
674 static int parse_func_tracer_opts(const struct option *opt,
675                                   const char *str, int unset)
676 {
677         int ret;
678         struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
679         struct sublevel_option func_tracer_opts[] = {
680                 { .name = "call-graph", .value_ptr = &ftrace->func_stack_trace },
681                 { .name = "irq-info",   .value_ptr = &ftrace->func_irq_info },
682                 { .name = NULL, }
683         };
684
685         if (unset)
686                 return 0;
687
688         ret = perf_parse_sublevel_options(str, func_tracer_opts);
689         if (ret)
690                 return ret;
691
692         return 0;
693 }
694
695 static int parse_graph_tracer_opts(const struct option *opt,
696                                   const char *str, int unset)
697 {
698         int ret;
699         struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
700         struct sublevel_option graph_tracer_opts[] = {
701                 { .name = "nosleep-time",       .value_ptr = &ftrace->graph_nosleep_time },
702                 { .name = "noirqs",             .value_ptr = &ftrace->graph_noirqs },
703                 { .name = NULL, }
704         };
705
706         if (unset)
707                 return 0;
708
709         ret = perf_parse_sublevel_options(str, graph_tracer_opts);
710         if (ret)
711                 return ret;
712
713         return 0;
714 }
715
716 static void select_tracer(struct perf_ftrace *ftrace)
717 {
718         bool graph = !list_empty(&ftrace->graph_funcs) ||
719                      !list_empty(&ftrace->nograph_funcs);
720         bool func = !list_empty(&ftrace->filters) ||
721                     !list_empty(&ftrace->notrace);
722
723         /* The function_graph has priority over function tracer. */
724         if (graph)
725                 ftrace->tracer = "function_graph";
726         else if (func)
727                 ftrace->tracer = "function";
728         /* Otherwise, the default tracer is used. */
729
730         pr_debug("%s tracer is used\n", ftrace->tracer);
731 }
732
733 int cmd_ftrace(int argc, const char **argv)
734 {
735         int ret;
736         struct perf_ftrace ftrace = {
737                 .tracer = DEFAULT_TRACER,
738                 .target = { .uid = UINT_MAX, },
739         };
740         const char * const ftrace_usage[] = {
741                 "perf ftrace [<options>] [<command>]",
742                 "perf ftrace [<options>] -- <command> [<options>]",
743                 NULL
744         };
745         const struct option ftrace_options[] = {
746         OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
747                    "tracer to use: function_graph(default) or function"),
748         OPT_BOOLEAN('F', "funcs", &ftrace.list_avail_functions,
749                     "Show available functions to filter"),
750         OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
751                    "trace on existing process id"),
752         OPT_INCR('v', "verbose", &verbose,
753                  "be more verbose"),
754         OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
755                     "system-wide collection from all CPUs"),
756         OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
757                     "list of cpus to monitor"),
758         OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func",
759                      "trace given functions using function tracer",
760                      parse_filter_func),
761         OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func",
762                      "do not trace given functions", parse_filter_func),
763         OPT_CALLBACK(0, "func-opts", &ftrace, "options",
764                      "function tracer options, available options: call-graph,irq-info",
765                      parse_func_tracer_opts),
766         OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func",
767                      "trace given functions using function_graph tracer",
768                      parse_filter_func),
769         OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
770                      "Set nograph filter on given functions", parse_filter_func),
771         OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth,
772                     "Max depth for function graph tracer"),
773         OPT_CALLBACK(0, "graph-opts", &ftrace, "options",
774                      "graph tracer options, available options: nosleep-time,noirqs",
775                      parse_graph_tracer_opts),
776         OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
777                      "size of per cpu buffer", parse_buffer_size),
778         OPT_BOOLEAN(0, "inherit", &ftrace.inherit,
779                     "trace children processes"),
780         OPT_END()
781         };
782
783         INIT_LIST_HEAD(&ftrace.filters);
784         INIT_LIST_HEAD(&ftrace.notrace);
785         INIT_LIST_HEAD(&ftrace.graph_funcs);
786         INIT_LIST_HEAD(&ftrace.nograph_funcs);
787
788         ret = perf_config(perf_ftrace_config, &ftrace);
789         if (ret < 0)
790                 return -1;
791
792         argc = parse_options(argc, argv, ftrace_options, ftrace_usage,
793                             PARSE_OPT_STOP_AT_NON_OPTION);
794         if (!argc && target__none(&ftrace.target))
795                 ftrace.target.system_wide = true;
796
797         select_tracer(&ftrace);
798
799         ret = target__validate(&ftrace.target);
800         if (ret) {
801                 char errbuf[512];
802
803                 target__strerror(&ftrace.target, ret, errbuf, 512);
804                 pr_err("%s\n", errbuf);
805                 goto out_delete_filters;
806         }
807
808         ftrace.evlist = evlist__new();
809         if (ftrace.evlist == NULL) {
810                 ret = -ENOMEM;
811                 goto out_delete_filters;
812         }
813
814         ret = perf_evlist__create_maps(ftrace.evlist, &ftrace.target);
815         if (ret < 0)
816                 goto out_delete_evlist;
817
818         ret = __cmd_ftrace(&ftrace, argc, argv);
819
820 out_delete_evlist:
821         evlist__delete(ftrace.evlist);
822
823 out_delete_filters:
824         delete_filter_func(&ftrace.filters);
825         delete_filter_func(&ftrace.notrace);
826         delete_filter_func(&ftrace.graph_funcs);
827         delete_filter_func(&ftrace.nograph_funcs);
828
829         return ret;
830 }