]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: If client disconnects, log the in-progress commands' input/output bytes.
authorTimo Sirainen <tss@iki.fi>
Mon, 21 Sep 2015 12:41:49 +0000 (15:41 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 21 Sep 2015 12:41:49 +0000 (15:41 +0300)
src/imap/imap-client.c
src/imap/imap-client.h
src/imap/imap-commands.c

index ae9ac9e770e14fc68ecde385e74c205d618cb898..2386fc46737321daf913b9fb1dbe8e89c0583e9f 100644 (file)
@@ -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);
 }
 
index 6bd935479f957a4dfe9c960ed2bfe3ffd794e5c6..f1c6cae188ad8a736278577519368175bfcb0ea5 100644 (file)
@@ -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;
 
index c4418dbf1fbc157a7d03f4c5a5700b82131202b7..2b0ee0f6dd616083ba36c8b706011c4afdd763c8 100644 (file)
@@ -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;
 }