Add valgrind support for consumer valgrind
authorDavid Goulet <dgoulet@efficios.com>
Mon, 10 Dec 2012 19:35:23 +0000 (14:35 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 4 Jul 2013 19:05:39 +0000 (15:05 -0400)
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 <dgoulet@efficios.com>
src/bin/lttng-sessiond/main.c
src/common/defaults.h
src/common/hashtable/rculfhash.c
tests/consumer-valgrind [new file with mode: 0755]

index c02f6d91e2ba904819c58f3058d83efef218c6fd..ed78b5622911cfc75517814f32a17de7a1738c4d 100644 (file)
@@ -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;
index 388b9f0d78348b54ed97889139b69a720d2ebb7e..572adf1bfea82723f445642a21b1bdeedae4c4eb 100644 (file)
 
 #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;
index b430a3dec76e681ebf561f33bb9fcc767c713037..e42c9201ceac0e47b2baa7131eb0ca012af6ddf2 100644 (file)
 #include <stdio.h>
 #include <pthread.h>
 
+#include <common/defaults.h>
 #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 (executable)
index 0000000..b3b9fc9
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# Copyright (c) - 2012 David Goulet <dgoulet@efficios.com>
+#
+# 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
This page took 0.030095 seconds and 4 git commands to generate.