From 567b56c2d6a1063cad997c956f3ed1d9d735f14e Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 16 Feb 2017 20:14:55 +0200 Subject: [PATCH] imap: Code cleanup - move command stats to struct client_command_stats --- src/imap/imap-client.c | 25 +++++++++++++------------ src/imap/imap-client.h | 32 ++++++++++++++++++-------------- src/imap/imap-commands.c | 8 ++++---- src/imap/imap-sync.c | 2 +- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 42c98d228a..d013fcc909 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -290,10 +290,10 @@ static const char *client_get_commands_status(struct client *client) str_append(str, cmd->name); if (cmd->next != NULL) str_append_c(str, ','); - running_usecs += cmd->running_usecs; - lock_wait_usecs += cmd->lock_wait_usecs; - bytes_in += cmd->bytes_in; - bytes_out += cmd->bytes_out; + running_usecs += cmd->stats.running_usecs; + lock_wait_usecs += cmd->stats.lock_wait_usecs; + bytes_in += cmd->stats.bytes_in; + bytes_out += cmd->stats.bytes_out; last_cmd = cmd; } if (last_cmd == NULL) @@ -311,7 +311,7 @@ static const char *client_get_commands_status(struct client *client) ioloop_wait_usecs = io_loop_get_wait_usecs(current_ioloop); msecs_in_ioloop = (ioloop_wait_usecs - - last_cmd->start_ioloop_wait_usecs + 999) / 1000; + last_cmd->stats.start_ioloop_wait_usecs + 999) / 1000; str_printfa(str, " running for %d.%03d + waiting %s for %d.%03d secs", (int)((running_usecs+999)/1000 / 1000), (int)((running_usecs+999)/1000 % 1000), cond_str, @@ -485,15 +485,15 @@ client_cmd_append_timing_stats(struct client_command_context *cmd, uint64_t ioloop_wait_usecs; unsigned int msecs_since_cmd; - if (cmd->start_time.tv_sec == 0) + if (cmd->stats.start_time.tv_sec == 0) return; ioloop_wait_usecs = io_loop_get_wait_usecs(current_ioloop); - msecs_in_cmd = (cmd->running_usecs + 999) / 1000; + msecs_in_cmd = (cmd->stats.running_usecs + 999) / 1000; msecs_in_ioloop = (ioloop_wait_usecs - - cmd->start_ioloop_wait_usecs + 999) / 1000; + cmd->stats.start_ioloop_wait_usecs + 999) / 1000; msecs_since_cmd = timeval_diff_msecs(&ioloop_timeval, - &cmd->last_run_timeval); + &cmd->stats.last_run_timeval); if (str_data(str)[str_len(str)-1] == '.') str_truncate(str, str_len(str)-1); @@ -736,9 +736,10 @@ struct client_command_context *client_command_alloc(struct client *client) cmd = p_new(client->command_pool, struct client_command_context, 1); 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); + cmd->stats.start_time = ioloop_timeval; + cmd->stats.last_run_timeval = ioloop_timeval; + cmd->stats.start_ioloop_wait_usecs = + io_loop_get_wait_usecs(current_ioloop); p_array_init(&cmd->module_contexts, cmd->pool, 5); DLLIST_PREPEND(&client->command_queue, cmd); diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index 9b9dd54585..bdc0468a38 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -52,6 +52,23 @@ enum client_command_state { CLIENT_COMMAND_STATE_DONE }; +struct client_command_stats { + /* 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 */ + uint64_t running_usecs; + /* how many usecs this command itself has spent waiting for locks */ + uint64_t lock_wait_usecs; + /* how many bytes of client input/output command has used */ + uint64_t bytes_in, bytes_out; +}; + struct client_command_context { struct client_command_context *prev, *next; struct client *client; @@ -76,20 +93,7 @@ struct client_command_context { struct imap_parser *parser; enum client_command_state state; - /* 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 */ - uint64_t running_usecs; - /* how many usecs this command itself has spent waiting for locks */ - uint64_t lock_wait_usecs; - /* how many bytes of client input/output command has used */ - uint64_t bytes_in, bytes_out; + struct client_command_stats stats; struct client_sync_context *sync; diff --git a/src/imap/imap-commands.c b/src/imap/imap-commands.c index d41f363d0a..70df94adcb 100644 --- a/src/imap/imap-commands.c +++ b/src/imap/imap-commands.c @@ -186,13 +186,13 @@ bool command_exec(struct client_command_context *cmd) finished = TRUE; io_loop_time_refresh(); - cmd->running_usecs += + cmd->stats.running_usecs += timeval_diff_usecs(&ioloop_timeval, &cmd_start_timeval); - cmd->lock_wait_usecs += + cmd->stats.lock_wait_usecs += file_lock_wait_get_total_usecs() - cmd_start_lock_waits; - cmd->bytes_in += i_stream_get_absolute_offset(cmd->client->input) - + cmd->stats.bytes_in += i_stream_get_absolute_offset(cmd->client->input) - cmd_start_bytes_in; - cmd->bytes_out += cmd->client->output->offset - cmd_start_bytes_out; + cmd->stats.bytes_out += cmd->client->output->offset - cmd_start_bytes_out; return finished; } diff --git a/src/imap/imap-sync.c b/src/imap/imap-sync.c index eb9c1142b0..56b933ac04 100644 --- a/src/imap/imap-sync.c +++ b/src/imap/imap-sync.c @@ -769,7 +769,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; + cmd->stats.last_run_timeval = ioloop_timeval; if (client->mailbox == NULL) { /* no mailbox selected, no point in delaying the sync */ if (tagline != NULL)