changeset 21584:69316c5e2424

imap: Code cleanup - move command stats to struct client_command_stats
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 16 Feb 2017 20:14:55 +0200
parents f3c79619c096
children 1d7bb1681e7b
files src/imap/imap-client.c src/imap/imap-client.h src/imap/imap-commands.c src/imap/imap-sync.c
diffstat 4 files changed, 36 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-client.c	Fri Feb 17 15:46:38 2017 +0200
+++ b/src/imap/imap-client.c	Thu Feb 16 20:14:55 2017 +0200
@@ -295,10 +295,10 @@
 		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)
@@ -316,7 +316,7 @@
 
 	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,
@@ -490,15 +490,15 @@
 	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 @@
 	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);
--- a/src/imap/imap-client.h	Fri Feb 17 15:46:38 2017 +0200
+++ b/src/imap/imap-client.h	Thu Feb 16 20:14:55 2017 +0200
@@ -52,6 +52,23 @@
 	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 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;
 
--- a/src/imap/imap-commands.c	Fri Feb 17 15:46:38 2017 +0200
+++ b/src/imap/imap-commands.c	Thu Feb 16 20:14:55 2017 +0200
@@ -186,13 +186,13 @@
 		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;
 }
 
--- a/src/imap/imap-sync.c	Fri Feb 17 15:46:38 2017 +0200
+++ b/src/imap/imap-sync.c	Thu Feb 16 20:14:55 2017 +0200
@@ -769,7 +769,7 @@
 	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)