summaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2020-12-10 11:57:48 +1100
committerNathan Scott <nathans@redhat.com>2020-12-10 11:57:48 +1100
commit75e9f9a8d92cda6ae8b161f1bf662597ac67c0f2 (patch)
tree397da395644c86f292d26bfe9226cfb5084c9735 /linux
parentdb5687a3556385521c42ee729aaa75a282b47c8c (diff)
Cull the definitions of pageSize and pageSizeKB from CRT.c
By storing the per-process m_resident and m_virt values in the form htop wants to display them in (KB, not pages), we no longer need to have definitions of pageSize and pageSizeKB in the common CRT code. These variables were never really CRT (i.e. display) related in the first place. It turns out the darwin platform code doesn't need to use these at all (the process values are extracted from the kernel in bytes not pages) and the other platforms can each use their own local pagesize variables, in more appropriate locations. Some platforms were actually already doing this, so this change is removing duplication of logic and variables there.
Diffstat (limited to 'linux')
-rw-r--r--linux/LinuxProcess.c12
-rw-r--r--linux/LinuxProcess.h4
-rw-r--r--linux/LinuxProcessList.c13
3 files changed, 22 insertions, 7 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index ef155af8..44c4b2d9 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -25,6 +25,8 @@ in the source distribution for its full text.
/* semi-global */
long long btime;
+int pageSize;
+int pageSizeKB;
/* Used to identify kernel threads in Comm and Exe columns */
static const char *const kthreadID = "KTHREAD";
@@ -632,19 +634,19 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
}
case CMINFLT: Process_colorNumber(str, lp->cminflt, coloring); return;
case CMAJFLT: Process_colorNumber(str, lp->cmajflt, coloring); return;
- case M_DRS: Process_humanNumber(str, lp->m_drs * CRT_pageSizeKB, coloring); return;
- case M_DT: Process_humanNumber(str, lp->m_dt * CRT_pageSizeKB, coloring); return;
+ case M_DRS: Process_humanNumber(str, lp->m_drs * pageSizeKB, coloring); return;
+ case M_DT: Process_humanNumber(str, lp->m_dt * pageSizeKB, coloring); return;
case M_LRS:
if (lp->m_lrs) {
- Process_humanNumber(str, lp->m_lrs * CRT_pageSizeKB, coloring);
+ Process_humanNumber(str, lp->m_lrs * pageSizeKB, coloring);
return;
}
attr = CRT_colors[PROCESS_SHADOW];
xSnprintf(buffer, n, " N/A ");
break;
- case M_TRS: Process_humanNumber(str, lp->m_trs * CRT_pageSizeKB, coloring); return;
- case M_SHARE: Process_humanNumber(str, lp->m_share * CRT_pageSizeKB, coloring); return;
+ case M_TRS: Process_humanNumber(str, lp->m_trs * pageSizeKB, coloring); return;
+ case M_SHARE: Process_humanNumber(str, lp->m_share * pageSizeKB, coloring); return;
case M_PSS: Process_humanNumber(str, lp->m_pss, coloring); return;
case M_SWAP: Process_humanNumber(str, lp->m_swap, coloring); return;
case M_PSSWP: Process_humanNumber(str, lp->m_psswp, coloring); return;
diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h
index ad396fb2..3c1e7e75 100644
--- a/linux/LinuxProcess.h
+++ b/linux/LinuxProcess.h
@@ -193,6 +193,10 @@ static inline bool Process_isUserlandThread(const Process* this) {
extern long long btime;
+extern int pageSize;
+
+extern int pageSizeKB;
+
extern ProcessFieldData Process_fields[];
extern ProcessPidColumn Process_pidColumns[];
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index b9ba247f..e228220f 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -202,6 +202,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
LinuxProcessList_initNetlinkSocket(this);
#endif
+ // Initialize page size
+ pageSize = sysconf(_SC_PAGESIZE);
+ if (pageSize == -1)
+ CRT_fatalError("Cannot get pagesize by sysconf(_SC_PAGESIZE)");
+ pageSizeKB = pageSize / ONE_K;
+
// Check for /proc/*/smaps_rollup availability (improves smaps parsing speed, Linux 4.14+)
FILE* file = fopen(PROCDIR "/self/smaps_rollup", "r");
if (file != NULL) {
@@ -573,7 +579,7 @@ static uint64_t LinuxProcessList_calcLibSize(openat_arg_t procFd) {
Hashtable_delete(ht);
- return total_size / CRT_pageSize;
+ return total_size / pageSize;
}
static bool LinuxProcessList_readStatmFile(LinuxProcess* process, openat_arg_t procFd, bool performLookup, unsigned long long now) {
@@ -593,6 +599,9 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, openat_arg_t p
fclose(statmfile);
if (r == 7) {
+ process->super.m_virt *= pageSizeKB;
+ process->super.m_resident *= pageSizeKB;
+
if (tmp_m_lrs) {
process->m_lrs = tmp_m_lrs;
} else if (performLookup) {
@@ -1365,7 +1374,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
/* period might be 0 after system sleep */
float percent_cpu = (period < 1e-6) ? 0.0f : ((lp->utime + lp->stime - lasttimes) / period * 100.0);
proc->percent_cpu = CLAMP(percent_cpu, 0.0f, cpus * 100.0f);
- proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0;
+ proc->percent_mem = proc->m_resident / (double)(pl->totalMem) * 100.0;
if (!preExisting) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy