mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Simplify statm parsing and document unused fields
This commit is contained in:
parent
3653ee35c5
commit
954d6c12f5
@ -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, },
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user