23 #include <sys/utsname.h> 24 #include <sys/types.h> 40 #include <subcmd/parse-options.h> 45 #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" 46 #define DEFAULT_FUNC_FILTER "!_*" 47 #define DEFAULT_LIST_FILTER "*" 95 const char *
err = NULL;
102 ret = err ? -EINVAL : -ENOMEM;
106 if (ret == -EINVAL) {
107 pr_err(
"Filter parse error at %td.\n", err - str + 1);
108 pr_err(
"Source: \"%s\"\n", str);
109 pr_err(
" %*c\n", (
int)(err - str + 1),
'^');
127 if (!
params.target && ptr && *ptr ==
'/') {
128 params.target = strdup(ptr);
131 params.target_used =
false;
134 buf = ptr + (strlen(ptr) - 3);
136 if (strcmp(buf,
".ko"))
146 int i, len, ret, found_target;
150 if (found_target < 0)
153 if (found_target && argc == 1)
158 for (i = 0; i <
argc; i++) {
159 if (i == 0 && found_target)
162 len += strlen(argv[i]) + 1;
168 for (i = 0; i <
argc; i++) {
169 if (i == 0 && found_target)
172 len += sprintf(&buf[len],
"%s ", argv[i]);
180 int unset __maybe_unused)
186 if (!strcmp(opt->long_name,
"exec"))
188 else if (!strcmp(opt->long_name,
"module"))
194 if (
params.uprobes || strchr(str,
'/')) {
197 pr_warning(
"Failed to get the absolute path of %s: %m\n", str);
207 params.target_used =
false;
215 const char *
str,
int unset __maybe_unused)
223 ns_pid = (pid_t)strtol(str, NULL, 10);
226 pr_warning(
"Failed to parse %s as a pid: %s\n", str,
244 #ifdef HAVE_DWARF_SUPPORT 246 const char *
str,
int unset __maybe_unused)
253 if (
params.command ==
'L') {
254 pr_warning(
"Warning: more than one --line options are" 255 " detected. Only the first one is valid.\n");
259 params.command = opt->short_name;
266 const char *
str,
int unset __maybe_unused)
275 if (!ret && pev->
nargs != 0) {
276 pr_err(
" Error: '--vars' doesn't accept arguments.\n");
279 params.command = opt->short_name;
284 # define opt_show_lines NULL 285 # define opt_show_vars NULL 288 const char *
str,
int unset __maybe_unused)
291 params.command = opt->short_name;
299 const char *
str,
int unset)
302 params.command = opt->short_name;
311 const char *
str,
int unset __maybe_unused)
328 for (i = 0; i <
params.nevents; i++)
343 str_error_r(-err, sbuf,
sizeof(sbuf)), err);
351 const char *
event = NULL, *
group = NULL;
361 if (
params.command ==
'D') {
370 for (i = k = 0; i < npevs; i++)
373 pr_info(
"Added new event%s\n", (k > 1) ?
"s:" :
":");
374 for (i = 0; i < npevs; i++) {
377 for (k = 0; k < pev->
ntevs; k++) {
393 pr_info(
"\nYou can now use it in all perf tools, such as:\n\n");
394 pr_info(
"\tperf record -e %s:%s -aR sleep 1\n\n", group,
event);
413 pr_debug(
"Failed to get buildids: %d\n", ret);
414 return ret ?: -ENOMEM;
423 pr_warning(
"Failed to remove entries for %s\n", nd->
s);
431 int ret, ret2, ufd = -1, kfd = -1;
433 struct strlist *klist = NULL, *ulist = NULL;
439 pr_debug(
"Delete filter: \'%s\'\n", str);
451 if (!klist || !ulist) {
459 pr_info(
"Removed event: %s\n", ent->
s);
469 pr_info(
"Removed event: %s\n", ent->
s);
476 if (ret == -ENOENT && ret2 == -ENOENT)
477 pr_warning(
"\"%s\" does not hit any event.\n", str);
494 #ifdef HAVE_DWARF_SUPPORT 495 #define PROBEDEF_STR \ 496 "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT [[NAME=]ARG ...]" 498 #define PROBEDEF_STR "[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]" 505 const char *
const probe_usage[] = {
506 "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]",
507 "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]",
508 "perf probe [<options>] --del '[GROUP:]EVENT' ...",
509 "perf probe --list [GROUP:]EVENT ...",
510 #ifdef HAVE_DWARF_SUPPORT 511 "perf probe [<options>] --line 'LINEDESC'",
512 "perf probe [<options>] --vars 'PROBEPOINT'",
514 "perf probe [<options>] --funcs",
517 struct option options[] = {
518 OPT_INCR(
'v',
"verbose", &
verbose,
519 "be more verbose (show parsed arguments, etc)"),
520 OPT_BOOLEAN(
'q',
"quiet", &
params.quiet,
521 "be quiet (do not show any messages)"),
522 OPT_CALLBACK_DEFAULT(
'l',
"list", NULL,
"[GROUP:]EVENT",
523 "list up probe events",
525 OPT_CALLBACK(
'd',
"del", NULL,
"[GROUP:]EVENT",
"delete a probe event.",
528 "probe point definition, where\n" 529 "\t\tGROUP:\tGroup name (optional)\n" 530 "\t\tEVENT:\tEvent name\n" 531 "\t\tFUNC:\tFunction name\n" 532 "\t\tOFF:\tOffset from function entry (in byte)\n" 533 "\t\t%return:\tPut the probe at function return\n" 534 #ifdef HAVE_DWARF_SUPPORT
535 "\t\tSRC:\tSource code path\n" 536 "\t\tRL:\tRelative line number from function entry.\n" 537 "\t\tAL:\tAbsolute line number in file.\n" 538 "\t\tPT:\tLazy expression of line code.\n" 539 "\t\tARG:\tProbe argument (local variable name or\n" 540 "\t\t\tkprobe-tracer argument format.)\n",
542 "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n",
546 "Show trace event definition of given traceevent for k/uprobe_events.",
547 opt_add_probe_event),
549 " with existing name"),
550 OPT_CALLBACK(
'L',
"line", NULL,
551 "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
553 OPT_CALLBACK(
'V',
"vars", NULL,
554 "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT",
557 "Show external variables too (with --vars only)"),
559 "Show variables location range in scope (with --vars only)"),
561 "file",
"vmlinux pathname"),
563 "directory",
"path to kernel source"),
565 "Don't search inlined functions"),
568 "Set how many probe points can be found for a probe."),
569 OPT_CALLBACK_DEFAULT(
'F',
"funcs", NULL,
"[FILTER]",
570 "Show potential probe-able functions.",
572 OPT_CALLBACK(
'\0',
"filter", NULL,
573 "[!]FILTER",
"Set a filter (with --vars/funcs only)\n" 577 OPT_CALLBACK(
'x',
"exec", NULL,
"executable|path",
579 OPT_CALLBACK(
'm',
"module", NULL,
"modname|path",
580 "target module name (for online) or path (for offline)",
583 "Enable symbol demangling"),
585 "Enable kernel symbol demangling"),
588 "Look for files with symbols relative to this directory"),
589 OPT_CALLBACK(0,
"target-ns", NULL,
"pid",
595 set_option_flag(options,
'a',
"add", PARSE_OPT_EXCLUSIVE);
596 set_option_flag(options,
'd',
"del", PARSE_OPT_EXCLUSIVE);
597 set_option_flag(options,
'D',
"definition", PARSE_OPT_EXCLUSIVE);
598 set_option_flag(options,
'l',
"list", PARSE_OPT_EXCLUSIVE);
599 #ifdef HAVE_DWARF_SUPPORT 600 set_option_flag(options,
'L',
"line", PARSE_OPT_EXCLUSIVE);
601 set_option_flag(options,
'V',
"vars", PARSE_OPT_EXCLUSIVE);
603 # define set_nobuild(s, l, c) set_option_nobuild(options, s, l, "NO_DWARF=1", c) 613 set_option_flag(options,
'F',
"funcs", PARSE_OPT_EXCLUSIVE);
615 argc = parse_options(argc, argv, options, probe_usage,
616 PARSE_OPT_STOP_AT_NON_OPTION);
618 if (strcmp(argv[0],
"-") == 0) {
619 usage_with_options_msg(probe_usage, options,
620 "'-' is not supported.\n");
623 usage_with_options_msg(probe_usage, options,
624 "another command except --add is set.\n");
636 pr_err(
" Error: -v and -q are exclusive.\n");
661 pr_err(
" Error: Don't use --list with --exec.\n");
662 parse_options_usage(probe_usage, options,
"l",
true);
663 parse_options_usage(NULL, options,
"x",
true);
676 #ifdef HAVE_DWARF_SUPPORT 706 pr_err(
" Error: -x/-m must follow the probe definitions.\n");
707 parse_options_usage(probe_usage, options,
"m",
true);
708 parse_options_usage(NULL, options,
"x",
true);
719 usage_with_options(probe_usage, options);
734 return ret < 0 ? ret : 0;
#define DEFAULT_LIST_FILTER
struct nsinfo * nsinfo__new(pid_t pid)
int show_perf_probe_events(struct strfilter *filter)
#define DEFAULT_FUNC_FILTER
struct perf_probe_event events[MAX_PROBES]
const char * source_prefix
int show_perf_probe_event(const char *group, const char *event, struct perf_probe_event *pev, const char *module, bool use_stdout)
const char * vmlinux_name
struct strfilter * strfilter__new(const char *rules, const char **err)
char * nsinfo__realpath(const char *path, struct nsinfo *nsi)
static int opt_add_probe_event(const struct option *opt, const char *str, int unset __maybe_unused)
int probe_file__open_both(int *kfd, int *ufd, int flag)
struct probe_trace_point point
int init_probe_symbol_maps(bool user_only)
#define DEFAULT_VAR_FILTER
void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs)
#define pr_debug2(fmt,...)
int probe_file__del_strlist(int fd, struct strlist *namelist)
static int __cmd_probe(int argc, const char **argv)
int strfilter__or(struct strfilter *filter, const char *rules, const char **err)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs)
void line_range__clear(struct line_range *lr)
struct probe_trace_event * tevs
static int init_params(void)
int show_available_vars(struct perf_probe_event *pevs __maybe_unused, int npevs __maybe_unused, struct strfilter *filter __maybe_unused)
static int set_target(const char *ptr)
int show_available_funcs(const char *target, struct nsinfo *nsi, struct strfilter *_filter, bool user)
int parse_line_range_desc(const char *arg, struct line_range *lr)
void strfilter__delete(struct strfilter *filter)
#define pr_debug(fmt,...)
int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs)
void clear_perf_probe_event(struct perf_probe_event *pev)
void exit_probe_symbol_maps(void)
static int perf_del_probe_events(struct strfilter *filter)
static int str(yyscan_t scanner, int token)
static int parse_probe_event(const char *str)
#define strlist__for_each_entry(pos, slist)
struct probe_cache * probe_cache__new(const char *target, struct nsinfo *nsi)
static int perf_add_probe_events(struct perf_probe_event *pevs, int npevs)
char * strfilter__string(struct strfilter *filter)
bool ignore_vmlinux_buildid
void probe_cache__delete(struct probe_cache *pcache)
int show_probe_trace_events(struct perf_probe_event *pevs, int npevs)
struct nsinfo * nsinfo__get(struct nsinfo *nsi)
struct strfilter * filter
int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
int probe_cache__commit(struct probe_cache *pcache)
static int params_add_filter(const char *str)
int probe_cache__filter_purge(struct probe_cache *pcache, struct strfilter *filter)
int show_line_range(struct line_range *lr __maybe_unused, const char *module __maybe_unused, struct nsinfo *nsi __maybe_unused, bool user __maybe_unused)
void strlist__delete(struct strlist *slist)
static int opt_set_target_ns(const struct option *opt __maybe_unused, const char *str, int unset __maybe_unused)
static int parse_probe_event_argv(int argc, const char **argv)
static int opt_set_filter(const struct option *opt __maybe_unused, const char *str, int unset __maybe_unused)
struct strlist * build_id_cache__list_all(bool validonly)
static void pr_err_with_code(const char *msg, int err)
int cmd_probe(int argc, const char **argv)
static int del_perf_probe_caches(struct strfilter *filter)
#define pr_warning(fmt,...)
int line_range__init(struct line_range *lr)
void nsinfo__put(struct nsinfo *nsi)
static int opt_set_filter_with_command(const struct option *opt, const char *str, int unset)
static int opt_set_target(const struct option *opt, const char *str, int unset __maybe_unused)
int probe_file__get_events(int fd, struct strfilter *filter, struct strlist *plist)
struct strlist * strlist__new(const char *list, const struct strlist_config *config)
static void cleanup_params(void)
void static void * zalloc(size_t size)
#define set_nobuild(s, l, c)