]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Code cleanup - move command stats to struct client_command_stats
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 16 Feb 2017 18:14:55 +0000 (20:14 +0200)
committerGitLab <gitlab@git.dovecot.net>
Sun, 19 Feb 2017 00:38:13 +0000 (02:38 +0200)
src/imap/imap-client.c
src/imap/imap-client.h
src/imap/imap-commands.c
src/imap/imap-sync.c

index 42c98d228a3343f209d55e2653e3f3c01e860ea3..d013fcc909f7449bf32dfb8e6202ded211aff2cc 100644 (file)
@@ -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);
index 9b9dd545853342cc7029d577289306fdace2865e..bdc0468a38a2edfe7e03a696ffd26a68dd9e87cc 100644 (file)
@@ -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;
 
index d41f363d0a21c535aa4cfacbf97ff13847e9e4ce..70df94adcb60027edd44b39d6a8a425ccc13eeb0 100644 (file)
@@ -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;
 }
 
index eb9c1142b0c55ad8021f3dcbe6becd51e12086b3..56b933ac04ccbbb5ea58b21edba82a803ea1f2b4 100644 (file)
@@ -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)