Skip to content

Commit

Permalink
Mem_watcher:增加项目的测试程序 (#855)
Browse files Browse the repository at this point in the history
* 增加项目的测试程序

* 修改可视化文档

---------

Co-authored-by: qcloud <[email protected]>
  • Loading branch information
Super-Lzzx and qcloud authored Jul 10, 2024
1 parent 4f31f2a commit d8d193c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 lmp/eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher -p
```
切记根据自己的文件所在目录进行修改,如果不知道或者不确定的可以在自己的程序文件下输入`pwd`命令进行查看,如果目录出现错误会失败。

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#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;
}

0 comments on commit d8d193c

Please sign in to comment.