From: Timo Sirainen Date: Mon, 17 Aug 2020 12:33:23 +0000 (+0300) Subject: imap, imap-hibernate: Track how long hibernation lasted X-Git-Tag: 2.3.13~354 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8fac1bccc1bdafb87609e7b0d875d8b2caf4e17e;p=thirdparty%2Fdovecot%2Fcore.git imap, imap-hibernate: Track how long hibernation lasted --- diff --git a/src/imap-hibernate/imap-client.c b/src/imap-hibernate/imap-client.c index ac38a31cfa..341cf3d099 100644 --- a/src/imap-hibernate/imap-client.c +++ b/src/imap-hibernate/imap-client.c @@ -14,6 +14,7 @@ #include "base64.h" #include "str.h" #include "strescape.h" +#include "time-util.h" #include "var-expand.h" #include "master-service.h" #include "master-service-settings.h" @@ -113,9 +114,14 @@ static void imap_client_unhibernate_failed(struct imap_client **_client, const char *error) { struct imap_client *client = *_client; + struct timeval created; + event_get_create_time(client->event, &created); + struct event_passthrough *e = event_create_passthrough(client->event)-> set_name("imap_client_unhibernated")-> + add_int("hibernation_usecs", + timeval_diff_usecs(&ioloop_timeval, &created))-> add_str("error", error); e_error(e->event(), IMAP_CLIENT_UNHIBERNATE_ERROR": %s", error); imap_client_destroy(_client, IMAP_CLIENT_UNHIBERNATE_ERROR); @@ -146,11 +152,16 @@ imap_client_move_back_send_callback(void *context, struct ostream *output) struct imap_client *client = context; const struct imap_client_state *state = &client->state; string_t *str = t_str_new(256); + struct timeval created; const unsigned char *input_data; size_t input_size; ssize_t ret; str_append_tabescaped(str, state->username); + event_get_create_time(client->event, &created); + str_printfa(str, "\thibernation_started=%"PRIdTIME_T".%06u", + created.tv_sec, (unsigned int)created.tv_usec); + if (state->session_id != NULL) { str_append(str, "\tsession="); str_append_tabescaped(str, state->session_id); diff --git a/src/imap/imap-master-client.c b/src/imap/imap-master-client.c index 57bf1be43d..addf6759a6 100644 --- a/src/imap/imap-master-client.c +++ b/src/imap/imap-master-client.c @@ -9,6 +9,7 @@ #include "str.h" #include "strescape.h" #include "str-sanitize.h" +#include "time-util.h" #include "master-service.h" #include "mail-storage-service.h" #include "imap-client.h" @@ -30,6 +31,8 @@ struct imap_master_input { buffer_t *state; /* command tag */ const char *tag; + /* Timestamp when hibernation started */ + struct timeval hibernation_start_time; dev_t peer_dev; ino_t peer_ino; @@ -134,6 +137,12 @@ imap_master_client_parse_input(const char *const *args, pool_t pool, "Invalid session_created value: %s", value); return -1; } + } else if (strcmp(key, "hibernation_started") == 0) { + if (str_to_timeval(value, &master_input_r->hibernation_start_time) < 0) { + *error_r = t_strdup_printf( + "Invalid hibernation_started value: %s", value); + return -1; + } } else if (strcmp(key, "userdb_fields") == 0) { input_r->userdb_fields = t_strsplit_tabescaped(value); @@ -243,8 +252,12 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, } client->imap_client_created = TRUE; + long long hibernation_usecs = + timeval_diff_usecs(&ioloop_timeval, + &master_input.hibernation_start_time); struct event *event = event_create(imap_client->event); event_set_name(event, "imap_client_unhibernated"); + event_add_int(event, "hibernation_usecs", hibernation_usecs); imap_client->state_import_bad_idle_done = master_input.state_import_bad_idle_done; imap_client->state_import_idle_continue = @@ -309,7 +322,9 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, if (master_input.tag != NULL) imap_state_import_idle_cmd_tag(imap_client, master_input.tag); - e_debug(event, "imap-master: Unhibernated because %s", reason); + e_debug(event, "imap-master: Unhibernated because %s " + "(hibernated for %llu.%06llu secs)", reason, + hibernation_usecs/1000000, hibernation_usecs%1000000); event_unref(&event); /* make sure all pending input gets handled */