dovecot-2.2: imap: If client disconnects, log the in-progress co...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 21 12:43:06 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/e937b8e7a6a3
changeset: 19164:e937b8e7a6a3
user: Timo Sirainen <tss at iki.fi>
date: Mon Sep 21 15:41:49 2015 +0300
description:
imap: If client disconnects, log the in-progress commands' input/output bytes.
diffstat:
src/imap/imap-client.c | 10 ++++++----
src/imap/imap-client.h | 2 ++
src/imap/imap-commands.c | 8 ++++++++
3 files changed, 16 insertions(+), 4 deletions(-)
diffs (81 lines):
diff -r 12dda0010920 -r e937b8e7a6a3 src/imap/imap-client.c
--- a/src/imap/imap-client.c Mon Sep 21 15:32:02 2015 +0300
+++ b/src/imap/imap-client.c Mon Sep 21 15:41:49 2015 +0300
@@ -260,6 +260,7 @@
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 @@
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 @@
(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 -r 12dda0010920 -r e937b8e7a6a3 src/imap/imap-client.h
--- a/src/imap/imap-client.h Mon Sep 21 15:32:02 2015 +0300
+++ b/src/imap/imap-client.h Mon Sep 21 15:41:49 2015 +0300
@@ -81,6 +81,8 @@
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 -r 12dda0010920 -r e937b8e7a6a3 src/imap/imap-commands.c
--- a/src/imap/imap-commands.c Mon Sep 21 15:32:02 2015 +0300
+++ b/src/imap/imap-commands.c Mon Sep 21 15:41:49 2015 +0300
@@ -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 @@
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 @@
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;
}
More information about the dovecot-cvs
mailing list