]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap, imap-hibernate: Track how long hibernation lasted
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 17 Aug 2020 12:33:23 +0000 (15:33 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 21 Aug 2020 08:51:13 +0000 (08:51 +0000)
src/imap-hibernate/imap-client.c
src/imap/imap-master-client.c

index ac38a31cfa65b8ae5552a80f967575f0ffa2437f..341cf3d099ea5a6b360f72063cd2f0336fbeaa88 100644 (file)
@@ -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);
index 57bf1be43dc85b11c69470e65ccdc643c03dcbb7..addf6759a6a24718371eecfd9df39d727d56c5b1 100644 (file)
@@ -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 */