summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-09-28 12:01:56 +0200
committercgzones <cgzones@googlemail.com>2020-10-06 18:59:02 +0200
commit954d6c12f58724773596b1bd669683ce59cae2c5 (patch)
tree1c744beac25e5d6a79f62a52c83bbaf357172c3b
parent3653ee35c572ccca09f8f080b78a1ad7d26cbb24 (diff)
Simplify statm parsing and document unused fields
-rw-r--r--linux/LinuxProcess.c4
-rw-r--r--linux/LinuxProcessList.c31
2 files changed, 15 insertions, 20 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index 8fb26e01..373c9ad8 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -67,8 +67,8 @@ ProcessFieldData Process_fields[] = {
[M_SHARE] = { .name = "M_SHARE", .title = " SHR ", .description = "Size of the process's shared pages", .flags = 0, },
[M_TRS] = { .name = "M_TRS", .title = " CODE ", .description = "Size of the text segment of the process", .flags = 0, },
[M_DRS] = { .name = "M_DRS", .title = " DATA ", .description = "Size of the data segment plus stack usage of the process", .flags = 0, },
- [M_LRS] = { .name = "M_LRS", .title = " LIB ", .description = "The library size of the process", .flags = 0, },
- [M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process", .flags = 0, },
+ [M_LRS] = { .name = "M_LRS", .title = " LIB ", .description = "The library size of the process (unused since Linux 2.6; always 0)", .flags = 0, },
+ [M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process (unused since Linux 2.6; always 0)", .flags = 0, },
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index c02bca88..2317e1c8 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -406,25 +406,20 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name) {
char filename[MAX_NAME+1];
- xSnprintf(filename, MAX_NAME, "%s/%s/statm", dirname, name);
- int fd = open(filename, O_RDONLY);
- if (fd == -1)
+ xSnprintf(filename, sizeof(filename), "%s/%s/statm", dirname, name);
+ FILE* statmfile = fopen(filename, "r");
+ if (!statmfile)
return false;
- char buf[PROC_LINE_LENGTH + 1];
- ssize_t rres = xread(fd, buf, PROC_LINE_LENGTH);
- close(fd);
- if (rres < 1) return false;
-
- char *p = buf;
- errno = 0;
- process->super.m_size = strtol(p, &p, 10); if (*p == ' ') p++;
- process->super.m_resident = strtol(p, &p, 10); if (*p == ' ') p++;
- process->m_share = strtol(p, &p, 10); if (*p == ' ') p++;
- process->m_trs = strtol(p, &p, 10); if (*p == ' ') p++;
- process->m_lrs = strtol(p, &p, 10); if (*p == ' ') p++;
- process->m_drs = strtol(p, &p, 10); if (*p == ' ') p++;
- process->m_dt = strtol(p, &p, 10);
- return (errno == 0);
+ int r = fscanf(statmfile, "%ld %ld %ld %ld %ld %ld %ld",
+ &process->super.m_size,
+ &process->super.m_resident,
+ &process->m_share,
+ &process->m_trs,
+ &process->m_lrs,
+ &process->m_drs,
+ &process->m_dt);
+ fclose(statmfile);
+ return r == 7;
}
static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name, bool haveSmapsRollup) {