summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2020-11-26 19:59:00 +0100
committerBenBE <BenBE@geshi.org>2020-11-26 22:58:34 +0100
commit2c27f1d9ab8bb8e4bb2f0242dc2b527f2d984355 (patch)
tree328e14afb1794c2c4ea43492702dffe466d4d984
parent08d6e253011889264d095fdd72e57c2c4c83cfc6 (diff)
Randomly refresh M_LRS calculation, but latest after 2s
-rw-r--r--linux/LinuxProcessList.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 3730c983..80c35699 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -623,7 +623,7 @@ static uint64_t LinuxProcessList_calcLibSize(const char* dirname, const char* na
return total_size / CRT_pageSize;
}
-static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name, bool performLookup) {
+static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name, bool performLookup, unsigned long long now) {
char filename[MAX_NAME + 1];
xSnprintf(filename, sizeof(filename), "%s/%s/statm", dirname, name);
FILE* statmfile = fopen(filename, "r");
@@ -646,13 +646,12 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* di
process->m_lrs = tmp_m_lrs;
} else if (performLookup) {
// Check if we really should recalculate the M_LRS value for this process
- struct timeval tv;
- gettimeofday(&tv, NULL);
- uint64_t timeInMilliSeconds = (uint64_t)tv.tv_sec * 1000ULL + (uint64_t)tv.tv_usec / 1000ULL;
- uint64_t passedTimeInMs = timeInMilliSeconds - process->last_mlrs_calctime;
+ uint64_t passedTimeInMs = now - process->last_mlrs_calctime;
- if(passedTimeInMs > 5000) {
- process->last_mlrs_calctime = timeInMilliSeconds;
+ uint64_t recheck = ((uint64_t)rand()) % 2048;
+
+ if(passedTimeInMs > 2000 || passedTimeInMs > recheck) {
+ process->last_mlrs_calctime = now;
process->m_lrs = LinuxProcessList_calcLibSize(dirname, name);
}
} else {
@@ -1358,7 +1357,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
if (settings->flags & PROCESS_FLAG_IO)
LinuxProcessList_readIoFile(lp, dirname, name, now);
- if (!LinuxProcessList_readStatmFile(lp, dirname, name, !!(settings->flags & PROCESS_FLAG_LINUX_LRS_FIX)))
+ if (!LinuxProcessList_readStatmFile(lp, dirname, name, !!(settings->flags & PROCESS_FLAG_LINUX_LRS_FIX), now))
goto errorReadingProcess;
if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)) {

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