Simplify statm parsing and document unused fields

This commit is contained in:
Christian Göttsche 2020-09-28 12:01:56 +02:00 committed by cgzones
parent 3653ee35c5
commit 954d6c12f5
2 changed files with 15 additions and 20 deletions

View File

@ -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_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_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_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_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", .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, }, [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_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, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },

View File

@ -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) { static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name) {
char filename[MAX_NAME+1]; char filename[MAX_NAME+1];
xSnprintf(filename, MAX_NAME, "%s/%s/statm", dirname, name); xSnprintf(filename, sizeof(filename), "%s/%s/statm", dirname, name);
int fd = open(filename, O_RDONLY); FILE* statmfile = fopen(filename, "r");
if (fd == -1) if (!statmfile)
return false; return false;
char buf[PROC_LINE_LENGTH + 1]; int r = fscanf(statmfile, "%ld %ld %ld %ld %ld %ld %ld",
ssize_t rres = xread(fd, buf, PROC_LINE_LENGTH); &process->super.m_size,
close(fd); &process->super.m_resident,
if (rres < 1) return false; &process->m_share,
&process->m_trs,
char *p = buf; &process->m_lrs,
errno = 0; &process->m_drs,
process->super.m_size = strtol(p, &p, 10); if (*p == ' ') p++; &process->m_dt);
process->super.m_resident = strtol(p, &p, 10); if (*p == ' ') p++; fclose(statmfile);
process->m_share = strtol(p, &p, 10); if (*p == ' ') p++; return r == 7;
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);
} }
static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name, bool haveSmapsRollup) { static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name, bool haveSmapsRollup) {