Skip to content

Commit

Permalink
daemon/defer: update uv time after longer operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Ondráček committed Jan 9, 2025
1 parent d5231f0 commit a47ca64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions daemon/defer.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct defer {
};
struct defer *defer = NULL;
bool defer_initialized = false;
uint64_t defer_uvtime_stamp = 0;
struct mmapped defer_mmapped = {0};

defer_sample_state_t defer_sample_state = {
Expand Down
9 changes: 7 additions & 2 deletions daemon/defer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern defer_sample_state_t defer_sample_state;

extern struct defer *defer; /// skip sampling/deferring if NULL
extern bool defer_initialized; /// defer_init was called, possibly keeping defer disabled

extern uint64_t defer_uvtime_stamp; /// stamp of the last uv time update

// TODO: reconsider `static inline` cases below

Expand All @@ -39,7 +39,12 @@ static inline uint64_t defer_get_stamp(void)
{
struct timespec now_ts = {0};
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now_ts);
return now_ts.tv_nsec + 1000*1000*1000 * (uint64_t)now_ts.tv_sec;
uint64_t stamp = now_ts.tv_nsec + 1000*1000*1000 * (uint64_t)now_ts.tv_sec;
if (defer_uvtime_stamp + 1000*1000 < stamp) {
defer_uvtime_stamp = stamp;
uv_update_time(uv_default_loop());
}
return stamp;
}

/// Annotate the work currently being accounted by an IP address.
Expand Down

0 comments on commit a47ca64

Please sign in to comment.