-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 增加项目的测试程序 * 修改可视化文档 --------- Co-authored-by: qcloud <[email protected]>
- Loading branch information
1 parent
4f31f2a
commit d8d193c
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
49 changes: 49 additions & 0 deletions
49
eBPF_Supermarket/Memory_Subsystem/mem_watcher/test/sysstat_test/sysstat_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |