sysSentry/ebpf-fix-iodump-warning.patch
2024-10-16 22:05:35 +08:00

78 lines
2.8 KiB
Diff

From cd7b99efa20bc76cebffefbd711b0e0b5cbb5472 Mon Sep 17 00:00:00 2001
From: zhangnan <zhangnan134@huawei.com>
Date: Wed, 16 Oct 2024 22:08:42 +0800
Subject: [PATCH] ebpf fix collect iodump
---
src/c/ebpf_collector/ebpf_collector.c | 27 +++++++++++-------------
src/python/sentryCollector/collect_io.py | 2 +-
2 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/c/ebpf_collector/ebpf_collector.c b/src/c/ebpf_collector/ebpf_collector.c
index 0885a5f..af452c8 100644
--- a/src/c/ebpf_collector/ebpf_collector.c
+++ b/src/c/ebpf_collector/ebpf_collector.c
@@ -119,23 +119,19 @@ char* find_device_name(dev_t dev) {
static void update_io_dump(struct bpf_map *map_res, int *io_dump, int *map_size, char *stage) {
struct time_range_io_count time_count;
- u32 io_dump_key = 0, io_dump_next_key = 0;
+ u32 io_dump_key = 0;
struct sysinfo info;
sysinfo(&info);
-
- while (bpf_map_get_next_key(map_res, &io_dump_key, &io_dump_next_key) == 0) {
- int err = bpf_map_lookup_elem(map_res, &io_dump_next_key, &time_count);
- if (err < 0) {
- fprintf(stderr, "failed to lookup %s io dump: %d\n", stage, err);
- break;
- }
- if (io_dump_key == io_dump_next_key) {
- break;
+ int count_time = 150;
+ u32 curr_time = info.uptime;
+ while (count_time >= 0) {
+ io_dump_key = curr_time - count_time;
+ int err = bpf_map_lookup_elem(map_res, &io_dump_key, &time_count);
+ if (err < 0) {
+ count_time -= 1;
+ continue;
}
-
- io_dump_key = io_dump_next_key;
-
- if ((info.uptime - io_dump_key) >= 2) {
+ if ((curr_time - io_dump_key) >= 2) {
int isempty = 1;
for (int key = 0; key < map_size; key++) {
if (time_count.count[key] > 0) {
@@ -143,10 +139,11 @@ static void update_io_dump(struct bpf_map *map_res, int *io_dump, int *map_size,
isempty = 0;
}
}
- if (isempty || (info.uptime - io_dump_key) > IO_DUMP_THRESHOLD) {
+ if (isempty || (curr_time - io_dump_key) > IO_DUMP_THRESHOLD) {
bpf_map_delete_elem(map_res, &io_dump_key);
}
}
+ count_time -= 1;
}
}
diff --git a/src/python/sentryCollector/collect_io.py b/src/python/sentryCollector/collect_io.py
index 9c6bbc9..8a82eab 100644
--- a/src/python/sentryCollector/collect_io.py
+++ b/src/python/sentryCollector/collect_io.py
@@ -387,7 +387,7 @@ class CollectIo():
curr_io_dump_count: int,
prev_io_dump_count: int
) -> Union[int, float]:
- io_dump_count = curr_io_dump_count - prev_io_dump_count
+ io_dump_count = curr_io_dump_count
if io_dump_count <= 0:
return 0
value = io_dump_count
--
2.33.0