From 87876010f0930d5260bfabbc1518b46e583412cd Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Thu, 17 Feb 2022 13:07:02 -0300 Subject: [PATCH] PG-311: Fix user/system cpu time zero values. Some queries were taking less than one millisecond to execute, since we store cpu time values in milliseconds in a float, a value of 0.1 (a tenth of millisecond) cast to int64 would truncate the fractional part and the result would be zero. To fix the problem, the cast to (int64) when calculating the average cpu time was removed, when updating entry statistics in pgss_update_entry() function. --- pg_stat_monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 379c3d6..f8ceab3 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -1359,8 +1359,8 @@ pgss_update_entry(pgssEntry *entry, } if (sys_info) { - e->counters.sysinfo.utime += (int64)(sys_info->utime - e->counters.sysinfo.utime)/e->counters.calls.calls; - e->counters.sysinfo.stime += (int64)(sys_info->stime - e->counters.sysinfo.stime)/e->counters.calls.calls; + e->counters.sysinfo.utime += (sys_info->utime - e->counters.sysinfo.utime)/e->counters.calls.calls; + e->counters.sysinfo.stime += (sys_info->stime - e->counters.sysinfo.stime)/e->counters.calls.calls; } if (walusage) {