From: Timo Sirainen Date: Tue, 9 Aug 2011 16:42:23 +0000 (+0300) Subject: indexer: If verbose_proctitle=yes, show how many clients/requests there are. X-Git-Tag: 2.1.alpha1~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfa8a04466cd46bdc422bd9eba8e6794758d677b;p=thirdparty%2Fdovecot%2Fcore.git indexer: If verbose_proctitle=yes, show how many clients/requests there are. --- diff --git a/src/indexer/indexer-client.c b/src/indexer/indexer-client.c index 443a4a1aaa..cc44a6447d 100644 --- a/src/indexer/indexer-client.c +++ b/src/indexer/indexer-client.c @@ -39,6 +39,7 @@ struct indexer_client_request { }; struct indexer_client *clients = NULL; +static unsigned int clients_count = 0; static void indexer_client_destroy(struct indexer_client *client); static void indexer_client_ref(struct indexer_client *client); @@ -173,7 +174,10 @@ indexer_client_create(int fd, struct indexer_queue *queue) client->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); client->output = o_stream_create_fd(fd, (size_t)-1, FALSE); client->io = io_add(fd, IO_READ, indexer_client_input, client); + DLLIST_PREPEND(&clients, client); + clients_count++; + indexer_refresh_proctitle(); return client; } @@ -193,7 +197,9 @@ static void indexer_client_destroy(struct indexer_client *client) client->fd = -1; indexer_client_unref(client); + clients_count--; master_service_client_connection_destroyed(master_service); + indexer_refresh_proctitle(); } static void indexer_client_ref(struct indexer_client *client) @@ -214,6 +220,11 @@ static void indexer_client_unref(struct indexer_client *client) i_free(client); } +unsigned int indexer_clients_get_count(void) +{ + return clients_count; +} + void indexer_clients_destroy_all(void) { while (clients != NULL) diff --git a/src/indexer/indexer-client.h b/src/indexer/indexer-client.h index b08e5c6f91..a3638a7374 100644 --- a/src/indexer/indexer-client.h +++ b/src/indexer/indexer-client.h @@ -6,6 +6,8 @@ struct indexer_queue; struct indexer_client * indexer_client_create(int fd, struct indexer_queue *queue); void indexer_client_status_callback(int percentage, void *context); + +unsigned int indexer_clients_get_count(void); void indexer_clients_destroy_all(void); #endif diff --git a/src/indexer/indexer-queue.c b/src/indexer/indexer-queue.c index 913189b87a..8d8893858e 100644 --- a/src/indexer/indexer-queue.c +++ b/src/indexer/indexer-queue.c @@ -121,6 +121,7 @@ void indexer_queue_append(struct indexer_queue *queue, bool append, if (queue->listen_callback != NULL) queue->listen_callback(queue); + indexer_refresh_proctitle(); } struct indexer_request *indexer_queue_request_peek(struct indexer_queue *queue) @@ -136,6 +137,7 @@ void indexer_queue_request_remove(struct indexer_queue *queue) DLLIST2_REMOVE(&queue->head, &queue->tail, request); hash_table_remove(queue->requests, request); + indexer_refresh_proctitle(); } static void indexer_queue_request_status_int(struct indexer_queue *queue, @@ -188,3 +190,8 @@ bool indexer_queue_is_empty(struct indexer_queue *queue) { return queue->head == NULL; } + +unsigned int indexer_queue_count(struct indexer_queue *queue) +{ + return hash_table_count(queue->requests); +} diff --git a/src/indexer/indexer-queue.h b/src/indexer/indexer-queue.h index a9adca8943..b54db3c049 100644 --- a/src/indexer/indexer-queue.h +++ b/src/indexer/indexer-queue.h @@ -24,6 +24,7 @@ void indexer_queue_append(struct indexer_queue *queue, bool append, void indexer_queue_cancel_all(struct indexer_queue *queue); bool indexer_queue_is_empty(struct indexer_queue *queue); +unsigned int indexer_queue_count(struct indexer_queue *queue); /* Return the next request from the queue, without removing it. */ struct indexer_request *indexer_queue_request_peek(struct indexer_queue *queue); diff --git a/src/indexer/indexer.c b/src/indexer/indexer.c index 21fe66a155..4c742e738b 100644 --- a/src/indexer/indexer.c +++ b/src/indexer/indexer.c @@ -2,7 +2,9 @@ #include "lib.h" #include "restrict-access.h" +#include "process-title.h" #include "master-service.h" +#include "master-service-settings.h" #include "indexer-client.h" #include "indexer-queue.h" #include "worker-pool.h" @@ -13,9 +15,20 @@ struct worker_request { struct indexer_request *request; }; +static const struct master_service_settings *set; static struct indexer_queue *queue; static struct worker_pool *worker_pool; +void indexer_refresh_proctitle(void) +{ + if (!set->verbose_proctitle) + return; + + process_title_set(t_strdup_printf("[%u clients, %u requests]", + indexer_clients_get_count(), + indexer_queue_count(queue))); +} + static bool idle_die(void) { return indexer_queue_is_empty(queue); @@ -104,6 +117,8 @@ static void worker_status_callback(int percentage, void *context) int main(int argc, char *argv[]) { + const char *error; + master_service = master_service_init("indexer", 0, &argc, &argv, NULL); if (master_getopt(master_service) > 0) return FATAL_DEFAULT; @@ -113,6 +128,10 @@ int main(int argc, char *argv[]) restrict_access_allow_coredumps(TRUE); master_service_set_idle_die_callback(master_service, idle_die); + if (master_service_settings_read_simple(master_service, NULL, &error) < 0) + i_fatal("Error reading configuration: %s", error); + set = master_service_settings_get(master_service); + master_service_init_finish(master_service); worker_pool = worker_pool_init("indexer-worker", worker_status_callback); diff --git a/src/indexer/indexer.h b/src/indexer/indexer.h index 6880f815c0..417a433cd9 100644 --- a/src/indexer/indexer.h +++ b/src/indexer/indexer.h @@ -4,4 +4,6 @@ /* percentage: -1 = failed, 0..99 = indexing in progress, 100 = done */ typedef void indexer_status_callback_t(int percentage, void *context); +void indexer_refresh_proctitle(void); + #endif