From 6cf8f2d5174a53f582e61d715edbb88d6e3367cc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 14 Jun 2023 21:20:33 +0200 Subject: Adding upstream version 1.40.0. Signed-off-by: Daniel Baumann --- collectors/ebpf.plugin/ebpf_apps.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'collectors/ebpf.plugin/ebpf_apps.c') diff --git a/collectors/ebpf.plugin/ebpf_apps.c b/collectors/ebpf.plugin/ebpf_apps.c index d6db4c676..3826f8efc 100644 --- a/collectors/ebpf.plugin/ebpf_apps.c +++ b/collectors/ebpf.plugin/ebpf_apps.c @@ -1414,6 +1414,28 @@ static inline void aggregate_pid_on_target(struct ebpf_target *w, struct ebpf_pi w->root_pid = pid_on_target; } +/** + * Process Accumulator + * + * Sum all values read from kernel and store in the first address. + * + * @param out the vector with read values. + * @param maps_per_core do I need to read all cores? + */ +void ebpf_process_apps_accumulator(ebpf_process_stat_t *out, int maps_per_core) +{ + int i, end = (maps_per_core) ? ebpf_nprocs : 1; + ebpf_process_stat_t *total = &out[0]; + for (i = 1; i < end; i++) { + ebpf_process_stat_t *w = &out[i]; + total->exit_call += w->exit_call; + total->task_err += w->task_err; + total->create_thread += w->create_thread; + total->create_process += w->create_process; + total->release_call += w->release_call; + } +} + /** * Collect data for all process * @@ -1421,8 +1443,9 @@ static inline void aggregate_pid_on_target(struct ebpf_target *w, struct ebpf_pi * It also creates the link between targets and PIDs. * * @param tbl_pid_stats_fd The mapped file descriptor for the hash table. + * @param maps_per_core do I have hash maps per core? */ -void collect_data_for_all_processes(int tbl_pid_stats_fd) +void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core) { if (unlikely(!ebpf_all_pids)) return; @@ -1448,6 +1471,10 @@ void collect_data_for_all_processes(int tbl_pid_stats_fd) uint32_t key; pids = ebpf_root_of_pids; // global list of all processes running // while (bpf_map_get_next_key(tbl_pid_stats_fd, &key, &next_key) == 0) { + size_t length = sizeof(ebpf_process_stat_t); + if (maps_per_core) + length *= ebpf_nprocs; + while (pids) { key = pids->pid; ebpf_process_stat_t *w = global_process_stats[key]; @@ -1456,7 +1483,7 @@ void collect_data_for_all_processes(int tbl_pid_stats_fd) global_process_stats[key] = w; } - if (bpf_map_lookup_elem(tbl_pid_stats_fd, &key, w)) { + if (bpf_map_lookup_elem(tbl_pid_stats_fd, &key, process_stat_vector)) { // Clean Process structures ebpf_process_stat_release(w); global_process_stats[key] = NULL; @@ -1467,6 +1494,12 @@ void collect_data_for_all_processes(int tbl_pid_stats_fd) continue; } + ebpf_process_apps_accumulator(process_stat_vector, maps_per_core); + + memcpy(w, process_stat_vector, sizeof(ebpf_process_stat_t)); + + memset(process_stat_vector, 0, length); + pids = pids->next; } -- cgit v1.2.3