dovecot-1.2: struct mail_private now contains all kinds of stati...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 29 02:57:18 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/fdaf0bda70d5
changeset: 8983:fdaf0bda70d5
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 28 19:55:51 2009 -0400
description:
struct mail_private now contains all kinds of statistics about file accesses.

diffstat:

12 files changed, 199 insertions(+), 16 deletions(-)
src/lib-storage/index/Makefile.am            |    2 
src/lib-storage/index/cydir/cydir-mail.c     |    3 
src/lib-storage/index/dbox/dbox-file.h       |    2 
src/lib-storage/index/dbox/dbox-mail.c       |    5 +
src/lib-storage/index/index-mail-headers.c   |    6 -
src/lib-storage/index/index-mail.c           |   38 ++++++--
src/lib-storage/index/index-mail.h           |    4 
src/lib-storage/index/istream-mail-stats.c   |  117 ++++++++++++++++++++++++++
src/lib-storage/index/istream-mail-stats.h   |    7 +
src/lib-storage/index/maildir/maildir-mail.c |   13 ++
src/lib-storage/index/raw/raw-mail.c         |    2 
src/lib-storage/mail-storage-private.h       |   16 +++

diffs (truncated from 456 to 300 lines):

diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/Makefile.am
--- a/src/lib-storage/index/Makefile.am	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/Makefile.am	Tue Apr 28 19:55:51 2009 -0400
@@ -10,6 +10,7 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-storage
 
 libstorage_index_a_SOURCES = \
+	istream-mail-stats.c \
 	index-fetch.c \
 	index-mail.c \
 	index-mail-headers.c \
@@ -29,6 +30,7 @@ libstorage_index_a_SOURCES = \
 	index-transaction.c
 
 headers = \
+	istream-mail-stats.h \
 	index-mail.h \
 	index-search-result.h \
 	index-sort.h \
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-mail.c	Tue Apr 28 19:55:51 2009 -0400
@@ -20,11 +20,13 @@ static const char *cydir_mail_get_path(s
 
 static int cydir_mail_stat(struct mail *mail, struct stat *st_r)
 {
+	struct mail_private *p = (struct mail_private *)mail;
 	const char *path;
 
 	if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
 		return mail_set_aborted(mail);
 
+	p->stats_dentry_lookup_count++;
 	path = cydir_mail_get_path(mail);
 	if (stat(path, st_r) < 0) {
 		if (errno == ENOENT)
@@ -98,6 +100,7 @@ cydir_mail_get_stream(struct mail *_mail
 	int fd;
 
 	if (mail->data.stream == NULL) {
+		mail->mail.stats_dentry_lookup_count++;
 		path = cydir_mail_get_path(_mail);
 		fd = open(path, O_RDONLY);
 		if (fd == -1) {
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/dbox/dbox-file.h
--- a/src/lib-storage/index/dbox/dbox-file.h	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-file.h	Tue Apr 28 19:55:51 2009 -0400
@@ -139,6 +139,8 @@ struct dbox_file {
 	unsigned int deleted:1;
 };
 
+#define dbox_file_is_open(file) ((file)->input != NULL)
+
 extern enum mail_flags dbox_mail_flags_map[DBOX_METADATA_FLAGS_COUNT];
 extern char dbox_mail_flag_chars[DBOX_METADATA_FLAGS_COUNT];
 
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/dbox/dbox-mail.c
--- a/src/lib-storage/index/dbox/dbox-mail.c	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Tue Apr 28 19:55:51 2009 -0400
@@ -77,6 +77,9 @@ dbox_mail_metadata_seek(struct dbox_mail
 
 	if (dbox_mail_lookup(mail, &offset, file_r) < 0)
 		return -1;
+
+	if (!dbox_file_is_open(*file_r))
+		mail->imail.mail.stats_dentry_lookup_count++;
 
 	ret = dbox_file_metadata_seek_mail_offset(*file_r, offset, &expunged);
 	if (ret <= 0) {
@@ -251,6 +254,8 @@ dbox_mail_get_stream(struct mail *_mail,
 		if (dbox_mail_lookup(mail, &offset, &mail->open_file) < 0)
 			return -1;
 
+		if (!dbox_file_is_open(mail->open_file))
+			mail->imail.mail.stats_dentry_lookup_count++;
 		ret = dbox_file_get_mail_stream(mail->open_file, offset, &uid,
 						&size, &input, &expunged);
 		if (ret < 0)
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/index-mail-headers.c	Tue Apr 28 19:55:51 2009 -0400
@@ -471,8 +471,8 @@ int index_mail_headers_get_envelope(stru
 	string_t *str;
 
 	str = str_new(mail->data_pool, 256);
-	if (mail_cache_lookup_field(mail->trans->cache_view, str,
-				    mail->data.seq, cache_field_envelope) > 0) {
+	if (index_mail_cache_lookup_field(mail, str,
+					  cache_field_envelope) > 0) {
 		mail->data.envelope = str_c(str);
 		return 0;
 	}
@@ -637,6 +637,7 @@ index_mail_get_raw_headers(struct index_
 		*value_r = index_mail_get_parsed_header(mail, field_idx);
 		return 0;
 	}
+	mail->mail.stats_cache_hit_count++;
 	data = buffer_get_modifiable_data(dest, &len);
 
 	if (len == 0) {
@@ -819,6 +820,7 @@ int index_mail_get_header_stream(struct 
 	if (mail_cache_lookup_headers(mail->trans->cache_view, dest,
 				      mail->data.seq, headers->idx,
 				      headers->count) > 0) {
+		mail->mail.stats_cache_hit_count++;
 		if (mail->data.filter_stream != NULL)
 			i_stream_destroy(&mail->data.filter_stream);
 		mail->data.filter_stream =
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/index-mail.c	Tue Apr 28 19:55:51 2009 -0400
@@ -15,6 +15,7 @@
 #include "mail-cache.h"
 #include "mail-index-modseq.h"
 #include "index-storage.h"
+#include "istream-mail-stats.h"
 #include "index-mail.h"
 
 struct mail_cache_field global_cache_fields[MAIL_INDEX_CACHE_FIELD_COUNT] = {
@@ -40,6 +41,18 @@ static int index_mail_parse_body(struct 
 static int index_mail_parse_body(struct index_mail *mail,
 				 enum index_cache_field field);
 
+int index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf,
+				  unsigned int field_idx)
+{
+	int ret;
+
+	ret = mail_cache_lookup_field(mail->trans->cache_view, buf,
+				      mail->data.seq, field_idx);
+	if (ret > 0)
+		mail->mail.stats_cache_hit_count++;
+	return ret;
+}
+
 static struct message_part *get_unserialized_parts(struct index_mail *mail)
 {
 	unsigned int field_idx =
@@ -50,8 +63,7 @@ static struct message_part *get_unserial
 	int ret;
 
 	part_buf = buffer_create_dynamic(pool_datastack_create(), 128);
-	ret = mail_cache_lookup_field(mail->trans->cache_view, part_buf,
-				      mail->data.seq, field_idx);
+	ret = index_mail_cache_lookup_field(mail, part_buf, field_idx);
 	if (ret <= 0)
 		return NULL;
 
@@ -100,8 +112,7 @@ static bool index_mail_get_fixed_field(s
 		buf = buffer_create_data(pool_datastack_create(),
 					 data, data_size);
 
-		if (mail_cache_lookup_field(mail->trans->cache_view, buf,
-					    mail->data.seq, field_idx) <= 0)
+		if (index_mail_cache_lookup_field(mail, buf, field_idx) <= 0)
 			ret = FALSE;
 		else {
 			i_assert(buf->used == data_size);
@@ -802,7 +813,16 @@ int index_mail_init_stream(struct index_
 			   struct istream **stream_r)
 {
 	struct index_mail_data *data = &mail->data;
+	struct istream *input;
 	int ret;
+
+	if (!data->initialized_wrapper_stream && mail->mail.stats_track) {
+		input = i_stream_create_mail_stats_counter(&mail->mail,
+							   data->stream);
+		i_stream_unref(&data->stream);
+		data->stream = input;
+		data->initialized_wrapper_stream = TRUE;
+	}
 
 	i_stream_set_destroy_callback(data->stream,
 				      index_mail_stream_destroy_callback, mail);
@@ -953,11 +973,10 @@ int index_mail_get_special(struct mail *
 		    get_cached_parts(mail)) {
 			index_mail_get_plain_bodystructure(mail, str, FALSE);
 			data->body = str_c(str);
-		} else if (mail_cache_lookup_field(mail->trans->cache_view, str,
-					mail->data.seq, body_cache_field) > 0)
+		} else if (index_mail_cache_lookup_field(mail, str,
+							 body_cache_field) > 0)
 			data->body = str_c(str);
-		else if (mail_cache_lookup_field(mail->trans->cache_view, str,
-					mail->data.seq,
+		else if (index_mail_cache_lookup_field(mail, str,
 					bodystructure_cache_field) > 0) {
 			data->bodystructure =
 				p_strdup(mail->data_pool, str_c(str));
@@ -998,8 +1017,7 @@ int index_mail_get_special(struct mail *
 		    get_cached_parts(mail)) {
 			index_mail_get_plain_bodystructure(mail, str, TRUE);
 			data->bodystructure = str_c(str);
-		} else if (mail_cache_lookup_field(mail->trans->cache_view, str,
-					mail->data.seq,
+		} else if (index_mail_cache_lookup_field(mail, str,
 					bodystructure_cache_field) > 0) {
 			data->bodystructure = str_c(str);
 		} else {
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/index-mail.h
--- a/src/lib-storage/index/index-mail.h	Tue Apr 28 17:21:14 2009 -0400
+++ b/src/lib-storage/index/index-mail.h	Tue Apr 28 19:55:51 2009 -0400
@@ -108,6 +108,7 @@ struct index_mail_data {
 	unsigned int header_parsed:1;
 	unsigned int no_caching:1;
 	unsigned int destroying_stream:1;
+	unsigned int initialized_wrapper_stream:1;
 };
 
 struct index_mail {
@@ -215,4 +216,7 @@ void index_mail_cache_parse_deinit(struc
 void index_mail_cache_parse_deinit(struct mail *mail, time_t received_date,
 				   bool success);
 
+int index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf,
+				  unsigned int field_idx);
+
 #endif
diff -r 947fab5a8992 -r fdaf0bda70d5 src/lib-storage/index/istream-mail-stats.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/index/istream-mail-stats.c	Tue Apr 28 19:55:51 2009 -0400
@@ -0,0 +1,117 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "mail-storage-private.h"
+#include "istream-internal.h"
+#include "istream-mail-stats.h"
+
+struct mail_stats_istream {
+	struct istream_private istream;
+
+	struct mail_private *mail;
+	unsigned int files_read_increased:1;
+};
+
+static void i_stream_mail_stats_destroy(struct iostream_private *stream)
+{
+	struct mail_stats_istream *mstream =
+		(struct mail_stats_istream *)stream;
+
+	i_stream_unref(&mstream->istream.parent);
+}
+
+static void
+i_stream_mail_stats_set_max_buffer_size(struct iostream_private *stream,
+					size_t max_size)
+{
+	struct mail_stats_istream *mstream =
+		(struct mail_stats_istream *)stream;
+
+	mstream->istream.max_buffer_size = max_size;
+	i_stream_set_max_buffer_size(mstream->istream.parent, max_size);
+}
+
+static ssize_t
+i_stream_mail_stats_read_mail_stats(struct istream_private *stream)
+{
+	struct mail_stats_istream *mstream =
+		(struct mail_stats_istream *)stream;
+	size_t pos;
+	ssize_t ret;
+
+	if (stream->parent->v_offset !=
+	    stream->parent_start_offset + stream->istream.v_offset) {
+		i_stream_seek(stream->parent, stream->parent_start_offset +
+			      stream->istream.v_offset);
+	}
+
+	stream->buffer = i_stream_get_data(stream->parent, &pos);
+	if (pos <= stream->pos) {
+		if ((ret = i_stream_read(stream->parent)) == -2)
+			return -2;
+
+		if (ret > 0) {
+			mstream->mail->stats_files_read_bytes+= ret;
+			if (!mstream->files_read_increased) {
+				mstream->files_read_increased = TRUE;
+				mstream->mail->stats_files_read_count++;
+			}
+		}
+
+		stream->istream.stream_errno = stream->parent->stream_errno;
+		stream->istream.eof = stream->parent->eof;
+		stream->buffer = i_stream_get_data(stream->parent, &pos);
+	} else {
+		ret = 0;
+	}
+
+	stream->pos -= stream->skip;
+	stream->skip = 0;
+
+	ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) :
+		(ret == 0 ? 0 : -1);
+	stream->pos = pos;
+	i_assert(ret != -1 || stream->istream.eof ||
+		 stream->istream.stream_errno != 0);
+	return ret;
+}


More information about the dovecot-cvs mailing list