Skip to content

Commit

Permalink
lib: Added ioloop_global_wait_usecs
Browse files Browse the repository at this point in the history
This is helpful when multiple ioloops aren't used and
io_loop_get_wait_usecs() can't be easily used for all of them.
  • Loading branch information
sirainen authored and GitLab committed Oct 24, 2016
1 parent f83fd83 commit d327ea0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/ioloop.c
Expand Up @@ -15,8 +15,9 @@

time_t ioloop_time = 0;
struct timeval ioloop_timeval;

struct ioloop *current_ioloop = NULL;
uint64_t ioloop_global_wait_usecs = 0;

static ARRAY(io_switch_callback_t *) io_switch_callbacks = ARRAY_INIT;

static void io_loop_initialize_handler(struct ioloop *ioloop)
Expand Down Expand Up @@ -524,8 +525,10 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop)
ioloop->time_moved_callback(ioloop->next_max_time,
ioloop_timeval.tv_sec);
}
ioloop->ioloop_wait_usecs +=
long long diff =
timeval_diff_usecs(&ioloop_timeval, &prev_ioloop_timeval);
ioloop->ioloop_wait_usecs += diff;
ioloop_global_wait_usecs += diff;
}

ioloop_time = ioloop_timeval.tv_sec;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ioloop.h
Expand Up @@ -41,6 +41,8 @@ extern time_t ioloop_time;
extern struct timeval ioloop_timeval;

extern struct ioloop *current_ioloop;
/* Number of microseconds spent on all the ioloops waiting for themselves. */
extern uint64_t ioloop_global_wait_usecs;

/* You can create different handlers for IO_READ and IO_WRITE. IO_READ and
IO_ERROR can't use different handlers (and there's no point anyway).
Expand Down

0 comments on commit d327ea0

Please sign in to comment.