From 7ea8cf1ffa1ed6c76f7c0a92f588f266063b8ba3 Mon Sep 17 00:00:00 2001 From: qcloud Date: Fri, 5 Jul 2024 17:31:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/mem_watcher_vision.md | 2 +- .../mem_watcher/test/sysstat_test/Makefile | 11 +++++ .../test/sysstat_test/sysstat_test.c | 49 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/Makefile create mode 100644 eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/sysstat_test.c diff --git a/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md b/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md index 4226d65fe..02543b08a 100644 --- a/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md +++ b/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md @@ -17,7 +17,7 @@ - 执行`make start_service`指令,配置下载docker镜像并启动grafana和prometheus服务 - 执行如下指令开始采集数据以及相关处理: ```c - ./data-visual collect /home/ubuntu/lmp/eBPF_Supermarket/Memory_Subsystem/mem_watcher -p + ./data-visual collect /home/ubuntu/lmp/eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher -p ``` 切记根据自己的文件所在目录进行修改,如果不知道或者不确定的可以在自己的程序文件下输入`pwd`命令进行查看,如果目录出现错误会失败。 diff --git a/eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/Makefile b/eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/Makefile new file mode 100644 index 000000000..9e3fbbded --- /dev/null +++ b/eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/Makefile @@ -0,0 +1,11 @@ +CC = gcc +CFLAGS = -Wall -O2 +TARGET = sysstat_test + +all: $(TARGET) + +$(TARGET): sysstat_test.c + $(CC) $(CFLAGS) -o $(TARGET) sysstat_test.c + +clean: + rm -f $(TARGET) diff --git a/eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/sysstat_test.c b/eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/sysstat_test.c new file mode 100644 index 000000000..c0e7e64b5 --- /dev/null +++ b/eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/sysstat_test.c @@ -0,0 +1,49 @@ +#include +#include +#include + +#define ALLOC_SIZE_SMALL 512*1024*1024 // 分配 512 MB 内存 +#define ALLOC_SIZE_LARGE 1024*1024*1024 // 分配 1 GB 内存 + +void allocate_memory(size_t size) { + void *memory; + + printf("Allocating %lu MB memory...\n", size / (1024*1024)); + memory = malloc(size); + if (!memory) { + perror("Failed to allocate memory"); + return; + } + + // 填充内存以确保页面被分配 + printf("Filling memory...\n"); + for (size_t i = 0; i < size; ++i) { + ((char*)memory)[i] = (char)i; + } + + printf("Freeing memory...\n"); + free(memory); + + // 给内核更多时间处理回收 + printf("Sleeping for 10 seconds...\n"); + sleep(10); // 增加等待时间到 10 秒 + + printf("Memory management operation finished.\n"); +} + +int main() { + printf("Starting memory management demo...\n"); + + // 分配和释放多次小块内存 + for (int i = 0; i < 5; ++i) { + allocate_memory(ALLOC_SIZE_SMALL); + } + + // 分配和释放多次大块内存 + for (int i = 0; i < 5; ++i) { + allocate_memory(ALLOC_SIZE_LARGE); + } + + printf("Memory management demo finished.\n"); + return 0; +} From 0e74f74aa8b6e7ba8ff0d3e16e4cfc0ae66cd021 Mon Sep 17 00:00:00 2001 From: qcloud Date: Mon, 8 Jul 2024 15:56:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md b/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md index 02543b08a..b64ce6a24 100644 --- a/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md +++ b/eBPF_Supermarket/Memory_Subsystem/docs/mem_watcher_vision.md @@ -17,7 +17,7 @@ - 执行`make start_service`指令,配置下载docker镜像并启动grafana和prometheus服务 - 执行如下指令开始采集数据以及相关处理: ```c - ./data-visual collect /home/ubuntu/lmp/eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher -p + ./data-visual collect lmp/eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher -p ``` 切记根据自己的文件所在目录进行修改,如果不知道或者不确定的可以在自己的程序文件下输入`pwd`命令进行查看,如果目录出现错误会失败。