diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2022-06-07 11:28:04 +0100 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-06-07 17:39:37 +0100 |
commit | adfcb5304d44c7ad582e4aaa6e3ea42adeb543ed (patch) | |
tree | dfc3c37d8b1bce278d76b4e2cb3c968b5451c459 | |
parent | 5a3fdcfd615b502f123bb31f42d22577d44748ac (diff) | |
download | haskell-wip/get_r_usage.tar.gz |
getProcessCPUTime: Fix the getrusage fallback to account for system CPU timewip/get_r_usage
clock_gettime reports the combined total or user AND system time so in
order to replicate it with getrusage we need to add both system and user
time together.
See https://stackoverflow.com/questions/7622371/getrusage-vs-clock-gettime
Some sample measurements when building Cabal with this patch
t1: rusage
t2: clock_gettime
t1: 62347518000; t2: 62347520873
t1: 62395687000; t2: 62395690171
t1: 62432435000; t2: 62432437313
t1: 62478489000; t2: 62478492465
t1: 62514990000; t2: 62514992534
t1: 62515479000; t2: 62515480327
t1: 62515485000; t2: 62515486344
Fixes #21656
-rw-r--r-- | rts/posix/GetTime.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index b2e522facc..7588236ce5 100644 --- a/rts/posix/GetTime.c +++ b/rts/posix/GetTime.c @@ -138,7 +138,8 @@ Time getProcessCPUTime(void) { struct rusage t; getrusage(RUSAGE_SELF, &t); - return SecondsToTime(t.ru_utime.tv_sec) + USToTime(t.ru_utime.tv_usec); + return SecondsToTime(t.ru_utime.tv_sec + t.ru_stime.tv_sec) + + USToTime(t.ru_utime.tv_usec + t.ru_stime.tv_usec); } } |