Skip to content

Commit 98ff8da

Browse files
committed
use clock_monitonic_coarse for series reset
Using CLOCK_REALTIME for measuring time to reset the series is expensive (clock_gettime will do a system call). This is called in procstat_u64_series_add_point(), which means every update to the series (likely, on every IO) does this. Replace with CLOCK_MONOTONIC_COARSE. Signed-off-by: Anton Eidelman <anton@lightbitslabs.com>
1 parent bcba013 commit 98ff8da

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/procstat.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ enum {
6161
STATS_ENTRY_FLAG_AGGREGATOR = 1 << 3,
6262
};
6363

64+
#define SERIES_RESET_CLOCK CLOCK_MONOTONIC_COARSE
65+
6466
#define ATTRIBUTES_TIMEOUT_SEC (60.0 * 60)
6567
#define DNAME_INLINE_LEN 32
6668
struct procstat_dynamic_name {
@@ -1015,7 +1017,7 @@ bool is_reset(struct reset_info* reset)
10151017
uint64_t reset_interval, time_since_last_reset;
10161018

10171019
struct timespec cur_time;
1018-
if (clock_gettime(CLOCK_REALTIME, &cur_time) == 0) {
1020+
if (clock_gettime(SERIES_RESET_CLOCK, &cur_time) == 0) {
10191021
time_since_last_reset = cur_time.tv_sec - reset->last_reset_time;
10201022
reset_interval = __atomic_load_n(&reset->reset_interval, __ATOMIC_RELAXED);
10211023
if ((reset_interval) && (time_since_last_reset > reset_interval)) {
@@ -1226,7 +1228,7 @@ int procstat_create_u64_series(struct procstat_context *context, struct procstat
12261228
}
12271229

12281230
struct timespec cur_time;
1229-
if (clock_gettime(CLOCK_REALTIME, &cur_time) == 0) {
1231+
if (clock_gettime(SERIES_RESET_CLOCK, &cur_time) == 0) {
12301232
series->reset.last_reset_time = cur_time.tv_sec;
12311233
} else {
12321234
series->reset.last_reset_time = 0;
@@ -1696,7 +1698,7 @@ int procstat_create_histogram_u32_series(struct procstat_context *context, struc
16961698
}
16971699

16981700
struct timespec cur_time;
1699-
if (clock_gettime(CLOCK_REALTIME, &cur_time) == 0) {
1701+
if (clock_gettime(SERIES_RESET_CLOCK, &cur_time) == 0) {
17001702
series->reset.last_reset_time = cur_time.tv_sec;
17011703
} else {
17021704
series->reset.last_reset_time = 0;

0 commit comments

Comments
 (0)