From 213411173ca92fe3efe96d0e38e89562da3f295d 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: Linux: reorder some calls in LinuxProcessList_recurseProcTree() Improve maintainability by reordering calls in LinuxProcessList_recurseProcTree() to group them by side-effect or interdependency. --- linux/LinuxProcessTable.c | 60 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/linux/LinuxProcessTable.c b/linux/LinuxProcessTable.c index 032128c7..9139dbe5 100644 --- a/linux/LinuxProcessTable.c +++ b/linux/LinuxProcessTable.c @@ -1470,9 +1470,6 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar const bool scanMainThread = !hideUserlandThreads && !Process_isKernelThread(proc) && !mainTask; - if (ss->flags & PROCESS_FLAG_IO) - LinuxProcessTable_readIoFile(lp, procFd, scanMainThread); - if (!LinuxProcessTable_readStatmFile(lp, procFd, lhost, mainTask)) goto errorReadingProcess; @@ -1501,21 +1498,6 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar 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) { - LinuxProcessTable_readSmapsFile(lp, procFd, this->haveSmapsRollup); - } - if (pid == 1) { - smaps_flag = !smaps_flag; - } - } else { - lp->m_pss = ((const LinuxProcess*)mainTask)->m_pss; - } - } - char statCommand[MAX_NAME + 1]; unsigned long long int lasttimes = (lp->utime + lp->stime); unsigned long int last_tty_nr = proc->tty_nr; @@ -1531,10 +1513,6 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar proc->tty_name = LinuxProcessTable_updateTtyDevice(this->ttyDrivers, proc->tty_nr); } - if (ss->flags & PROCESS_FLAG_LINUX_IOPRIO) { - LinuxProcess_updateIOPriority(proc); - } - proc->percent_cpu = NAN; /* lhost->period might be 0 after system sleep */ if (lhost->period > 0.0) { @@ -1583,6 +1561,11 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar } } + /* + * Section gathering non-critical information that is independent from + * each other. + */ + /* Gather permitted capabilities (thread-specific data) for non-root process. */ if (proc->st_uid != 0 && proc->elevated_priv != TRI_OFF) { struct __user_cap_header_struct header = { .version = _LINUX_CAPABILITY_VERSION_3, .pid = Process_getPid(proc) }; @@ -1599,6 +1582,27 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar if (ss->flags & PROCESS_FLAG_LINUX_CGROUP) LinuxProcessTable_readCGroupFile(lp, procFd); + 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) { + LinuxProcessTable_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) { + LinuxProcessTable_readIoFile(lp, procFd, scanMainThread); + } + #ifdef HAVE_DELAYACCT if (ss->flags & PROCESS_FLAG_LINUX_DELAYACCT) { LibNl_readDelayAcctData(this, lp); @@ -1609,6 +1613,10 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar LinuxProcessTable_readOomData(lp, procFd, mainTask); } + if (ss->flags & PROCESS_FLAG_LINUX_IOPRIO) { + LinuxProcess_updateIOPriority(proc); + } + if (ss->flags & PROCESS_FLAG_LINUX_SECATTR) { LinuxProcessTable_readSecattrData(lp, procFd, mainTask); } @@ -1635,15 +1643,15 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar } } + /* + * 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->super.updated = true; Compat_openatArgClose(procFd); -- cgit v1.2.3