dovecot-2.2: imap: Return how long SELECT or EXAMINE command too...

dovecot at dovecot.org dovecot at dovecot.org
Wed May 15 15:35:25 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/21ab416ea0cd
changeset: 16363:21ab416ea0cd
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 15 15:35:10 2013 +0300
description:
imap: Return how long SELECT or EXAMINE command took to answer.
Could be useful to know sometimes if there's a large maildir where a lot
files need to be rename()d.

diffstat:

 src/imap/cmd-select.c |  19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diffs (55 lines):

diff -r 2c770b01d21f -r 21ab416ea0cd src/imap/cmd-select.c
--- a/src/imap/cmd-select.c	Wed May 15 15:26:47 2013 +0300
+++ b/src/imap/cmd-select.c	Wed May 15 15:35:10 2013 +0300
@@ -2,6 +2,7 @@
 
 #include "imap-common.h"
 #include "seq-range-array.h"
+#include "time-util.h"
 #include "imap-commands.h"
 #include "mail-search-build.h"
 #include "imap-search-args.h"
@@ -16,6 +17,7 @@
 	struct mail_namespace *ns;
 	struct mailbox *box;
 
+	struct timeval start_time;
 	struct imap_fetch_context *fetch_ctx;
 
 	uint32_t qresync_uid_validity;
@@ -198,14 +200,24 @@
 
 static void cmd_select_finish(struct imap_select_context *ctx, int ret)
 {
+	const char *resp_code;
+	struct timeval end_time;
+	int time_msecs;
+
 	if (ret < 0) {
 		if (ctx->box != NULL)
 			mailbox_free(&ctx->box);
 		ctx->cmd->client->mailbox = NULL;
 	} else {
-		client_send_tagline(ctx->cmd, mailbox_is_readonly(ctx->box) ?
-				    "OK [READ-ONLY] Select completed." :
-				    "OK [READ-WRITE] Select completed.");
+		resp_code = mailbox_is_readonly(ctx->box) ?
+			"READ-ONLY" : "READ-WRITE";
+		if (gettimeofday(&end_time, NULL) < 0)
+			memset(&end_time, 0, sizeof(end_time));
+		time_msecs = timeval_diff_msecs(&end_time, &ctx->start_time);
+		client_send_tagline(ctx->cmd, t_strdup_printf(
+			"OK [%s] %s completed (%d.%03d secs).", resp_code,
+			ctx->cmd->client->mailbox_examined ? "Examine" : "Select",
+			time_msecs/1000, time_msecs%1000));
 	}
 	select_context_free(ctx);
 }
@@ -398,6 +410,7 @@
 	ctx = p_new(cmd->pool, struct imap_select_context, 1);
 	ctx->cmd = cmd;
 	ctx->ns = client_find_namespace(cmd, &mailbox);
+	(void)gettimeofday(&ctx->start_time, NULL);
 	if (ctx->ns == NULL) {
 		close_selected_mailbox(client);
 		return TRUE;


More information about the dovecot-cvs mailing list