-
Notifications
You must be signed in to change notification settings - Fork 173
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里使用相对路径比较好一点
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里修改一下,我再合并代码哈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好!