dovecot-2.1: stats: Log more verbosely what happened if stats sh...

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 1 17:53:03 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/1c2d8da38a06
changeset: 13368:1c2d8da38a06
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 01 17:52:51 2011 +0300
description:
stats: Log more verbosely what happened if stats shrink.

diffstat:

 src/stats/mail-command.c |   7 +++++--
 src/stats/mail-session.c |   6 ++++--
 src/stats/mail-stats.c   |  27 +++++++++++++++++++++++----
 src/stats/mail-stats.h   |   2 +-
 4 files changed, 33 insertions(+), 9 deletions(-)

diffs (114 lines):

diff -r ea0b4da3ceef -r 1c2d8da38a06 src/stats/mail-command.c
--- a/src/stats/mail-command.c	Thu Sep 01 12:34:11 2011 +0300
+++ b/src/stats/mail-command.c	Thu Sep 01 17:52:51 2011 +0300
@@ -94,6 +94,7 @@
 	struct mail_session *session;
 	struct mail_command *cmd;
 	struct mail_stats stats, diff_stats;
+	const char *error;
 	unsigned int cmd_id;
 	bool done;
 	int ret;
@@ -134,8 +135,10 @@
 		if (session->ip != NULL)
 			session->ip->num_cmds++;
 	} else {
-		if (!mail_stats_diff(&cmd->stats, &stats, &diff_stats)) {
-			*error_r = "UPDATE-SESSION: stats shrank";
+		if (!mail_stats_diff(&cmd->stats, &stats, &diff_stats,
+				     &error)) {
+			*error_r = t_strconcat("UPDATE-SESSION: stats shrank: ",
+					       error, NULL);
 			return -1;
 		}
 		cmd->last_update = ioloop_timeval;
diff -r ea0b4da3ceef -r 1c2d8da38a06 src/stats/mail-session.c
--- a/src/stats/mail-session.c	Thu Sep 01 12:34:11 2011 +0300
+++ b/src/stats/mail-session.c	Thu Sep 01 17:52:51 2011 +0300
@@ -201,6 +201,7 @@
 {
 	struct mail_session *session;
 	struct mail_stats stats, diff_stats;
+	const char *error;
 	int ret;
 
 	/* <session guid> [key=value ..] */
@@ -212,8 +213,9 @@
 		return -1;
 	}
 
-	if (!mail_stats_diff(&session->stats, &stats, &diff_stats)) {
-		*error_r = "UPDATE-SESSION: stats shrank";
+	if (!mail_stats_diff(&session->stats, &stats, &diff_stats, &error)) {
+		*error_r = t_strconcat("UPDATE-SESSION: stats shrank: ",
+				       error, NULL);
 		return -1;
 	}
 	mail_session_refresh(session, &diff_stats);
diff -r ea0b4da3ceef -r 1c2d8da38a06 src/stats/mail-stats.c
--- a/src/stats/mail-stats.c	Thu Sep 01 12:34:11 2011 +0300
+++ b/src/stats/mail-stats.c	Thu Sep 01 17:52:51 2011 +0300
@@ -162,7 +162,7 @@
 
 bool mail_stats_diff(const struct mail_stats *stats1,
 		     const struct mail_stats *stats2,
-		     struct mail_stats *diff_stats_r)
+		     struct mail_stats *diff_stats_r, const char **error_r)
 {
 	unsigned int i;
 
@@ -178,20 +178,39 @@
 		case TYPE_NUM:
 			switch (parse_map[i].size) {
 			case sizeof(uint32_t):
-				if (!mail_stats_diff_uint32(dest, src1, src2))
+				if (!mail_stats_diff_uint32(dest, src1, src2)) {
+					*error_r = t_strdup_printf("%s %u < %u",
+						parse_map[i].name,
+						*(const uint32_t *)src2,
+						*(const uint32_t *)src1);
 					return FALSE;
+				}
 				break;
 			case sizeof(uint64_t):
-				if (!mail_stats_diff_uint64(dest, src1, src2))
+				if (!mail_stats_diff_uint64(dest, src1, src2)) {
+					const uint64_t *n1 = src1, *n2 = src2;
+
+					*error_r = t_strdup_printf("%s %llu < %llu",
+						parse_map[i].name,
+						(unsigned long long)n2,
+						(unsigned long long)n1);
 					return FALSE;
+				}
 				break;
 			default:
 				i_unreached();
 			}
 			break;
 		case TYPE_TIMEVAL:
-			if (!mail_stats_diff_timeval(dest, src1, src2))
+			if (!mail_stats_diff_timeval(dest, src1, src2)) {
+				const struct timeval *tv1 = src1, *tv2 = src2;
+
+				*error_r = t_strdup_printf("%s %ld.%d < %ld.%d",
+					parse_map[i].name,
+					(long)tv2->tv_sec, (int)tv2->tv_usec,
+					(long)tv1->tv_sec, (int)tv1->tv_usec);
 				return FALSE;
+			}
 			break;
 		}
 	}
diff -r ea0b4da3ceef -r 1c2d8da38a06 src/stats/mail-stats.h
--- a/src/stats/mail-stats.h	Thu Sep 01 12:34:11 2011 +0300
+++ b/src/stats/mail-stats.h	Thu Sep 01 17:52:51 2011 +0300
@@ -107,7 +107,7 @@
    is so, FALSE if not */
 bool mail_stats_diff(const struct mail_stats *stats1,
 		     const struct mail_stats *stats2,
-		     struct mail_stats *diff_stats_r);
+		     struct mail_stats *diff_stats_r, const char **error_r);
 void mail_stats_add(struct mail_stats *dest, const struct mail_stats *src);
 
 #endif


More information about the dovecot-cvs mailing list