changeset 13358:fd68963a7add

stats: Keep track of last_update in microsecond precision and export it as such.
author Timo Sirainen <tss@iki.fi>
date Thu, 01 Sep 2011 10:40:17 +0300
parents 03ad86ec4ebd
children 07f02f421588
files src/stats/client-export.c src/stats/mail-command.c src/stats/mail-domain.c src/stats/mail-ip.c src/stats/mail-session.c src/stats/mail-stats.h src/stats/mail-user.c
diffstat 7 files changed, 43 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/stats/client-export.c	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/client-export.c	Thu Sep 01 10:40:17 2011 +0300
@@ -124,7 +124,7 @@
 {
 	if (filter->connected && session->disconnected)
 		return FALSE;
-	if (filter->since > session->last_update)
+	if (filter->since > session->last_update.tv_sec)
 		return FALSE;
 	if (filter->user != NULL &&
 	    !wildcard_match(session->user->name, filter->user))
@@ -171,7 +171,7 @@
 mail_export_filter_match_user(const struct mail_export_filter *filter,
 			      const struct mail_user *user)
 {
-	if (filter->since > user->last_update)
+	if (filter->since > user->last_update.tv_sec)
 		return FALSE;
 	if (filter->domain != NULL &&
 	    !wildcard_match(user->domain->name, filter->domain))
@@ -185,7 +185,7 @@
 {
 	struct mail_user *user;
 
-	if (filter->since > domain->last_update)
+	if (filter->since > domain->last_update.tv_sec)
 		return FALSE;
 	if (filter->domain != NULL &&
 	    !wildcard_match(domain->name, filter->domain))
@@ -227,7 +227,7 @@
 		if (filter->domain != NULL && !domain_ok)
 			return FALSE;
 	}
-	if (filter->since > ip->last_update)
+	if (filter->since > ip->last_update.tv_sec)
 		return FALSE;
 	if (filter->ip_bits > 0 &&
 	    !net_is_in_network(&ip->ip, &filter->ip, filter->ip_bits))
@@ -235,6 +235,12 @@
 	return TRUE;
 }
 
+static void client_export_timeval(string_t *str, const struct timeval *tv)
+{
+	str_printfa(str, "\t%ld.%06u", (long)tv->tv_sec,
+		    (unsigned int)tv->tv_usec);
+}
+
 static int client_export_iter_command(struct client *client)
 {
 	struct client_export_cmd *cmd = client->cmd_export;
@@ -265,7 +271,7 @@
 			str_append(cmd->str,
 				   guid_128_to_string(command->session->guid));
 		} T_END;
-		str_printfa(cmd->str, "\t%ld", (long)command->last_update);
+		client_export_timeval(cmd->str, &command->last_update);
 		client_export_mail_stats(cmd->str, &command->stats);
 		str_append_c(cmd->str, '\n');
 		o_stream_send(client->output, str_data(cmd->str),
@@ -315,10 +321,9 @@
 			str_append_c(cmd->str, '\t');
 			str_tabescape_write(cmd->str, session->service);
 		} T_END;
-		str_printfa(cmd->str, "\t%d\t%ld\t%u",
-			    !session->disconnected,
-			    (long)session->last_update,
-			    session->num_cmds);
+		str_printfa(cmd->str, "\t%d", !session->disconnected);
+		client_export_timeval(cmd->str, &session->last_update);
+		str_printfa(cmd->str, "\t%u", session->num_cmds);
 		client_export_mail_stats(cmd->str, &session->stats);
 		str_append_c(cmd->str, '\n');
 		o_stream_send(client->output, str_data(cmd->str),
@@ -356,9 +361,9 @@
 
 		str_truncate(cmd->str, 0);
 		str_tabescape_write(cmd->str, user->name);
-		str_printfa(cmd->str, "\t%ld\t%ld\t%u\t%u",
-			    (long)user->reset_timestamp,
-			    (long)user->last_update,
+		str_printfa(cmd->str, "\t%ld", (long)user->reset_timestamp);
+		client_export_timeval(cmd->str, &user->last_update);
+		str_printfa(cmd->str, "\t%u\t%u",
 			    user->num_logins, user->num_cmds);
 		client_export_mail_stats(cmd->str, &user->stats);
 		str_append_c(cmd->str, '\n');
@@ -397,9 +402,9 @@
 
 		str_truncate(cmd->str, 0);
 		str_tabescape_write(cmd->str, domain->name);
-		str_printfa(cmd->str, "\t%ld\t%ld\t%u\t%u",
-			    (long)domain->reset_timestamp,
-			    (long)domain->last_update,
+		str_printfa(cmd->str, "\t%ld", (long)domain->reset_timestamp);
+		client_export_timeval(cmd->str, &domain->last_update);
+		str_printfa(cmd->str, "\t%u\t%u",
 			    domain->num_logins, domain->num_cmds);
 		client_export_mail_stats(cmd->str, &domain->stats);
 		str_append_c(cmd->str, '\n');
@@ -440,10 +445,9 @@
 		T_BEGIN {
 			str_append(cmd->str, net_ip2addr(&ip->ip));
 		} T_END;
-		str_printfa(cmd->str, "\t%ld\t%ld\t%u\t%u",
-			    (long)ip->reset_timestamp,
-			    (long)ip->last_update,
-			    ip->num_logins, ip->num_cmds);
+		str_printfa(cmd->str, "\t%ld", (long)ip->reset_timestamp);
+		client_export_timeval(cmd->str, &ip->last_update);
+		str_printfa(cmd->str, "\t%u\t%u", ip->num_logins, ip->num_cmds);
 		client_export_mail_stats(cmd->str, &ip->stats);
 		str_append_c(cmd->str, '\n');
 		o_stream_send(client->output, str_data(cmd->str),
--- a/src/stats/mail-command.c	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/mail-command.c	Thu Sep 01 10:40:17 2011 +0300
@@ -47,7 +47,7 @@
 	cmd->session = session;
 	cmd->name = i_strdup(name);
 	cmd->args = i_strdup(args);
-	cmd->last_update = ioloop_time;
+	cmd->last_update = ioloop_timeval;
 
 	DLLIST_PREPEND_FULL(&stable_mail_commands, cmd,
 			    stable_prev, stable_next);
@@ -138,7 +138,7 @@
 			*error_r = "UPDATE-SESSION: stats shrank";
 			return -1;
 		}
-		cmd->last_update = ioloop_time;
+		cmd->last_update = ioloop_timeval;
 		mail_stats_add(&session->stats, &diff_stats);
 	}
 	if (done) {
@@ -159,7 +159,7 @@
 		if (global_used_memory < stats_settings->memory_limit)
 			break;
 		if (ioloop_time -
-		    stable_mail_commands->last_update < stats_settings->command_min_time)
+		    stable_mail_commands->last_update.tv_sec < stats_settings->command_min_time)
 			break;
 	}
 }
--- a/src/stats/mail-domain.c	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/mail-domain.c	Thu Sep 01 10:40:17 2011 +0300
@@ -40,7 +40,7 @@
 	DLLIST2_APPEND_FULL(&mail_domains_head, &mail_domains_tail, domain,
 			    sorted_prev, sorted_next);
 	domain->num_logins++;
-	domain->last_update = ioloop_time;
+	domain->last_update = ioloop_timeval;
 	global_memory_alloc(mail_domain_memsize(domain));
 	return domain;
 }
@@ -86,7 +86,7 @@
 {
 	if (diff_stats != NULL)
 		mail_stats_add(&domain->stats, diff_stats);
-	domain->last_update = ioloop_time;
+	domain->last_update = ioloop_timeval;
 	DLLIST2_REMOVE_FULL(&mail_domains_head, &mail_domains_tail, domain,
 			    sorted_prev, sorted_next);
 	DLLIST2_APPEND_FULL(&mail_domains_head, &mail_domains_tail, domain,
@@ -101,7 +101,7 @@
 		if (global_used_memory < stats_settings->memory_limit)
 			break;
 		if (ioloop_time -
-		    mail_domains_head->last_update < stats_settings->domain_min_time)
+		    mail_domains_head->last_update.tv_sec < stats_settings->domain_min_time)
 			break;
 	}
 }
--- a/src/stats/mail-ip.c	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/mail-ip.c	Thu Sep 01 10:40:17 2011 +0300
@@ -39,7 +39,7 @@
 	DLLIST2_APPEND_FULL(&mail_ips_head, &mail_ips_tail, ip,
 			    sorted_prev, sorted_next);
 	ip->num_logins++;
-	ip->last_update = ioloop_time;
+	ip->last_update = ioloop_timeval;
 	global_memory_alloc(mail_ip_memsize(ip));
 	return ip;
 }
@@ -82,7 +82,7 @@
 {
 	if (diff_stats != NULL)
 		mail_stats_add(&ip->stats, diff_stats);
-	ip->last_update = ioloop_time;
+	ip->last_update = ioloop_timeval;
 	DLLIST2_REMOVE_FULL(&mail_ips_head, &mail_ips_tail, ip,
 			    sorted_prev, sorted_next);
 	DLLIST2_APPEND_FULL(&mail_ips_head, &mail_ips_tail, ip,
@@ -97,7 +97,7 @@
 		if (global_used_memory < stats_settings->memory_limit)
 			break;
 		if (ioloop_time -
-		    mail_ips_head->last_update < stats_settings->ip_min_time)
+		    mail_ips_head->last_update.tv_sec < stats_settings->ip_min_time)
 			break;
 	}
 }
--- a/src/stats/mail-session.c	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/mail-session.c	Thu Sep 01 10:40:17 2011 +0300
@@ -67,7 +67,7 @@
 	session->refcount = 1; /* unrefed at disconnect */
 	session->service = i_strdup(args[2]);
 	memcpy(session->guid, session_guid, sizeof(session->guid));
-	session->last_update = ioloop_time;
+	session->last_update = ioloop_timeval;
 	session->to_idle = timeout_add(MAIL_SESSION_IDLE_TIMEOUT_MSECS,
 				       mail_session_idle_timeout, session);
 
@@ -179,7 +179,7 @@
 
 	if (diff_stats != NULL)
 		mail_stats_add(&session->stats, diff_stats);
-	session->last_update = ioloop_time;
+	session->last_update = ioloop_timeval;
 	DLLIST2_REMOVE_FULL(&mail_sessions_head, &mail_sessions_tail, session,
 			    sorted_prev, sorted_next);
 	DLLIST2_APPEND_FULL(&mail_sessions_head, &mail_sessions_tail, session,
@@ -223,7 +223,7 @@
 		if (global_used_memory < stats_settings->memory_limit)
 			break;
 		if (ioloop_time -
-		    mail_sessions_head->last_update < stats_settings->session_min_time)
+		    mail_sessions_head->last_update.tv_sec < stats_settings->session_min_time)
 			break;
 	}
 }
--- a/src/stats/mail-stats.h	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/mail-stats.h	Thu Sep 01 10:40:17 2011 +0300
@@ -23,7 +23,7 @@
 	/* non-zero id means the command is still running */
 	unsigned int id;
 
-	time_t last_update;
+	struct timeval last_update;
 	struct mail_stats stats;
 
 	int refcount;
@@ -44,7 +44,7 @@
 	struct timeout *to_idle;
 
 	struct mail_stats stats;
-	time_t last_update;
+	struct timeval last_update;
 	unsigned int num_cmds;
 
 	bool disconnected;
@@ -61,7 +61,7 @@
 	struct mail_domain *domain;
 	time_t reset_timestamp;
 
-	time_t last_update;
+	struct timeval last_update;
 	struct mail_stats stats;
 	unsigned int num_logins;
 	unsigned int num_cmds;
@@ -76,7 +76,7 @@
 	char *name;
 	time_t reset_timestamp;
 
-	time_t last_update;
+	struct timeval last_update;
 	struct mail_stats stats;
 	unsigned int num_logins;
 	unsigned int num_cmds;
@@ -91,7 +91,7 @@
 	struct ip_addr ip;
 	time_t reset_timestamp;
 
-	time_t last_update;
+	struct timeval last_update;
 	struct mail_stats stats;
 	unsigned int num_logins;
 	unsigned int num_cmds;
--- a/src/stats/mail-user.c	Thu Sep 01 10:39:37 2011 +0300
+++ b/src/stats/mail-user.c	Thu Sep 01 10:40:17 2011 +0300
@@ -54,7 +54,7 @@
 	mail_domain_ref(user->domain);
 
 	user->num_logins++;
-	user->last_update = ioloop_time;
+	user->last_update = ioloop_timeval;
 	global_memory_alloc(mail_user_memsize(user));
 	return user;
 }
@@ -102,7 +102,7 @@
 {
 	if (diff_stats != NULL)
 		mail_stats_add(&user->stats, diff_stats);
-	user->last_update = ioloop_time;
+	user->last_update = ioloop_timeval;
 	DLLIST2_REMOVE_FULL(&mail_users_head, &mail_users_tail, user,
 			    sorted_prev, sorted_next);
 	DLLIST2_APPEND_FULL(&mail_users_head, &mail_users_tail, user,
@@ -118,7 +118,7 @@
 		if (global_used_memory < stats_settings->memory_limit)
 			break;
 		if (ioloop_time -
-		    mail_users_head->last_update < stats_settings->user_min_time)
+		    mail_users_head->last_update.tv_sec < stats_settings->user_min_time)
 			break;
 	}
 }