Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mem_watcher:增加项目的测试程序 #855

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 /home/ubuntu/lmp/eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher -p
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用相对路径比较好一点

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里修改一下,我再合并代码哈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好!

```
切记根据自己的文件所在目录进行修改,如果不知道或者不确定的可以在自己的程序文件下输入`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;
}
Loading