Skip to content

Commit

Permalink
imap: Include sync timing information in tagged command replies.
Browse files Browse the repository at this point in the history
Show it only when it's larger than 0 to avoid unnecessary output.
  • Loading branch information
sirainen committed May 19, 2016
1 parent 9b496d9 commit f008446
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/imap/imap-client.c
Expand Up @@ -480,6 +480,7 @@ client_cmd_append_timing_stats(struct client_command_context *cmd,
{
unsigned int msecs_in_cmd, msecs_in_ioloop;
uint64_t ioloop_wait_usecs;
unsigned int msecs_since_cmd;

if (cmd->start_time.tv_sec == 0)
return;
Expand All @@ -488,12 +489,19 @@ client_cmd_append_timing_stats(struct client_command_context *cmd,
msecs_in_cmd = (cmd->running_usecs + 999) / 1000;
msecs_in_ioloop = (ioloop_wait_usecs -
cmd->start_ioloop_wait_usecs + 999) / 1000;
msecs_since_cmd = timeval_diff_msecs(&ioloop_timeval,
&cmd->last_run_timeval);

if (str_data(str)[str_len(str)-1] == '.')
str_truncate(str, str_len(str)-1);
str_printfa(str, " (%d.%03d + %d.%03d secs).",
str_printfa(str, " (%d.%03d + %d.%03d ",
msecs_in_cmd / 1000, msecs_in_cmd % 1000,
msecs_in_ioloop / 1000, msecs_in_ioloop % 1000);
if (msecs_since_cmd > 0) {
str_printfa(str, "+ %d.%03d ",
msecs_since_cmd / 1000, msecs_since_cmd % 1000);
}
str_append(str, "secs).");
}

void client_send_tagline(struct client_command_context *cmd, const char *data)
Expand Down Expand Up @@ -721,6 +729,7 @@ struct client_command_context *client_command_alloc(struct client *client)
cmd->client = client;
cmd->pool = client->command_pool;
cmd->start_time = ioloop_timeval;
cmd->last_run_timeval = ioloop_timeval;
cmd->start_ioloop_wait_usecs = io_loop_get_wait_usecs(current_ioloop);
p_array_init(&cmd->module_contexts, cmd->pool, 5);

Expand Down
3 changes: 3 additions & 0 deletions src/imap/imap-client.h
Expand Up @@ -79,6 +79,9 @@ struct client_command_context {
/* time when command handling was started - typically this is after
reading all the parameters. */
struct timeval start_time;
/* time when command handling was last finished. this is before
mailbox syncing is done. */
struct timeval last_run_timeval;
/* io_loop_get_wait_usecs()'s value when the command was started */
uint64_t start_ioloop_wait_usecs;
/* how many usecs this command itself has spent running */
Expand Down
1 change: 1 addition & 0 deletions src/imap/imap-sync.c
Expand Up @@ -762,6 +762,7 @@ bool cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags,
if (cmd->cancel)
return TRUE;

cmd->last_run_timeval = ioloop_timeval;
if (client->mailbox == NULL) {
/* no mailbox selected, no point in delaying the sync */
if (tagline != NULL)
Expand Down

0 comments on commit f008446

Please sign in to comment.