diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2022-05-06 13:43:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-06 13:43:22 +0000 |
commit | b20911cbda25a265ac492bbed1bd44ab9d8a7526 (patch) | |
tree | d17f5dfb22d680825ee22e17615f3138fbd0d148 /libnetdata | |
parent | f851d07fae31995a3b07abdaab046ca57fa48669 (diff) |
Remove sync warning (#12831)
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/ebpf/ebpf.c | 73 | ||||
-rw-r--r-- | libnetdata/ebpf/ebpf.h | 5 |
2 files changed, 75 insertions, 3 deletions
diff --git a/libnetdata/ebpf/ebpf.c b/libnetdata/ebpf/ebpf.c index dde6d57fce..43dc7d6f22 100644 --- a/libnetdata/ebpf/ebpf.c +++ b/libnetdata/ebpf/ebpf.c @@ -843,9 +843,13 @@ void ebpf_adjust_thread_load(ebpf_module_t *mod, struct btf *file) } /** + * Parse BTF file * - * @param filename - * @return + * Parse a specific BTF file present on filesystem + * + * @param filename the file that will be parsed. + * + * @return It returns a pointer for the file on success and NULL otherwise. */ struct btf *ebpf_parse_btf_file(const char *filename) { @@ -858,6 +862,71 @@ struct btf *ebpf_parse_btf_file(const char *filename) return bf; } + +/** + * Load default btf file + * + * Load the default BTF file on environment. + * + * @param path is the fullpath + * @param filename is the file inside BTF path. + */ +struct btf *ebpf_load_btf_file(char *path, char *filename) +{ + char fullpath[PATH_MAX + 1]; + snprintfz(fullpath, PATH_MAX, "%s/%s", path, filename); + struct btf *ret = ebpf_parse_btf_file(fullpath); + if (!ret) + info("Your environment does not have BTF file %s/%s. The plugin will work with 'legacy' code.", + path, filename); + + return ret; +} + +/** + * Find BTF attach type + * + * Search type fr current btf file. + * + * @param file is the structure for the btf file already parsed. + */ +static inline const struct btf_type *ebpf_find_btf_attach_type(struct btf *file) +{ + int id = btf__find_by_name_kind(file, "bpf_attach_type", BTF_KIND_ENUM); + if (id < 0) { + fprintf(stderr, "Cannot find 'bpf_attach_type'"); + + return NULL; + } + + return btf__type_by_id(file, id); +} + +/** + * Is function inside BTF + * + * Look for a specific function inside the given BTF file. + * + * @param file is the structure for the btf file already parsed. + * @param function is the function that we want to find. + */ +int ebpf_is_function_inside_btf(struct btf *file, char *function) +{ + const struct btf_type *type = ebpf_find_btf_attach_type(file); + if (!type) + return -1; + + const struct btf_enum *e = btf_enum(type); + int i, id; + for (id = -1, i = 0; i < btf_vlen(type); i++, e++) { + if (!strcmp(btf__name_by_offset(file, e->name_off), "BPF_TRACE_FENTRY")) { + id = btf__find_by_name_kind(file, function, BTF_KIND_FUNC); + break; + } + } + + return (id > 0) ? 1 : 0; +} #endif /** diff --git a/libnetdata/ebpf/ebpf.h b/libnetdata/ebpf/ebpf.h index f701e1d4dc..ec486b59a8 100644 --- a/libnetdata/ebpf/ebpf.h +++ b/libnetdata/ebpf/ebpf.h @@ -275,7 +275,8 @@ extern int ebpf_enable_tracing_values(char *subsys, char *eventname); extern int ebpf_disable_tracing_values(char *subsys, char *eventname); // BTF Section -#define EBPF_DEFAULT_BTF_FILE "/sys/kernel/btf" +#define EBPF_DEFAULT_BTF_FILE "vmlinux" +#define EBPF_DEFAULT_BTF_PATH "/sys/kernel/btf" #define EBPF_DEFAULT_ERROR_MSG "Cannot open or load BPF file for thread" // BTF helpers @@ -287,6 +288,8 @@ extern void ebpf_select_host_prefix(char *output, size_t length, char *syscall, #ifdef LIBBPF_MAJOR_VERSION extern void ebpf_adjust_thread_load(ebpf_module_t *mod, struct btf *file); extern struct btf *ebpf_parse_btf_file(const char *filename); +extern struct btf *ebpf_load_btf_file(char *path, char *filename); +extern int ebpf_is_function_inside_btf(struct btf *file, char *function); #endif #endif /* NETDATA_EBPF_H */ |