From 5b3e444a4f10bc0c41a03196921ebbc2a18f7793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 17 Apr 2023 19:04:09 +0200 Subject: [PATCH] Linux: reorder some calls in LinuxProcessList_recurseProcTree() Improve maintainability by reordering calls in LinuxProcessList_recurseProcTree() to group them by side-effect or interdependency. --- linux/LinuxProcessList.c | 57 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 83112b702..1b48e46dd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1636,11 +1636,6 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ continue; } - const bool scanMainThread = !hideUserlandThreads && !Process_isKernelThread(proc) && !mainTask; - - if (ss->flags & PROCESS_FLAG_IO) - LinuxProcessList_readIoFile(lp, procFd, scanMainThread, pl->realtimeMs); - if (!LinuxProcessList_readStatmFile(lp, procFd, mainTask)) goto errorReadingProcess; @@ -1669,20 +1664,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ proc->mergedCommand.lastUpdate = 0; } - if ((ss->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)) { - if (!mainTask) { - // Read smaps file of each process only every second pass to improve performance - static int smaps_flag = 0; - if ((pid & 1) == smaps_flag) { - LinuxProcessList_readSmapsFile(lp, procFd, this->haveSmapsRollup); - } - if (pid == 1) { - smaps_flag = !smaps_flag; - } - } else { - lp->m_pss = ((const LinuxProcess*)mainTask)->m_pss; - } - } + const bool scanMainThread = !hideUserlandThreads && !Process_isKernelThread(proc) && !mainTask; char statCommand[MAX_NAME + 1]; unsigned long long int lasttimes = (lp->utime + lp->stime); @@ -1699,10 +1681,6 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ proc->tty_name = LinuxProcessList_updateTtyDevice(this->ttyDrivers, proc->tty_nr); } - if (ss->flags & PROCESS_FLAG_LINUX_IOPRIO) { - LinuxProcess_updateIOPriority(lp); - } - /* * - period might be 0 after system sleep * - stime/utime might drop when switching to scan the main thread instead of the whole process @@ -1776,6 +1754,27 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ } } + if ((ss->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)) { + if (!mainTask) { + // Read smaps file of each process only every second pass to improve performance + static int smaps_flag = 0; + if ((pid & 1) == smaps_flag) { + LinuxProcessList_readSmapsFile(lp, procFd, this->haveSmapsRollup); + } + if (pid == 1) { + smaps_flag = !smaps_flag; + } + } else { + lp->m_pss = ((const LinuxProcess*)mainTask)->m_pss; + lp->m_swap = ((const LinuxProcess*)mainTask)->m_swap; + lp->m_psswp = ((const LinuxProcess*)mainTask)->m_psswp; + } + } + + if (ss->flags & PROCESS_FLAG_IO) { + LinuxProcessList_readIoFile(lp, procFd, scanMainThread, pl->realtimeMs); + } + #ifdef HAVE_DELAYACCT if (ss->flags & PROCESS_FLAG_LINUX_DELAYACCT) { LinuxProcessList_readDelayAcctData(this, lp); @@ -1786,6 +1785,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ LinuxProcessList_readOomData(lp, procFd, mainTask); } + if (ss->flags & PROCESS_FLAG_LINUX_IOPRIO) { + LinuxProcess_updateIOPriority(lp); + } + if (ss->flags & PROCESS_FLAG_LINUX_SECATTR) { LinuxProcessList_readSecattrData(lp, procFd, mainTask); } @@ -1804,15 +1807,15 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ } #endif + /* + * Final section after all data has been gathered + */ + if (!proc->cmdline && statCommand[0] && (proc->state == ZOMBIE || Process_isKernelThread(proc) || settings->showThreadNames)) { Process_updateCmdline(proc, statCommand, 0, strlen(statCommand)); } - /* - * Final section after all data has been gathered - */ - proc->updated = true; Compat_openatArgClose(procFd);