Skip to content

Commit

Permalink
imap: Code cleanup - move command stats to struct client_command_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed Feb 19, 2017
1 parent aee9f24 commit 567b56c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
25 changes: 13 additions & 12 deletions src/imap/imap-client.c
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 18 additions & 14 deletions src/imap/imap-client.h
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/imap/imap-commands.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/imap/imap-sync.c
Expand Up @@ -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)
Expand Down

0 comments on commit 567b56c

Please sign in to comment.