summaryrefslogtreecommitdiffstats
path: root/DateTimeMeter.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2021-03-30 15:55:48 +1100
committerSohaib <sohaib.amhmd@gmail.com>2021-04-05 23:41:07 +0200
commit356488aa53e8c0bedeb7641685d931c8900098c5 (patch)
treec09f2df8264cc4075b72a55409ae261c021cda55 /DateTimeMeter.c
parent421bdeec603b4fb1a4edec0e802c437fbe47fca0 (diff)
Request the realtime and monotonic clock times once per sample
Refactor the sample time code to make one call to gettimeofday (aka the realtime clock in clock_gettime, when available) and one to the monotonic clock. Stores each in more appropriately named ProcessList fields for ready access when needed. Every platform gets the opportunity to provide their own clock code, and the existing Mac OS X specific code is moved below darwin instead of in Compat. A couple of leftover time(2) calls are converted to use these ProcessList fields as well, instead of yet again sampling the system clock. Related to https://github.com/htop-dev/htop/pull/574
Diffstat (limited to 'DateTimeMeter.c')
-rw-r--r--DateTimeMeter.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/DateTimeMeter.c b/DateTimeMeter.c
index 3fb515b5..588b9fbe 100644
--- a/DateTimeMeter.c
+++ b/DateTimeMeter.c
@@ -20,9 +20,10 @@ static const int DateTimeMeter_attributes[] = {
};
static void DateTimeMeter_updateValues(Meter* this) {
- time_t t = time(NULL);
+ const ProcessList* pl = this->pl;
+
struct tm result;
- const struct tm* lt = localtime_r(&t, &result);
+ const struct tm* lt = localtime_r(&pl->realtime.tv_sec, &result);
int year = lt->tm_year + 1900;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
this->total = 366;

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