Try#185,改进的watcher,使用macOS与Linux中的size命令进行静态内存分析。#211
Closed
tofucurd wants to merge 14 commits intoProject-LemonLime:masterfrom
Closed
Try#185,改进的watcher,使用macOS与Linux中的size命令进行静态内存分析。#211tofucurd wants to merge 14 commits intoProject-LemonLime:masterfrom
size命令进行静态内存分析。#211tofucurd wants to merge 14 commits intoProject-LemonLime:masterfrom
Conversation
size in macOS and Linux to analyze static memory usage before running.size命令进行静态内存分析。
size命令进行静态内存分析。size命令进行静态内存分析。
Author
|
Windows没有环境实现。 |
alphagocc
reviewed
Jun 19, 2023
unix/watcher_macos.cpp
Outdated
| // Find the line containing the relevant sections | ||
| if (std::isdigit(buffer[0])) { | ||
| // Parse the sizes from the line | ||
| size_t size__TEXT, size__DATA; |
Author
There was a problem hiding this comment.
因为size输出就是__TEXT __DATA, 是可执行文件的文件头标识。
unix/watcher_linux.cpp
Outdated
|
|
||
| int calculateStaticMemoryUsage(const char* executableName) { | ||
| char command[256]; | ||
| snprintf(command, sizeof(command), "size %s", executableName); |
Author
There was a problem hiding this comment.
改成了sizeof(executableName) + 128, macos下最长为1024, linux下最长为4096
linux:
#define PATH_MAX 4096macos:
#define MAX_INPUT 1024 /* max bytes in terminal input */
Dust1404
suggested changes
Jul 28, 2023
unix/watcher_linux.cpp
Outdated
| int calculateStaticMemoryUsage(const char* executableName) { | ||
| char command[256]; | ||
| snprintf(command, sizeof(command), "size %s", executableName); | ||
| char command[sizeof(executableName) + 128]; |
Member
There was a problem hiding this comment.
这里 sizeof(executableName) 是 8,是指针的大小,不是 executableName 的长度。或许可以使用 PATH_MAX,是系统最长的路径长度。
Dust1404
reviewed
Jul 28, 2023
Member
Dust1404
left a comment
There was a problem hiding this comment.
hard code 是不建议的做法。另外注意一下缩进的统一。
Author
|
fix with using |
Dust1404
reviewed
Jul 28, 2023
Member
Dust1404
left a comment
There was a problem hiding this comment.
总体来说很有启发性也是可行的检查方法。
但是直接调用 command line tools,然后 parse 输出结果有很多问题。比如不同系统版本不同的 size 命令输出格式是否统一?未来是否会更改?同时 parse 过程也有一些很 tricky 的点,并不能保证对所有场景都一直有效。
直接去解析 elf 文件自己统计可能是更好的做法。
Comment on lines
+36
to
+41
| char buffer[256]; | ||
| size_t staticMemoryUsage = 0; | ||
|
|
||
| while (fgets(buffer, sizeof(buffer), output) != NULL) { | ||
| // Find the line containing the relevant sections | ||
| if (buffer[3] >= '0' && buffer[3] <= '9') { |
Member
There was a problem hiding this comment.
[256] 是否足够?buffer[3] 是否适合所有情况?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
在我的机子上经过验证,#185 #169 #142中macOS与Linux解决.
在两个watcher源码内加入使用
size命令的片段,并在fork()之前就判定静态内存,实测可以防止以上issue的问题出现。我的机子: