From: Timo Sirainen Date: Mon, 21 Sep 2015 12:41:49 +0000 (+0300) Subject: imap: If client disconnects, log the in-progress commands' input/output bytes. X-Git-Tag: 2.2.19.rc1~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c9b76ca218d93dc97e27d6ec04a645e8dc6f228b;p=thirdparty%2Fdovecot%2Fcore.git imap: If client disconnects, log the in-progress commands' input/output bytes. --- diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index ae9ac9e770..2386fc4673 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -260,6 +260,7 @@ static const char *client_get_commands_status(struct client *client) struct client_command_context *cmd; unsigned int msecs_in_ioloop; uint64_t running_usecs = 0, ioloop_wait_usecs; + unsigned long long bytes_in = 0, bytes_out = 0; string_t *str; if (client->command_queue == NULL) @@ -272,6 +273,8 @@ static const char *client_get_commands_status(struct client *client) if (cmd->next != NULL) str_append_c(str, ','); running_usecs += cmd->running_usecs; + bytes_in += cmd->bytes_in; + bytes_out += cmd->bytes_out; } ioloop_wait_usecs = io_loop_get_wait_usecs(current_ioloop); @@ -281,10 +284,9 @@ static const char *client_get_commands_status(struct client *client) (int)((running_usecs+999)/1000 / 1000), (int)((running_usecs+999)/1000 % 1000), msecs_in_ioloop / 1000, msecs_in_ioloop % 1000); - if (o_stream_get_buffer_used_size(client->output) > 0) - str_printfa(str, ", %"PRIuSIZE_T" B output buffered", - o_stream_get_buffer_used_size(client->output)); - str_append_c(str, ')'); + str_printfa(str, ", %llu B in + %llu+%"PRIuSIZE_T" B out)", + bytes_in, bytes_out, + o_stream_get_buffer_used_size(client->output)); return str_c(str); } diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index 6bd935479f..f1c6cae188 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -81,6 +81,8 @@ struct client_command_context { uint64_t start_ioloop_wait_usecs; /* how many usecs this command itself has spent running */ uint64_t running_usecs; + /* how many bytes of client input/output command has used */ + uint64_t bytes_in, bytes_out; struct client_sync_context *sync; diff --git a/src/imap/imap-commands.c b/src/imap/imap-commands.c index c4418dbf1f..2b0ee0f6dd 100644 --- a/src/imap/imap-commands.c +++ b/src/imap/imap-commands.c @@ -4,6 +4,8 @@ #include "array.h" #include "buffer.h" #include "ioloop.h" +#include "istream.h" +#include "ostream.h" #include "time-util.h" #include "imap-commands.h" @@ -156,9 +158,12 @@ bool command_exec(struct client_command_context *cmd) const struct command_hook *hook; bool finished; struct timeval cmd_start_timeval; + uint64_t cmd_start_bytes_in, cmd_start_bytes_out; io_loop_time_refresh(); cmd_start_timeval = ioloop_timeval; + cmd_start_bytes_in = i_stream_get_absolute_offset(cmd->client->input); + cmd_start_bytes_out = cmd->client->output->offset; array_foreach(&command_hooks, hook) hook->pre(cmd); @@ -171,6 +176,9 @@ bool command_exec(struct client_command_context *cmd) io_loop_time_refresh(); cmd->running_usecs += timeval_diff_usecs(&ioloop_timeval, &cmd_start_timeval); + cmd->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; return finished; }