20 #include <sys/types.h> 32 #include <api/fs/tracing_path.h> 40 #define MAX_CMDLEN 4094 50 config =
"CONFIG_UPROBE_EVENTS";
52 config =
"CONFIG_KPROBE_EVENTS";
54 pr_warning(
"%cprobe_events file does not exist" 55 " - please rebuild kernel with %s.\n",
56 uprobe ?
'u' :
'k', config);
57 }
else if (err == -ENOTSUP)
58 pr_warning(
"Tracefs or debugfs is not mounted.\n");
60 pr_warning(
"Failed to open %cprobe_events: %s\n",
62 str_error_r(-err, sbuf,
sizeof(sbuf)));
68 if (kerr == -ENOTSUP && uerr == -ENOTSUP)
69 pr_warning(
"Tracefs or debugfs is not mounted.\n");
70 else if (kerr == -ENOENT && uerr == -ENOENT)
71 pr_warning(
"Please rebuild kernel with CONFIG_KPROBE_EVENTS " 72 "or/and CONFIG_UPROBE_EVENTS.\n");
75 pr_warning(
"Failed to open kprobe events: %s.\n",
76 str_error_r(-kerr, sbuf,
sizeof(sbuf)));
77 pr_warning(
"Failed to open uprobe events: %s.\n",
78 str_error_r(-uerr, sbuf,
sizeof(sbuf)));
89 pr_debug(
"Opening %s write=%d\n", buf, readwrite);
91 ret = open(buf, O_RDWR | O_APPEND, 0);
93 ret = open(buf, O_RDONLY, 0);
132 if (*kfd < 0 && *ufd < 0) {
160 fp = fdopen(fddup,
"r");
162 goto out_close_fddup;
174 pr_debug(
"strlist__add failed (%d)\n", ret);
200 memset(&tev, 0,
sizeof(tev));
242 pr_debug(
"Failed to synthesize probe trace event.\n");
246 pr_debug(
"Writing event: %s\n", buf);
248 if (write(fd, buf, strlen(buf)) < (
int)strlen(buf)) {
251 str_error_r(errno, sbuf,
sizeof(sbuf)));
270 p = strchr(buf + 2,
':');
272 pr_debug(
"Internal error: %s should have ':' but not.\n",
279 pr_debug(
"Writing event: %s\n", buf);
280 ret = write(fd, buf, strlen(buf));
289 str_error_r(-ret, buf,
sizeof(buf)));
309 p = strchr(ent->
s,
':');
357 BUG_ON(!list_empty(&entry->
node));
372 INIT_LIST_HEAD(&entry->
node);
400 *tevs =
zalloc(ret *
sizeof(*tev));
420 char *dir_name = NULL;
421 bool is_kallsyms =
false;
443 pr_debug(
"Failed to get build-id from %s.\n", target);
452 pr_debug(
"Failed to add build-id cache: %s\n", target);
461 pr_debug(
"Failed to get cache from %s\n", target);
465 snprintf(cpath,
PATH_MAX,
"%s/probes", dir_name);
466 fd = open(cpath, O_CREAT | O_RDWR, 0644);
468 pr_debug(
"Failed to open cache(%d): %s\n", fd, cpath);
482 fddup = dup(pcache->
fd);
485 fp = fdopen(fddup,
"r");
494 p = strchr(buf,
'\n');
498 if (buf[0] ==
'#' || buf[0] ==
'%') {
506 entry->
spev = strdup(buf + 1);
535 INIT_LIST_HEAD(&pcache->
entries);
536 pcache->
fd = -EINVAL;
545 list_for_each_entry_safe(entry, n, &pcache->
entries,
node) {
546 list_del_init(&entry->
node);
572 pr_debug(
"Cache open error: %d\n", ret);
578 pr_debug(
"Cache read error: %d\n", ret);
589 static bool streql(
const char *a,
const char *b)
597 return !strcmp(a, b);
623 (!strcmp(entry->
spev, cmd)))
659 if (!pcache || !pev || !tevs || ntevs <= 0) {
667 list_del_init(&entry->
node);
676 for (i = 0; i < ntevs; i++) {
677 if (!tevs[i].point.symbol)
687 pr_debug(
"Added probe cache: %d\n", ntevs);
691 pr_debug(
"Failed to add probe caches\n");
696 #ifdef HAVE_GELF_GETNOTE_SUPPORT 697 static unsigned long long sdt_note__get_addr(
struct sdt_note *note)
699 return note->
bit32 ? (
unsigned long long)note->
addr.
a32[0]
700 : (
unsigned long long)note->
addr.
a64[0];
703 static const char *
const type_to_suffix[] = {
704 ":s64",
"",
"",
"",
":s32",
"",
":s16",
":s8",
705 "",
":u8",
":u16",
"",
":u32",
"",
"",
"",
":u64" 713 static int sdt_arg_parse_size(
char *n_ptr,
const char **suffix)
717 type_idx = strtol(n_ptr, NULL, 10);
718 if (type_idx < -8 || type_idx > 8) {
719 pr_debug4(
"Failed to get a valid sdt type\n");
723 *suffix = type_to_suffix[type_idx + 8];
727 static int synthesize_sdt_probe_arg(
struct strbuf *buf,
int i,
const char *arg)
729 char *op, *
desc = strdup(arg), *new_op = NULL;
730 const char *suffix =
"";
743 op = strchr(desc,
'@');
748 if (sdt_arg_parse_size(desc, &suffix))
760 ret =
strbuf_addf(buf,
" arg%d=%s%s", i + 1, new_op, suffix);
772 static char *synthesize_sdt_probe_command(
struct sdt_note *note,
773 const char *pathname,
777 char *ret = NULL, **
args;
784 sdtgrp, note->
name, pathname,
785 sdt_note__get_addr(note)) < 0)
794 for (i = 0; i < args_count; ++i) {
795 if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
807 int probe_cache__scan_sdt(
struct probe_cache *pcache,
const char *pathname)
810 struct list_head sdtlist;
816 INIT_LIST_HEAD(&sdtlist);
819 pr_debug4(
"Failed to get sdt note: %d\n", ret);
822 list_for_each_entry(note, &sdtlist,
note_list) {
823 ret = snprintf(sdtgrp, 64,
"sdt_%s", note->
provider);
835 ret = asprintf(&entry->
spev,
"%s:%s=%s", sdtgrp,
843 buf = synthesize_sdt_probe_command(note, pathname, sdtgrp);
854 list_del_init(&entry->
node);
867 const char *prefix = entry->
sdt ?
"%" :
"#";
870 ret = fstat(fd, &st);
875 iov[0].iov_base = (
void *)prefix; iov[0].iov_len = 1;
876 iov[1].iov_base = entry->
spev; iov[1].iov_len = strlen(entry->
spev);
877 iov[2].iov_base = (
void *)
"\n"; iov[2].iov_len = 1;
878 ret = writev(fd, iov, 3);
879 if (ret < (
int)iov[1].iov_len + 2)
883 iov[0].iov_base = (
void *)snode->
s;
884 iov[0].iov_len = strlen(snode->
s);
885 iov[1].iov_base = (
void *)
"\n"; iov[1].iov_len = 1;
886 ret = writev(fd, iov, 2);
887 if (ret < (
int)iov[0].iov_len + 1)
896 if (ftruncate(fd, st.st_size) < 0)
908 ret = lseek(pcache->
fd, 0, SEEK_SET);
912 ret = ftruncate(pcache->
fd, 0);
918 pr_debug(
"Cache committed: %d\n", ret);
929 char buf[128], *ptr = entry->
spev;
943 list_for_each_entry_safe(entry, tmp, &pcache->
entries,
node) {
945 pr_info(
"Removed cached event: %s\n", entry->
spev);
946 list_del_init(&entry->
node);
960 printf(
"%s\n", entry->
spev);
973 pr_debug(
"list cache with filter: %s\n", buf);
978 pr_debug(
"Failed to get buildids: %d\n", errno);
985 if (!list_empty(&pcache->
entries)) {
987 printf(
"%s (%s):\n", buf, nd->
s);
1008 #define DEFINE_TYPE(idx, pat) \ 1009 [idx] = {.pattern = pat, .avail = false} 1021 static bool scanned =
false;
1030 fp = fdopen(fd,
"r");
1036 while (getline(&buf, &len, fp) > 0)
1047 if (type >= FTRACE_README_END)
char * build_id_cache__origname(const char *sbuild_id)
int strbuf_init(struct strbuf *sb, ssize_t hint)
int probe_cache__add_entry(struct probe_cache *pcache, struct perf_probe_event *pev, struct probe_trace_event *tevs, int ntevs)
char * build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size)
struct probe_cache_entry * probe_cache__find(struct probe_cache *pcache, struct perf_probe_event *pev)
void clear_probe_trace_event(struct probe_trace_event *tev)
void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc)
static int probe_cache__show_entries(struct probe_cache *pcache, struct strfilter *filter)
static struct strlist * __probe_file__get_namelist(int fd, bool include_group)
int probe_file__open_both(int *kfd, int *ufd, int flag)
int cleanup_sdt_note_list(struct list_head *sdt_notes)
int arch_sdt_arg_parse_op(char *old_op, char **new_op)
int build_id_cache__add_s(const char *sbuild_id, const char *name, struct nsinfo *nsi, bool is_kallsyms, bool is_vdso)
static struct probe_cache_entry * probe_cache_entry__new(struct perf_probe_event *pev)
static bool streql(const char *a, const char *b)
int strlist__add(struct strlist *slist, const char *new_entry)
int probe_file__add_event(int fd, struct probe_trace_event *tev)
static void probe_cache_entry__delete(struct probe_cache_entry *entry)
int probe_file__del_strlist(int fd, struct strlist *namelist)
#define for_each_probe_cache_entry(entry, pcache)
struct strlist * probe_file__get_namelist(int fd)
bool strglobmatch(const char *str, const char *pat)
static unsigned int strlist__nr_entries(const struct strlist *slist)
int get_sdt_note_list(struct list_head *head, const char *target)
static void print_both_open_warning(int kerr, int uerr)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
bool kretprobe_offset_is_supported(void)
char * synthesize_perf_probe_command(struct perf_probe_event *pev)
static bool probe_cache_entry__compare(struct probe_cache_entry *entry, struct strfilter *filter)
union sdt_note::@149 addr
#define pr_debug4(fmt,...)
bool probe_type_is_available(enum probe_type type)
char * synthesize_probe_trace_command(struct probe_trace_event *tev)
void nsinfo__mountns_exit(struct nscookie *nc)
#define pr_debug(fmt,...)
int probe_file__del_events(int fd, struct strfilter *filter)
void clear_perf_probe_event(struct perf_probe_event *pev)
static int entry(u64 ip, struct unwind_info *ui)
#define strlist__for_each_entry(pos, slist)
int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
void probe_cache__purge(struct probe_cache *pcache)
struct probe_cache * probe_cache__new(const char *target, struct nsinfo *nsi)
static struct probe_cache * probe_cache__alloc(void)
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
char * strfilter__string(struct strfilter *filter)
#define DSO__NAME_KALLSYMS
struct list_head note_list
bool strfilter__compare(struct strfilter *filter, const char *str)
int open_trace_file(const char *trace_file, bool readwrite)
void probe_cache__delete(struct probe_cache *pcache)
static int __del_trace_probe_event(int fd, struct str_node *ent)
static struct rb_root result
int e_snprintf(char *str, size_t size, const char *format,...)
struct strfilter * filter
struct probe_cache_entry * probe_cache__find_by_name(struct probe_cache *pcache, const char *group, const char *event)
static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
int probe_cache__commit(struct probe_cache *pcache)
char * strbuf_detach(struct strbuf *sb, size_t *sz)
int probe_cache__filter_purge(struct probe_cache *pcache, struct strfilter *filter)
struct perf_probe_event pev
int probe_cache_entry__get_event(struct probe_cache_entry *entry, struct probe_trace_event **tevs)
static struct @135 ftrace_readme_table[]
char * build_id_cache__cachedir(const char *sbuild_id, const char *name, struct nsinfo *nsi, bool is_kallsyms, bool is_vdso)
bool build_id_cache__cached(const char *sbuild_id)
void strlist__delete(struct strlist *slist)
int probe_cache__show_all_caches(struct strfilter *filter)
static int probe_cache__load(struct probe_cache *pcache)
static int probe_cache__open(struct probe_cache *pcache, const char *target, struct nsinfo *nsi)
struct strlist * build_id_cache__list_all(bool validonly)
int strbuf_addf(struct strbuf *sb, const char *fmt,...)
int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
int perf_probe_event__copy(struct perf_probe_event *dst, struct perf_probe_event *src)
static bool scan_ftrace_readme(enum ftrace_readme type)
int probe_file__open(int flag)
#define pr_warning(fmt,...)
static void print_open_warning(int err, bool uprobe)
static int open_kprobe_events(bool readwrite)
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 int open_uprobe_events(bool readwrite)
void strbuf_release(struct strbuf *sb)
#define DEFINE_TYPE(idx, pat)
char ** argv_split(const char *str, int *argcp)
void static void * zalloc(size_t size)
struct strlist * probe_file__get_rawlist(int fd)