mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
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.
This commit is contained in:
@ -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) {
|
||||
|
||||
|
Reference in New Issue
Block a user