diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2021-05-03 11:13:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 11:13:37 +0000 |
commit | ac3f9b171754014126edf6235d7d751f9aaa4ea5 (patch) | |
tree | 2042dd486cf52293d1427e60fc8907508ae51212 /libnetdata/ebpf | |
parent | 705a766c3fcea0df0b360b3ad858a2f5e2ee025b (diff) |
Ebpf directory cache (#10855)
Add new thread to ebpf.plugin.
Diffstat (limited to 'libnetdata/ebpf')
-rw-r--r-- | libnetdata/ebpf/ebpf.c | 44 | ||||
-rw-r--r-- | libnetdata/ebpf/ebpf.h | 2 |
2 files changed, 46 insertions, 0 deletions
diff --git a/libnetdata/ebpf/ebpf.c b/libnetdata/ebpf/ebpf.c index 985d9a674b..1f71f6a248 100644 --- a/libnetdata/ebpf/ebpf.c +++ b/libnetdata/ebpf/ebpf.c @@ -416,6 +416,50 @@ struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, char * return ebpf_attach_programs(*obj, count_programs, em->names); } +static char *ebpf_update_name(char *search) +{ + char filename[FILENAME_MAX + 1]; + char *ret = NULL; + snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, NETDATA_KALLSYMS); + procfile *ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT); + if(unlikely(!ff)) { + error("Cannot open %s%s", netdata_configured_host_prefix, NETDATA_KALLSYMS); + return ret; + } + + ff = procfile_readall(ff); + if(unlikely(!ff)) + return ret; + + unsigned long i, lines = procfile_lines(ff); + size_t length = strlen(search); + for(i = 0; i < lines ; i++) { + char *cmp = procfile_lineword(ff, i,2);; + if (!strncmp(search, cmp, length)) { + ret = strdupz(cmp); + break; + } + } + + procfile_close(ff); + + return ret; +} + +void ebpf_update_names(ebpf_specify_name_t *opt, ebpf_module_t *em) +{ + int mode = em->mode; + em->names = opt; + + size_t i = 0; + while (opt[i].program_name) { + opt[i].retprobe = (mode == MODE_RETURN); + opt[i].optional = ebpf_update_name(opt[i].function_to_attach); + + i++; + } +} + //---------------------------------------------------------------------------------------------------------------------- void ebpf_mount_config_name(char *filename, size_t length, char *path, char *config) diff --git a/libnetdata/ebpf/ebpf.h b/libnetdata/ebpf/ebpf.h index 89f8bf45fb..bc55d95951 100644 --- a/libnetdata/ebpf/ebpf.h +++ b/libnetdata/ebpf/ebpf.h @@ -7,6 +7,7 @@ #include <bpf/libbpf.h> #define NETDATA_DEBUGFS "/sys/kernel/debug/tracing/" +#define NETDATA_KALLSYMS "/proc/kallsyms" // Config files #define EBPF_GLOBAL_SECTION "global" @@ -143,5 +144,6 @@ extern void ebpf_mount_config_name(char *filename, size_t length, char *path, ch extern int ebpf_load_config(struct config *config, char *filename); extern void ebpf_update_module_using_config(ebpf_module_t *modules, struct config *cfg); extern void ebpf_update_module(ebpf_module_t *em, struct config *cfg, char *cfg_file); +extern void ebpf_update_names(ebpf_specify_name_t *opt, ebpf_module_t *em); #endif /* NETDATA_EBPF_H */ |