changeset 13192:af8c5e56d098

indexer: If verbose_proctitle=yes, show how many clients/requests there are.
author Timo Sirainen <tss@iki.fi>
date Tue, 09 Aug 2011 19:42:23 +0300
parents c705f4fa7a77
children 63ce98c611e4
files src/indexer/indexer-client.c src/indexer/indexer-client.h src/indexer/indexer-queue.c src/indexer/indexer-queue.h src/indexer/indexer.c src/indexer/indexer.h
diffstat 6 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/indexer/indexer-client.c	Tue Aug 09 19:28:00 2011 +0300
+++ b/src/indexer/indexer-client.c	Tue Aug 09 19:42:23 2011 +0300
@@ -39,6 +39,7 @@
 };
 
 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 @@
 	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 @@
 	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 @@
 	i_free(client);
 }
 
+unsigned int indexer_clients_get_count(void)
+{
+	return clients_count;
+}
+
 void indexer_clients_destroy_all(void)
 {
 	while (clients != NULL)
--- a/src/indexer/indexer-client.h	Tue Aug 09 19:28:00 2011 +0300
+++ b/src/indexer/indexer-client.h	Tue Aug 09 19:42:23 2011 +0300
@@ -6,6 +6,8 @@
 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
--- a/src/indexer/indexer-queue.c	Tue Aug 09 19:28:00 2011 +0300
+++ b/src/indexer/indexer-queue.c	Tue Aug 09 19:42:23 2011 +0300
@@ -121,6 +121,7 @@
 
 	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 @@
 
 	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 @@
 {
 	return queue->head == NULL;
 }
+
+unsigned int indexer_queue_count(struct indexer_queue *queue)
+{
+	return hash_table_count(queue->requests);
+}
--- a/src/indexer/indexer-queue.h	Tue Aug 09 19:28:00 2011 +0300
+++ b/src/indexer/indexer-queue.h	Tue Aug 09 19:42:23 2011 +0300
@@ -24,6 +24,7 @@
 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);
--- a/src/indexer/indexer.c	Tue Aug 09 19:28:00 2011 +0300
+++ b/src/indexer/indexer.c	Tue Aug 09 19:42:23 2011 +0300
@@ -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 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 @@
 
 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 @@
 	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);
--- a/src/indexer/indexer.h	Tue Aug 09 19:28:00 2011 +0300
+++ b/src/indexer/indexer.h	Tue Aug 09 19:42:23 2011 +0300
@@ -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