mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
[3.14] gh-132917: Use /proc/self/status for mem usage info. (GH-133544) (gh-133718)
On Linux, use /proc/self/status for mem usage info. Using smaps_rollup is quite a lot slower and
we can get the similar info from /proc/self/status.
(cherry picked from commit 751db4e649)
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
This commit is contained in:
parent
4c6fa89216
commit
8e86f9c3cc
1 changed files with 5 additions and 6 deletions
|
|
@ -1927,8 +1927,7 @@ get_process_mem_usage(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
// Linux, use smaps_rollup (Kernel >= 4.4) for RSS + Swap
|
FILE* fp = fopen("/proc/self/status", "r");
|
||||||
FILE* fp = fopen("/proc/self/smaps_rollup", "r");
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -1938,11 +1937,11 @@ get_process_mem_usage(void)
|
||||||
long long swap_kb = -1;
|
long long swap_kb = -1;
|
||||||
|
|
||||||
while (fgets(line_buffer, sizeof(line_buffer), fp) != NULL) {
|
while (fgets(line_buffer, sizeof(line_buffer), fp) != NULL) {
|
||||||
if (rss_kb == -1 && strncmp(line_buffer, "Rss:", 4) == 0) {
|
if (rss_kb == -1 && strncmp(line_buffer, "VmRSS:", 6) == 0) {
|
||||||
sscanf(line_buffer + 4, "%lld", &rss_kb);
|
sscanf(line_buffer + 6, "%lld", &rss_kb);
|
||||||
}
|
}
|
||||||
else if (swap_kb == -1 && strncmp(line_buffer, "Swap:", 5) == 0) {
|
else if (swap_kb == -1 && strncmp(line_buffer, "VmSwap:", 7) == 0) {
|
||||||
sscanf(line_buffer + 5, "%lld", &swap_kb);
|
sscanf(line_buffer + 7, "%lld", &swap_kb);
|
||||||
}
|
}
|
||||||
if (rss_kb != -1 && swap_kb != -1) {
|
if (rss_kb != -1 && swap_kb != -1) {
|
||||||
break; // Found both
|
break; // Found both
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue