From 0fdcd108bac993adaab2ac5bad84b9aede1c6a99 Mon Sep 17 00:00:00 2001
From: David Goulet <dgoulet@efficios.com>
Date: Fri, 1 Feb 2013 10:27:14 -0500
Subject: [PATCH] Fix: add health state update

Signed-off-by: David Goulet <dgoulet@efficios.com>
---
 src/bin/lttng-sessiond/cmd.c          |   99 +++++++++++++++++++++++++++++++++
 src/bin/lttng-sessiond/consumer.c     |    7 +++
 src/bin/lttng-sessiond/main.c         |   15 +++++
 src/bin/lttng-sessiond/session.c      |   13 +++++
 src/bin/lttng-sessiond/ust-consumer.c |    1 +
 tests/tools/Makefile.am               |    5 +-
 6 files changed, 139 insertions(+), 1 deletion(-)

diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
index 8bffdc4..3c0ef69 100644
--- a/src/bin/lttng-sessiond/cmd.c
+++ b/src/bin/lttng-sessiond/cmd.c
@@ -140,6 +140,7 @@ static void list_lttng_channels(int domain, struct ltt_session *session,
 		if (session->kernel_session != NULL) {
 			cds_list_for_each_entry(kchan,
 					&session->kernel_session->channel_list.head, list) {
+				health_code_update();
 				/* Copy lttng_channel struct to array */
 				memcpy(&channels[i], kchan->channel, sizeof(struct lttng_channel));
 				channels[i].enabled = kchan->enabled;
@@ -155,6 +156,7 @@ static void list_lttng_channels(int domain, struct ltt_session *session,
 		rcu_read_lock();
 		cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
 				&iter.iter, uchan, node.node) {
+			health_code_update();
 			strncpy(channels[i].name, uchan->name, LTTNG_SYMBOL_NAME_LEN);
 			channels[i].attr.overwrite = uchan->attr.overwrite;
 			channels[i].attr.subbuf_size = uchan->attr.subbuf_size;
@@ -223,6 +225,7 @@ static int list_lttng_ust_global_events(char *channel_name,
 	}
 
 	cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) {
+		health_code_update();
 		strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN);
 		tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
 		tmp[i].enabled = uevent->enabled;
@@ -298,6 +301,7 @@ static int list_lttng_kernel_events(char *channel_name,
 
 	/* Kernel channels */
 	cds_list_for_each_entry(event, &kchan->events_list.head , list) {
+		health_code_update();
 		strncpy((*events)[i].name, event->event->name, LTTNG_SYMBOL_NAME_LEN);
 		(*events)[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
 		(*events)[i].enabled = event->enabled;
@@ -350,6 +354,8 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
 
 	assert(uri);
 
+	health_code_update();
+
 	if (consumer == NULL) {
 		DBG("No consumer detected. Don't add URI. Stopping.");
 		ret = LTTNG_ERR_NO_CONSUMER;
@@ -421,6 +427,7 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
 	}
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -471,6 +478,8 @@ static int create_connect_relayd(struct consumer_output *output,
 	int ret;
 	struct lttcomm_sock *sock;
 
+	health_code_update();
+
 	/* Create socket object from URI */
 	sock = lttcomm_alloc_sock_from_uri(uri);
 	if (sock == NULL) {
@@ -485,7 +494,9 @@ static int create_connect_relayd(struct consumer_output *output,
 	}
 
 	/* Connect to relayd so we can proceed with a session creation. */
+	health_poll_entry();
 	ret = relayd_connect(sock);
+	health_poll_exit();
 	if (ret < 0) {
 		ERR("Unable to reach lttng-relayd");
 		ret = LTTNG_ERR_RELAYD_CONNECT_FAIL;
@@ -497,8 +508,10 @@ static int create_connect_relayd(struct consumer_output *output,
 		DBG3("Creating relayd stream socket from URI");
 
 		/* Check relayd version */
+		health_poll_entry();
 		ret = relayd_version_check(sock, RELAYD_VERSION_COMM_MAJOR,
 				RELAYD_VERSION_COMM_MINOR);
+		health_poll_exit();
 		if (ret < 0) {
 			ret = LTTNG_ERR_RELAYD_VERSION_FAIL;
 			goto close_sock;
@@ -514,6 +527,7 @@ static int create_connect_relayd(struct consumer_output *output,
 
 	*relayd_sock = sock;
 
+	health_code_update();
 	return LTTNG_OK;
 
 close_sock:
@@ -525,6 +539,7 @@ free_sock:
 		lttcomm_destroy_sock(sock);
 	}
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -538,6 +553,8 @@ static int send_consumer_relayd_socket(int domain, struct ltt_session *session,
 	int ret;
 	struct lttcomm_sock *sock = NULL;
 
+	health_code_update();
+
 	/* Set the network sequence index if not set. */
 	if (consumer->net_seq_index == -1) {
 		/*
@@ -589,6 +606,7 @@ close_sock:
 		lttcomm_destroy_sock(sock);
 	}
 
+	health_code_update();
 	return ret;
 }
 
@@ -658,7 +676,9 @@ static int setup_relayd(struct ltt_session *session)
 			/* Code flow error */
 			assert(socket->fd >= 0);
 
+			health_poll_entry();
 			pthread_mutex_lock(socket->lock);
+			health_poll_exit();
 			ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session,
 					usess->consumer, socket);
 			pthread_mutex_unlock(socket->lock);
@@ -675,7 +695,9 @@ static int setup_relayd(struct ltt_session *session)
 			/* Code flow error */
 			assert(socket->fd >= 0);
 
+			health_poll_entry();
 			pthread_mutex_lock(socket->lock);
+			health_poll_exit();
 			ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session,
 					ksess->consumer, socket);
 			pthread_mutex_unlock(socket->lock);
@@ -698,6 +720,8 @@ static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe)
 	int ret;
 	struct ltt_kernel_channel *kchan;
 
+	health_code_update();
+
 	/* Open kernel metadata */
 	if (ksess->metadata == NULL) {
 		ret = kernel_open_metadata(ksess);
@@ -719,6 +743,7 @@ static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe)
 
 	/* For each channel */
 	cds_list_for_each_entry(kchan, &ksess->channel_list.head, list) {
+		health_code_update();
 		if (kchan->stream_count == 0) {
 			ret = kernel_open_channel_stream(kchan);
 			if (ret < 0) {
@@ -752,6 +777,7 @@ static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe)
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -767,6 +793,7 @@ int cmd_disable_channel(struct ltt_session *session, int domain,
 	usess = session->ust_session;
 
 	rcu_read_lock();
+	health_code_update();
 
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
@@ -812,6 +839,7 @@ int cmd_disable_channel(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	rcu_read_unlock();
 	return ret;
 }
@@ -834,6 +862,7 @@ int cmd_enable_channel(struct ltt_session *session,
 	DBG("Enabling channel %s for session %s", attr->name, session->name);
 
 	rcu_read_lock();
+	health_code_update();
 
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
@@ -903,6 +932,7 @@ int cmd_enable_channel(struct ltt_session *session,
 	}
 
 error:
+	health_code_update();
 	rcu_read_unlock();
 	return ret;
 }
@@ -917,6 +947,7 @@ int cmd_disable_event(struct ltt_session *session, int domain,
 	int ret;
 
 	rcu_read_lock();
+	health_code_update();
 
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
@@ -976,6 +1007,7 @@ int cmd_disable_event(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	rcu_read_unlock();
 	return ret;
 }
@@ -989,6 +1021,7 @@ int cmd_disable_event_all(struct ltt_session *session, int domain,
 	int ret;
 
 	rcu_read_lock();
+	health_code_update();
 
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
@@ -1048,6 +1081,7 @@ int cmd_disable_event_all(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	rcu_read_unlock();
 	return ret;
 }
@@ -1060,6 +1094,8 @@ int cmd_add_context(struct ltt_session *session, int domain,
 {
 	int ret;
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
 		assert(session->kernel_session);
@@ -1121,6 +1157,7 @@ int cmd_add_context(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -1139,6 +1176,7 @@ int cmd_enable_event(struct ltt_session *session, int domain,
 	assert(channel_name);
 
 	rcu_read_lock();
+	health_code_update();
 
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
@@ -1233,6 +1271,7 @@ int cmd_enable_event(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	rcu_read_unlock();
 	return ret;
 }
@@ -1251,6 +1290,7 @@ int cmd_enable_event_all(struct ltt_session *session, int domain,
 	assert(channel_name);
 
 	rcu_read_lock();
+	health_code_update();
 
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
@@ -1382,6 +1422,7 @@ int cmd_enable_event_all(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	rcu_read_unlock();
 	return ret;
 }
@@ -1395,6 +1436,8 @@ ssize_t cmd_list_tracepoints(int domain, struct lttng_event **events)
 	int ret;
 	ssize_t nb_events = 0;
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
 		nb_events = kernel_list_events(kernel_tracer_fd, events);
@@ -1415,9 +1458,11 @@ ssize_t cmd_list_tracepoints(int domain, struct lttng_event **events)
 		goto error;
 	}
 
+	health_code_update();
 	return nb_events;
 
 error:
+	health_code_update();
 	/* Return negative value to differentiate return code */
 	return -ret;
 }
@@ -1431,6 +1476,8 @@ ssize_t cmd_list_tracepoint_fields(int domain,
 	int ret;
 	ssize_t nb_fields = 0;
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_UST:
 		nb_fields = ust_app_list_event_fields(fields);
@@ -1445,9 +1492,11 @@ ssize_t cmd_list_tracepoint_fields(int domain,
 		goto error;
 	}
 
+	health_code_update();
 	return nb_fields;
 
 error:
+	health_code_update();
 	/* Return negative value to differentiate return code */
 	return -ret;
 }
@@ -1463,6 +1512,8 @@ int cmd_start_trace(struct ltt_session *session)
 
 	assert(session);
 
+	health_code_update();
+
 	/* Ease our life a bit ;) */
 	ksession = session->kernel_session;
 	usess = session->ust_session;
@@ -1505,6 +1556,7 @@ int cmd_start_trace(struct ltt_session *session)
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -1520,6 +1572,8 @@ int cmd_stop_trace(struct ltt_session *session)
 
 	assert(session);
 
+	health_code_update();
+
 	/* Short cut */
 	ksession = session->kernel_session;
 	usess = session->ust_session;
@@ -1545,6 +1599,7 @@ int cmd_stop_trace(struct ltt_session *session)
 
 		/* Flush all buffers before stopping */
 		cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) {
+			health_code_update();
 			ret = kernel_flush_buffer(kchan);
 			if (ret < 0) {
 				ERR("Kernel flush buffer error");
@@ -1577,6 +1632,7 @@ int cmd_stop_trace(struct ltt_session *session)
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -1595,6 +1651,8 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session,
 	assert(uris);
 	assert(nb_uri > 0);
 
+	health_code_update();
+
 	/* Can't enable consumer after session started. */
 	if (session->enabled) {
 		ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
@@ -1698,6 +1756,7 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -1713,6 +1772,8 @@ int cmd_create_session_uri(char *name, struct lttng_uri *uris,
 
 	assert(name);
 
+	health_code_update();
+
 	/*
 	 * Verify if the session already exist
 	 *
@@ -1774,12 +1835,14 @@ int cmd_create_session_uri(char *name, struct lttng_uri *uris,
 	session->consumer->enabled = 1;
 
 end:
+	health_code_update();
 	return LTTNG_OK;
 
 consumer_error:
 	session_destroy(session);
 session_error:
 find_error:
+	health_code_update();
 	return ret;
 }
 
@@ -1795,6 +1858,8 @@ int cmd_destroy_session(struct ltt_session *session, int wpipe)
 	/* Safety net */
 	assert(session);
 
+	health_code_update();
+
 	usess = session->ust_session;
 	ksess = session->kernel_session;
 
@@ -1827,6 +1892,7 @@ int cmd_destroy_session(struct ltt_session *session, int wpipe)
 
 	ret = session_destroy(session);
 
+	health_code_update();
 	return ret;
 }
 
@@ -1837,6 +1903,8 @@ int cmd_calibrate(int domain, struct lttng_calibrate *calibrate)
 {
 	int ret;
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
 	{
@@ -1870,6 +1938,7 @@ int cmd_calibrate(int domain, struct lttng_calibrate *calibrate)
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -1886,6 +1955,8 @@ int cmd_register_consumer(struct ltt_session *session, int domain,
 	assert(cdata);
 	assert(sock_path);
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
 	{
@@ -1899,7 +1970,9 @@ int cmd_register_consumer(struct ltt_session *session, int domain,
 			goto error;
 		}
 
+		health_poll_entry();
 		sock = lttcomm_connect_unix_sock(sock_path);
+		health_poll_exit();
 		if (sock < 0) {
 			ret = LTTNG_ERR_CONNECT_FAIL;
 			goto error;
@@ -1943,6 +2016,7 @@ int cmd_register_consumer(struct ltt_session *session, int domain,
 	ret = LTTNG_OK;
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -1955,6 +2029,8 @@ ssize_t cmd_list_domains(struct ltt_session *session,
 	int ret, index = 0;
 	ssize_t nb_dom = 0;
 
+	health_code_update();
+
 	if (session->kernel_session != NULL) {
 		DBG3("Listing domains found kernel domain");
 		nb_dom++;
@@ -1981,9 +2057,11 @@ ssize_t cmd_list_domains(struct ltt_session *session,
 		index++;
 	}
 
+	health_code_update();
 	return nb_dom;
 
 error:
+	health_code_update();
 	/* Return negative value to differentiate return code */
 	return -ret;
 }
@@ -1998,6 +2076,8 @@ ssize_t cmd_list_channels(int domain, struct ltt_session *session,
 	int ret;
 	ssize_t nb_chan = 0;
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
 		if (session->kernel_session != NULL) {
@@ -2038,9 +2118,11 @@ ssize_t cmd_list_channels(int domain, struct ltt_session *session,
 		goto error;
 	}
 
+	health_code_update();
 	return nb_chan;
 
 error:
+	health_code_update();
 	/* Return negative value to differentiate return code */
 	return -ret;
 }
@@ -2054,6 +2136,8 @@ ssize_t cmd_list_events(int domain, struct ltt_session *session,
 	int ret = 0;
 	ssize_t nb_event = 0;
 
+	health_code_update();
+
 	switch (domain) {
 	case LTTNG_DOMAIN_KERNEL:
 		if (session->kernel_session != NULL) {
@@ -2074,9 +2158,11 @@ ssize_t cmd_list_events(int domain, struct ltt_session *session,
 		goto error;
 	}
 
+	health_code_update();
 	return nb_event;
 
 error:
+	health_code_update();
 	/* Return negative value to differentiate return code */
 	return -ret;
 }
@@ -2098,11 +2184,15 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid,
 
 	DBG("Getting all available session for UID %d GID %d",
 			uid, gid);
+
+	health_code_update();
+
 	/*
 	 * Iterate over session list and append data after the control struct in
 	 * the buffer.
 	 */
 	cds_list_for_each_entry(session, &list->head, list) {
+		health_code_update();
 		/*
 		 * Only list the sessions the user can control.
 		 */
@@ -2146,6 +2236,8 @@ int cmd_disable_consumer(int domain, struct ltt_session *session)
 
 	assert(session);
 
+	health_code_update();
+
 	if (session->enabled) {
 		/* Can't disable consumer on an already started session */
 		ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
@@ -2192,6 +2284,7 @@ int cmd_disable_consumer(int domain, struct ltt_session *session)
 	}
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -2207,6 +2300,8 @@ int cmd_enable_consumer(int domain, struct ltt_session *session)
 
 	assert(session);
 
+	health_code_update();
+
 	/* Can't enable consumer after session started. */
 	if (session->enabled) {
 		ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
@@ -2391,6 +2486,7 @@ int cmd_enable_consumer(int domain, struct ltt_session *session)
 	}
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -2406,6 +2502,8 @@ int cmd_data_pending(struct ltt_session *session)
 
 	assert(session);
 
+	health_code_update();
+
 	/* Session MUST be stopped to ask for data availability. */
 	if (session->enabled) {
 		ret = LTTNG_ERR_SESSION_STARTED;
@@ -2432,6 +2530,7 @@ int cmd_data_pending(struct ltt_session *session)
 	ret = 0;
 
 error:
+	health_code_update();
 	return ret;
 }
 
diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c
index 344c662..63ead50 100644
--- a/src/bin/lttng-sessiond/consumer.c
+++ b/src/bin/lttng-sessiond/consumer.c
@@ -44,7 +44,9 @@ int consumer_recv_status_reply(struct consumer_socket *sock)
 
 	assert(sock);
 
+	health_poll_entry();
 	ret = lttcomm_recv_unix_sock(sock->fd, &reply, sizeof(reply));
+	health_poll_exit();
 	if (ret <= 0) {
 		if (ret == 0) {
 			/* Orderly shutdown. Don't return 0 which means success. */
@@ -681,6 +683,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
 	assert(consumer);
 	assert(consumer_sock);
 
+	health_code_update();
+
 	/* Bail out if consumer is disabled */
 	if (!consumer->enabled) {
 		ret = LTTNG_OK;
@@ -720,6 +724,7 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
 	DBG2("Consumer relayd socket sent");
 
 error:
+	health_code_update();
 	return ret;
 }
 
@@ -817,7 +822,9 @@ int consumer_is_data_pending(unsigned int id,
 		 * the reply status message.
 		 */
 
+		health_poll_entry();
 		ret = lttcomm_recv_unix_sock(socket->fd, &ret_code, sizeof(ret_code));
+		health_poll_exit();
 		if (ret <= 0) {
 			if (ret == 0) {
 				/* Orderly shutdown. Don't return 0 which means success. */
diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c
index 461394e..603c9e8 100644
--- a/src/bin/lttng-sessiond/main.c
+++ b/src/bin/lttng-sessiond/main.c
@@ -1872,7 +1872,9 @@ static int start_consumerd(struct consumer_data *consumer_data)
 		goto error;
 	}
 
+	health_poll_entry();
 	pthread_mutex_lock(&consumer_data->pid_mutex);
+	health_poll_exit();
 	if (consumer_data->pid != 0) {
 		pthread_mutex_unlock(&consumer_data->pid_mutex);
 		goto end;
@@ -1885,6 +1887,8 @@ static int start_consumerd(struct consumer_data *consumer_data)
 		goto error;
 	}
 
+	health_code_update();
+
 	/* Setting up the consumer_data pid */
 	consumer_data->pid = ret;
 	DBG2("Consumer pid %d", consumer_data->pid);
@@ -1897,6 +1901,8 @@ static int start_consumerd(struct consumer_data *consumer_data)
 		goto error;
 	}
 
+	health_code_update();
+
 end:
 	return 0;
 
@@ -2126,6 +2132,7 @@ static int create_kernel_session(struct ltt_session *session)
 	/* Create directory(ies) on local filesystem. */
 	if (session->kernel_session->consumer->type == CONSUMER_DST_LOCAL &&
 			strlen(session->kernel_session->consumer->dst.trace_path) > 0) {
+		health_code_update();
 		ret = run_as_mkdir_recursive(
 				session->kernel_session->consumer->dst.trace_path,
 				S_IRWXU | S_IRWXG, session->uid, session->gid);
@@ -2432,6 +2439,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
 	}
 skip_domain:
 
+	health_code_update();
+
 	/* Validate consumer daemon state when start/stop trace command */
 	if (cmd_ctx->lsm->cmd_type == LTTNG_START_TRACE ||
 			cmd_ctx->lsm->cmd_type == LTTNG_STOP_TRACE) {
@@ -2630,7 +2639,9 @@ skip_domain:
 
 		/* Receive variable len data */
 		DBG("Receiving %zu URI(s) from client ...", nb_uri);
+		health_poll_entry();
 		ret = lttcomm_recv_unix_sock(sock, uris, len);
+		health_poll_exit();
 		if (ret <= 0) {
 			DBG("No URIs received from client... continuing");
 			*sock_error = 1;
@@ -2694,7 +2705,9 @@ skip_domain:
 
 			/* Receive variable len data */
 			DBG("Waiting for %zu URIs from client ...", nb_uri);
+			health_poll_entry();
 			ret = lttcomm_recv_unix_sock(sock, uris, len);
+			health_poll_exit();
 			if (ret <= 0) {
 				DBG("No URIs received from client... continuing");
 				*sock_error = 1;
@@ -2873,8 +2886,10 @@ skip_domain:
 		}
 		/* Receive var. len. data */
 		DBG("Receiving var len data from client ...");
+		health_poll_entry();
 		ret = lttcomm_recv_unix_sock(sock, bytecode,
 				cmd_ctx->lsm->u.enable.bytecode_len);
+		health_poll_exit();
 		if (ret <= 0) {
 			DBG("Nothing recv() from client var len data... continuing");
 			*sock_error = 1;
diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c
index 7d0ee7d..33dbca6 100644
--- a/src/bin/lttng-sessiond/session.c
+++ b/src/bin/lttng-sessiond/session.c
@@ -26,6 +26,7 @@
 #include <common/common.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 
+#include "health.h"
 #include "session.h"
 
 /*
@@ -83,7 +84,13 @@ struct ltt_session_list *session_get_list(void)
  */
 void session_lock_list(void)
 {
+	/*
+	 * Trying to lock this session list can take an arbitrary amount of time so
+	 * let's set the health poll execution state.
+	 */
+	health_poll_entry();
 	pthread_mutex_lock(&ltt_session_list.lock);
+	health_poll_exit();
 }
 
 /*
@@ -99,7 +106,13 @@ void session_unlock_list(void)
  */
 void session_lock(struct ltt_session *session)
 {
+	/*
+	 * Trying to lock this session list can take an arbitrary amount of time so
+	 * let's set the health poll execution state.
+	 */
+	health_poll_entry();
 	pthread_mutex_lock(&session->lock);
+	health_poll_exit();
 }
 
 /*
diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c
index 768c8f4..ebba231 100644
--- a/src/bin/lttng-sessiond/ust-consumer.c
+++ b/src/bin/lttng-sessiond/ust-consumer.c
@@ -174,6 +174,7 @@ static int send_channel_streams(struct consumer_socket *sock,
 	}
 
 	cds_list_for_each_entry_safe(stream, tmp, &uchan->streams.head, list) {
+		health_code_update();
 		if (!stream->obj->shm_fd) {
 			continue;
 		}
diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am
index 4fe494c..7ed807a 100644
--- a/tests/tools/Makefile.am
+++ b/tests/tools/Makefile.am
@@ -10,14 +10,16 @@ noinst_PROGRAMS = test_sessions test_kernel_data_trace
 UTILS=../utils.h
 SESSIONS=$(top_srcdir)/src/bin/lttng-sessiond/session.c \
 		 $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \
+		 $(top_srcdir)/src/bin/lttng-sessiond/health.c \
 		 $(top_srcdir)/src/common/uri.c \
 		 $(top_srcdir)/src/common/utils.c \
 		 $(top_srcdir)/src/common/error.c
 KERN_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-kernel.c \
 				$(top_srcdir)/src/bin/lttng-sessiond/consumer.c \
+				$(top_srcdir)/src/bin/lttng-sessiond/health.c \
 				$(top_srcdir)/src/common/uri.c \
 				$(top_srcdir)/src/common/utils.c
-COMMON=$(top_builddir)/src/common/libcommon.la
+COMMON=$(top_builddir)/src/common/libcommon.la -lrt
 HASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la
 SESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la
 
@@ -33,6 +35,7 @@ if HAVE_LIBLTTNG_UST_CTL
 noinst_PROGRAMS += test_ust_data_trace
 UST_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-ust.c \
 			   $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \
+			   $(top_srcdir)/src/bin/lttng-sessiond/health.c \
 			   $(top_srcdir)/src/common/uri.c \
 			   $(top_srcdir)/src/common/utils.c
 # UST trace data unit tests
-- 
1.7.10.4

