From 76f3e2db72941aa4d234ac4aef087222d30b77b7 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 10 Dec 2012 14:35:23 -0500 Subject: [PATCH] Add valgrind support for consumer The tests/consumer-valgrind is a script that starts the session daemon with valgrind support for the consumer. Output files are: /tmp/valgrind.ust32consumer.log /tmp/valgrind.ust64consumer.log /tmp/valgrind.kconsumer.log Signed-off-by: David Goulet --- src/bin/lttng-sessiond/main.c | 68 ++++++++++++++++++++++++++------ src/common/defaults.h | 3 ++ src/common/hashtable/rculfhash.c | 7 +++- tests/consumer-valgrind | 21 ++++++++++ 4 files changed, 85 insertions(+), 14 deletions(-) create mode 100755 tests/consumer-valgrind diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index c02f6d91e..ed78b5622 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -236,6 +236,9 @@ static int app_socket_timeout; /* Set in main() with the current page size. */ long page_size; +/* If set to nonzero, spawn the consumer with valgrind. */ +static int consumer_debug_valgrind; + static void setup_consumerd_path(void) { @@ -2032,11 +2035,21 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) break; } DBG("Using kernel consumer at: %s", consumer_to_use); - execl(consumer_to_use, - "lttng-consumerd", verbosity, "-k", - "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, - "--consumerd-err-sock", consumer_data->err_unix_sock_path, - NULL); + if (consumer_debug_valgrind) { + execl("/usr/bin/valgrind", + "valgrind", "--leak-check=full", "--show-reachable=yes", + "--tool=memcheck", "--track-fds=yes", + "--log-file=/tmp/valgrind.kconsumer.log", + consumer_to_use, verbosity, "-k", + "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, + "--consumerd-err-sock", consumer_data->err_unix_sock_path, + NULL); + } else { + execl(consumer_to_use, "lttng-consumerd", verbosity, "-k", + "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, + "--consumerd-err-sock", consumer_data->err_unix_sock_path, + NULL); + } break; case LTTNG_CONSUMER64_UST: { @@ -2071,10 +2084,21 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) } } DBG("Using 64-bit UST consumer at: %s", consumerd64_bin); - ret = execl(consumerd64_bin, "lttng-consumerd", verbosity, "-u", - "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, - "--consumerd-err-sock", consumer_data->err_unix_sock_path, - NULL); + if (consumer_debug_valgrind) { + ret = execl("/usr/bin/valgrind", + "valgrind", "--leak-check=full", "--show-reachable=yes", + "--tool=memcheck", "--track-fds=yes", + "--log-file=/tmp/valgrind.ust64consumer.log", + consumerd64_bin, verbosity, "-u", + "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, + "--consumerd-err-sock", consumer_data->err_unix_sock_path, + NULL); + } else { + ret = execl(consumerd64_bin, "lttng-consumerd", verbosity, "-u", + "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, + "--consumerd-err-sock", consumer_data->err_unix_sock_path, + NULL); + } if (consumerd64_libdir[0] != '\0') { free(tmpnew); } @@ -2116,10 +2140,21 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) } } DBG("Using 32-bit UST consumer at: %s", consumerd32_bin); - ret = execl(consumerd32_bin, "lttng-consumerd", verbosity, "-u", - "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, - "--consumerd-err-sock", consumer_data->err_unix_sock_path, - NULL); + if (consumer_debug_valgrind) { + ret = execl("/usr/bin/valgrind", + "valgrind", "--leak-check=full", "--show-reachable=yes", + "--tool=memcheck", "--track-fds=yes", + "--log-file=/tmp/valgrind.ust32consumer.log", + consumerd32_bin, verbosity, "-u", + "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, + "--consumerd-err-sock", consumer_data->err_unix_sock_path, + NULL); + } else { + ret = execl(consumerd32_bin, "lttng-consumerd", verbosity, "-u", + "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, + "--consumerd-err-sock", consumer_data->err_unix_sock_path, + NULL); + } if (consumerd32_libdir[0] != '\0') { free(tmpnew); } @@ -4275,6 +4310,13 @@ int main(int argc, char **argv) } } + /* Valgrind env. variable setup. */ + if (getenv(DEFAULT_CONSUMER_DEBUG_VALGRIND_ENV)) { + consumer_debug_valgrind = 1; + /* Valgrind does not support clone(). */ + setenv("LTTNG_DEBUG_NOCLONE", "1", 1); + } + /* Create thread quit pipe */ if ((ret = init_thread_quit_pipe()) < 0) { goto error; diff --git a/src/common/defaults.h b/src/common/defaults.h index 388b9f0d7..572adf1bf 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -206,6 +206,9 @@ #define DEFAULT_SNAPSHOT_NAME "snapshot" +/* Set to 1 to enable valgrind debugging for consumer. */ +#define DEFAULT_CONSUMER_DEBUG_VALGRIND_ENV "LTTNG_CONSUMER_DEBUG_VALGRIND" + extern size_t default_channel_subbuf_size; extern size_t default_metadata_subbuf_size; extern size_t default_ust_pid_channel_subbuf_size; diff --git a/src/common/hashtable/rculfhash.c b/src/common/hashtable/rculfhash.c index b430a3dec..e42c9201c 100644 --- a/src/common/hashtable/rculfhash.c +++ b/src/common/hashtable/rculfhash.c @@ -274,6 +274,7 @@ #include #include +#include #include "rculfhash.h" #include "rculfhash-internal.h" #include "urcu-flavor.h" @@ -631,7 +632,11 @@ int ht_get_split_count_index(unsigned long hash) int cpu; assert(split_count_mask >= 0); - cpu = sched_getcpu(); + if (getenv(DEFAULT_CONSUMER_DEBUG_VALGRIND_ENV)) { + cpu = 0; + } else { + cpu = sched_getcpu(); + } if (caa_unlikely(cpu < 0)) return hash & split_count_mask; else diff --git a/tests/consumer-valgrind b/tests/consumer-valgrind new file mode 100755 index 000000000..b3b9fc98b --- /dev/null +++ b/tests/consumer-valgrind @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Copyright (c) - 2012 David Goulet +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by as published by +# the Free Software Foundation; only version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +DIR=`dirname $(readlink -f $0)` + +LTTNG_CONSUMER_DEBUG_VALGRIND=1 $DIR/../src/bin/lttng-sessiond/lttng-sessiond --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" $1 -- 2.34.1