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