From 54461f0fd185f7da122b78707f97bd8fe03bc823 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 7 May 2009 16:11:38 -0400 Subject: [PATCH 01/16] add COPYING file --- COPYING | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 COPYING diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..160836e --- /dev/null +++ b/COPYING @@ -0,0 +1,16 @@ +UST - LTTng Userspace Tracer +Copyright (C) 2009 Pierre-Marc Fournier, Mathieu Desnoyers and others. + +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 the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +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. -- 2.34.1 From 7c2343de7f0d04535565637bbd52653befdc337f Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 7 May 2009 16:44:47 -0400 Subject: [PATCH 02/16] update manual --- doc/manual.lyx | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/doc/manual.lyx b/doc/manual.lyx index 47e20d6..13a6e60 100644 --- a/doc/manual.lyx +++ b/doc/manual.lyx @@ -84,7 +84,7 @@ One buffer per process (multiple threads share the same buffer) \end_layout \begin_layout Itemize -Early process tracing (from the beginning of the main() function +Early process tracing (from the beginning of the main() function) \end_layout \begin_layout Itemize @@ -96,7 +96,11 @@ Still to implement: \end_layout \begin_layout Itemize -Support of dynamic instrumentation (being implemented in +Support for dynamic instrumentation +\end_layout + +\begin_layout Itemize +Per thread or per CPU buffers \end_layout \begin_layout Standard @@ -112,6 +116,10 @@ A extension to gdb tracepoints that will allow the tracing of applications Performance \end_layout +\begin_layout Section +Installation +\end_layout + \begin_layout Section Instrumenting an Application \end_layout @@ -126,7 +134,7 @@ In order to record a trace of events occurring in a application, the application \begin_layout Standard There are no limitations on the type of code that may be instrumented. Multi-threaded programs may be instrumented without problem. - Signal handler may be instrumented as well. + Signal handlers may be instrumented as well. \end_layout \begin_layout Standard @@ -165,7 +173,7 @@ status open \begin_layout Plain Layout -void function() +int main(int argc, char **argv) \end_layout \begin_layout Plain Layout @@ -232,6 +240,15 @@ firstarg %d secondarg %s \begin_layout Plain Layout +\end_layout + +\begin_layout Plain Layout + +return 0; +\end_layout + +\begin_layout Plain Layout + } \end_layout @@ -418,6 +435,26 @@ TRACEPOINT_LIB; Compiling the Application \end_layout +\begin_layout Standard +See the +\begin_inset Quotes eld +\end_inset + +hello +\begin_inset Quotes erd +\end_inset + + directory for an example application and makefile. +\end_layout + +\begin_layout Itemize +The compiler must have access to the include path for the libust headers. +\end_layout + +\begin_layout Itemize +The application should be statically or dynamically linked to libust. +\end_layout + \begin_layout Section Recording a Trace \end_layout -- 2.34.1 From 2615de09cbdc7ef9b62db08c182bd75acfad6487 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 8 May 2009 09:36:25 -0400 Subject: [PATCH 03/16] add more readmes --- README | 37 +++++++++++++++++++++++++++++++++++++ ust/README | 3 +++ ustd/README | 3 +++ 3 files changed, 43 insertions(+) create mode 100644 README create mode 100644 ust/README create mode 100644 ustd/README diff --git a/README b/README new file mode 100644 index 0000000..18874e8 --- /dev/null +++ b/README @@ -0,0 +1,37 @@ +LTTNG USERSPACE TRACER + +NOTE: THIS LIBRARY HAS NOT BEEN RELEASED YET BECAUSE ALTOUGH IT IS LICENCED AS +LGPL, IT CAN ONLY BE USED AS GPL BECAUSE IT DEPENDS ON GPL LIBRARIES. IT WILL BE +RELEASED AS SOON AS THESE ISSUES ARE RESOLVED. + +Dependencies: + +- liburcu-pmf + Userspace RCU library, pmf patches. + http://git.dorsal.polymtl.ca + +- libkcompat + Linux kernel userspace compatibility library. + http://git.dorsal.polymtl.ca + +Package contents: + +- libust + The actual userspace tracing library that must be linked to the + instrumented programs. + +- ust + A program to control the tracing of userspace applications. It can list + markers, start the tracing, stop the tracing, enable/disable markers, etc. + +- ustd + The daemon that collects trace data and writes it to the disk. + +- Documentation + +- hello + An example application that uses the userspace tracer. + +- libmallocwrap + An example library that can be LD_PRELOAD'ed to instrument calls to malloc() + in any program without need to recompile it. diff --git a/ust/README b/ust/README new file mode 100644 index 0000000..69e513b --- /dev/null +++ b/ust/README @@ -0,0 +1,3 @@ +ust is a helper application used to control tracing on programs that support tracing. + +It can list markers, enable/disable markers, start tracing and stop tracing. diff --git a/ustd/README b/ustd/README new file mode 100644 index 0000000..8fcd218 --- /dev/null +++ b/ustd/README @@ -0,0 +1,3 @@ +This is ustd, the UST daemon. + +This daemon is used to collect the traces for the traced programs. -- 2.34.1 From 0d31b2dae761b34ba322f701ad219e8db0a63001 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 8 May 2009 17:03:01 -0400 Subject: [PATCH 04/16] configure.ac: make help and error msgs more clear --- configure.ac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index dbaa45b..e63477b 100644 --- a/configure.ac +++ b/configure.ac @@ -49,10 +49,10 @@ AC_C_INLINE AC_FUNC_MALLOC AC_CHECK_FUNCS([gettimeofday munmap socket strerror strtol]) -AC_ARG_WITH(urcu, [ --with-urcu path Path to userspace RCU source], URCU_PATH="$withval", AC_MSG_ERROR([Must specify urcu path.])) -AC_CHECK_FILE("$URCU_PATH/urcu.h", , AC_MSG_ERROR([Cannot find urcu.h in urcu directory])) -AC_ARG_WITH(kcompat, [ --with-kcompat path Path to userspace kcompat source], KCOMPAT_PATH="$withval", AC_MSG_ERROR([Must specify kcompat path.])) -AC_CHECK_FILE("$KCOMPAT_PATH/kcompat.h", , AC_MSG_ERROR([Cannot find kcompat.h in kcompat directory])) +AC_ARG_WITH(urcu, [ --with-urcu path Path to userspace RCU library source], URCU_PATH="$withval", AC_MSG_ERROR([Must specify liburcu path.])) +AC_CHECK_FILE("$URCU_PATH/urcu.h", , AC_MSG_ERROR([Cannot find urcu.h in liburcu directory])) +AC_ARG_WITH(kcompat, [ --with-kcompat path Path to libkcompat source], KCOMPAT_PATH="$withval", AC_MSG_ERROR([Must specify libkcompat path.])) +AC_CHECK_FILE("$KCOMPAT_PATH/kcompat.h", , AC_MSG_ERROR([Cannot find kcompat.h in libkcompat directory])) AC_SUBST(URCU_PATH) AC_SUBST(KCOMPAT_PATH) -- 2.34.1 From 3f05bdbd765d65a35f685c9ee3a8da5d4b8c8487 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 8 May 2009 17:03:24 -0400 Subject: [PATCH 05/16] continue work on manual --- doc/manual.lyx | 306 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 302 insertions(+), 4 deletions(-) diff --git a/doc/manual.lyx b/doc/manual.lyx index 13a6e60..5badcd3 100644 --- a/doc/manual.lyx +++ b/doc/manual.lyx @@ -1,4 +1,4 @@ -#LyX 1.6.1 created this file. For more info see http://www.lyx.org/ +#LyX 1.6.2 created this file. For more info see http://www.lyx.org/ \lyxformat 345 \begin_document \begin_header @@ -120,6 +120,109 @@ Performance Installation \end_layout +\begin_layout Subsection +Obtain the code +\end_layout + +\begin_layout Standard +To compile UST, you need: +\end_layout + +\begin_layout Itemize +the UST code +\end_layout + +\begin_layout Itemize +libkcompat +\end_layout + +\begin_layout Itemize +liburcu-pmf +\end_layout + +\begin_layout Subsection +Configure libkcompat +\end_layout + +\begin_layout Standard +Edit kcompat.h and uncomment the architecture of the target system. +\end_layout + +\begin_layout Subsection +Configure libust +\end_layout + +\begin_layout Standard +If the code was obtained through git, first generate a Makefile by running + autogen.sh. +\end_layout + +\begin_layout Standard +Then, run ./configure, specifying the directories of liburcu and libkcompat. + Example: +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +./configure --with-urcu=/home/pmf/liburcu-pmf --with-kcompat=/home/pmf/libkcompat +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Subsection +Build liburcu +\end_layout + +\begin_layout Standard +Go to the liburcu directory and run: +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +make +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Subsection +Build ust +\end_layout + +\begin_layout Standard +Go to the ust directory and run: +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +make +\end_layout + +\end_inset + + +\end_layout + \begin_layout Section Instrumenting an Application \end_layout @@ -243,8 +346,8 @@ firstarg %d secondarg %s \end_layout \begin_layout Plain Layout - -return 0; + + return 0; \end_layout \begin_layout Plain Layout @@ -459,10 +562,173 @@ The application should be statically or dynamically linked to libust. Recording a Trace \end_layout +\begin_layout Standard +These preliminary steps need to be done before recording a trace. +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +Create the directory for the communication sockets. + Eventually this should be somewhere in /var. +\end_layout + +\begin_layout Plain Layout + +$ mkdir /tmp/socks +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\begin_layout Plain Layout + +Create the directory where ustd will write the trace. + This will become configurable. +\end_layout + +\begin_layout Plain Layout + +$ mkdir /tmp/trace +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\begin_layout Plain Layout + +Start the daemon +\end_layout + +\begin_layout Plain Layout + +$ ustd +\end_layout + +\end_inset + + +\end_layout + \begin_layout Subsection Basic Recording \end_layout +\begin_layout Standard +Tracing on a running program is controlled with the ust helper program. + Ust can start the tracing, stop the tracing, enable markers, disable markers + and list the markers. + Another program, ustd, is a daemon that collects the trace events and write + them to a file. +\end_layout + +\begin_layout Standard +In order to record a trace, the daemon must first be started with the following + command. +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +ustd +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +Markers can be listed with the following command (for PID 1234). +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +ust --list-markers 1234 +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +A marker can be enabled with the following command (for PID 1234). +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +ust --enable-marker ust/mymark 1234 +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +Then, the trace can be started. +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +ust --start-trace 1234 +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +Eventually it can be stopped and destroyed. +\end_layout + +\begin_layout Standard +\begin_inset listings +inline false +status open + +\begin_layout Plain Layout + +ust --stop-trace 1234 +\end_layout + +\begin_layout Plain Layout + +ust --destroy-trace 1234 +\end_layout + +\end_inset + + +\end_layout + \begin_layout Subsection Early Tracing \end_layout @@ -493,7 +759,34 @@ status open \begin_layout Plain Layout -$ UST_TRACE=1 UST_AUTOPROBE=1 ./prog +# In another terminal, start the daemon. +\end_layout + +\begin_layout Plain Layout + +ustd +\end_layout + +\begin_layout Plain Layout + +\end_layout + +\begin_layout Plain Layout + +# Start +\begin_inset Quotes eld +\end_inset + +prog +\begin_inset Quotes erd +\end_inset + + with early tracing. +\end_layout + +\begin_layout Plain Layout + +UST_TRACE=1 UST_AUTOPROBE=1 ./prog \end_layout \end_inset @@ -534,6 +827,11 @@ Calls to uninstrumented libraries may be instrumented by creating a wrapper point. \end_layout +\begin_layout Standard +Such an example can be found in the libmallocwrap directory of the ust code + package. +\end_layout + \begin_layout Subsection Tracing Programs Without Linking them to the Tracing Library \end_layout -- 2.34.1 From d373b5cd72bd352646a1454a1f3273c67eb5ba25 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 8 May 2009 17:03:42 -0400 Subject: [PATCH 06/16] ust: improve cmd line arg help, add --help and -h --- ust/ust.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ust/ust.c b/ust/ust.c index 2f7a6bd..8752dbd 100644 --- a/ust/ust.c +++ b/ust/ust.c @@ -34,10 +34,12 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) {"enable-marker", 1, 0, 1007}, {"disable-marker", 1, 0, 1008}, {"start", 0, 0, 1009}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 1010}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "", long_options, &option_index); + c = getopt_long(argc, argv, "h", long_options, &option_index); if (c == -1) break; @@ -71,6 +73,11 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) case 1008: asprintf(&opts->cmd, "disable_marker %s", optarg); break; + case 'h': + usage(); + exit(0); + case 1010: + printf("Version 0\n"); default: /* unknown option or other error; error is printed by getopt, just return */ @@ -96,16 +103,16 @@ char *progname = NULL; void usage(void) { - fprintf(stderr, "usage: %s [OPTIONS] OPERATION PID...\n", progname); + fprintf(stderr, "usage: %s [OPTIONS] COMMAND PID...\n", progname); fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\ \n\ -Operations:\n\ -\t--start-trace\tStart tracing\n\ -\t--stop-trace\tStop tracing\n\ -\t--destroy-trace\tDestroy the trace\n\ -\t--enable-marker CHANNEL_NAME/MARKER_NAME\tEnable a marker\n\ -\t--disable-marker CHANNEL_NAME/MARKER_NAME\tDisable a marker\n\ -\t--list-markers\tList the markers of the process and their state\n\ +Commands:\n\ + --start-trace\t\t\tStart tracing\n\ + --stop-trace\t\t\tStop tracing\n\ + --destroy-trace\t\t\tDestroy the trace\n\ + --enable-marker CHANNEL/MARKER\tEnable a marker\n\ + --disable-marker CHANNEL/MARKER\tDisable a marker\n\ + --list-markers\tList the markers of the process and their state\n\ \n\ "); } -- 2.34.1 From 70551b5ea9201e5640a37f01d5b12bce1516dbb4 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 8 May 2009 17:18:01 -0400 Subject: [PATCH 07/16] configure.ac: make --help more clear --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e63477b..a7f9a73 100644 --- a/configure.ac +++ b/configure.ac @@ -49,9 +49,9 @@ AC_C_INLINE AC_FUNC_MALLOC AC_CHECK_FUNCS([gettimeofday munmap socket strerror strtol]) -AC_ARG_WITH(urcu, [ --with-urcu path Path to userspace RCU library source], URCU_PATH="$withval", AC_MSG_ERROR([Must specify liburcu path.])) +AC_ARG_WITH(urcu, [ --with-urcu=path Path to userspace RCU library source], URCU_PATH="$withval", AC_MSG_ERROR([Must specify liburcu path.])) AC_CHECK_FILE("$URCU_PATH/urcu.h", , AC_MSG_ERROR([Cannot find urcu.h in liburcu directory])) -AC_ARG_WITH(kcompat, [ --with-kcompat path Path to libkcompat source], KCOMPAT_PATH="$withval", AC_MSG_ERROR([Must specify libkcompat path.])) +AC_ARG_WITH(kcompat, [ --with-kcompat=path Path to libkcompat source], KCOMPAT_PATH="$withval", AC_MSG_ERROR([Must specify libkcompat path.])) AC_CHECK_FILE("$KCOMPAT_PATH/kcompat.h", , AC_MSG_ERROR([Cannot find kcompat.h in libkcompat directory])) AC_SUBST(URCU_PATH) AC_SUBST(KCOMPAT_PATH) -- 2.34.1 From 769d015768372ce7f68ff12bbc55aa339c3a6bcd Mon Sep 17 00:00:00 2001 From: Jan Blunck Date: Mon, 8 Jun 2009 13:19:08 -0400 Subject: [PATCH 08/16] make compatible with new version of libkcompat --- libust/channels.h | 1 - libust/marker-control.c | 2 +- libust/marker.c | 7 +++++-- libust/marker.h | 2 +- libust/relay.c | 2 +- libust/relay.h | 2 +- libust/serialize.c | 7 +++++-- libust/tracectl.c | 4 ++-- libust/tracepoint.c | 6 ++++-- libust/tracepoint.h | 2 +- libust/tracer.h | 4 ++-- libust/tracercore.h | 1 - share/kernelcompat.h | 3 +-- ust/Makefile.am | 4 ++-- ustd/Makefile.am | 2 +- 15 files changed, 27 insertions(+), 22 deletions(-) diff --git a/libust/channels.h b/libust/channels.h index dedc1f8..4eb512d 100644 --- a/libust/channels.h +++ b/libust/channels.h @@ -14,7 +14,6 @@ #include "kernelcompat.h" #include "kref.h" -#include "list.h" #define EVENTS_PER_CHANNEL 65536 diff --git a/libust/marker-control.c b/libust/marker-control.c index 29c43b0..3f11c9a 100644 --- a/libust/marker-control.c +++ b/libust/marker-control.c @@ -32,7 +32,7 @@ //ust// #include //ust// #include #include "kernelcompat.h" -#include "list.h" +//#include "list.h" #include "tracer.h" #include "localerr.h" diff --git a/libust/marker.c b/libust/marker.c index ade2d9c..0a318ac 100644 --- a/libust/marker.c +++ b/libust/marker.c @@ -30,13 +30,16 @@ //ust// #include //ust// #include -#include "marker.h" +#define _LGPL_SOURCE +#include + #include "kernelcompat.h" + +#include "marker.h" #include "usterr.h" #include "channels.h" #include "tracercore.h" #include "tracer.h" -#include "urcu.h" extern struct marker __start___markers[] __attribute__((visibility("hidden"))); extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); diff --git a/libust/marker.h b/libust/marker.h index 7c3d8c5..122fca7 100644 --- a/libust/marker.h +++ b/libust/marker.h @@ -19,7 +19,7 @@ //ust// #include #include "kernelcompat.h" #include "compiler.h" -#include "list.h" +#include //ust// struct module; //ust// struct task_struct; diff --git a/libust/relay.c b/libust/relay.c index 17f63ec..530a496 100644 --- a/libust/relay.c +++ b/libust/relay.c @@ -26,7 +26,7 @@ #include #include #include -#include "list.h" +//#include "list.h" #include "relay.h" #include "channels.h" #include "kref.h" diff --git a/libust/relay.h b/libust/relay.h index ddbb812..7d582a8 100644 --- a/libust/relay.h +++ b/libust/relay.h @@ -22,7 +22,7 @@ //ust// #include //ust// #include #include "kref.h" -#include "list.h" +//#include "list.h" #include "channels.h" /* Needs a _much_ better name... */ diff --git a/libust/serialize.c b/libust/serialize.c index 9b7fcad..00ba487 100644 --- a/libust/serialize.c +++ b/libust/serialize.c @@ -18,12 +18,15 @@ //ust// #include #include #include + #include "kernelcompat.h" +#define _LGPL_SOURCE +#include + #include "relay.h" #include "tracer.h" -#include "list.h" +//#include "list.h" #include "usterr.h" -#include "urcu.h" enum ltt_type { LTT_TYPE_SIGNED_INT, diff --git a/libust/tracectl.c b/libust/tracectl.c index b3dd4c2..3b9d3d3 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -166,7 +166,7 @@ void process_blocked_consumers(void) close(bc->fd_producer); - __list_del(bc->list.prev, bc->list.next); + list_del(&bc->list); result = ustcomm_send_reply(&bc->server, "END", &bc->src); if(result < 0) { @@ -194,7 +194,7 @@ void process_blocked_consumers(void) } free(reply); - __list_del(bc->list.prev, bc->list.next); + list_del(&bc->list); } } diff --git a/libust/tracepoint.c b/libust/tracepoint.c index 8a9ed01..ebcbe25 100644 --- a/libust/tracepoint.c +++ b/libust/tracepoint.c @@ -35,8 +35,10 @@ #include "kernelcompat.h" #include "tracepoint.h" #include "usterr.h" -#include "list.h" -#include "urcu.h" +//#include "list.h" + +#define _LGPL_SOURCE +#include //extern struct tracepoint __start___tracepoints[] __attribute__((visibility("hidden"))); //extern struct tracepoint __stop___tracepoints[] __attribute__((visibility("hidden"))); diff --git a/libust/tracepoint.h b/libust/tracepoint.h index 3b24701..81eea62 100644 --- a/libust/tracepoint.h +++ b/libust/tracepoint.h @@ -28,7 +28,7 @@ //#include //#include -#include "urcu.h" +//#include "urcu.h" #include "immediate.h" #include "kernelcompat.h" diff --git a/libust/tracer.h b/libust/tracer.h index 70d1c10..079e467 100644 --- a/libust/tracer.h +++ b/libust/tracer.h @@ -14,9 +14,9 @@ #include #include -#include "relay.h" -#include "list.h" +//#include "list.h" #include "kernelcompat.h" +#include "relay.h" #include "channels.h" #include "tracercore.h" #include "marker.h" diff --git a/libust/tracercore.h b/libust/tracercore.h index e5ff00f..dd16de3 100644 --- a/libust/tracercore.h +++ b/libust/tracercore.h @@ -7,7 +7,6 @@ #ifndef LTT_CORE_H #define LTT_CORE_H -#include "list.h" #include "kernelcompat.h" //ust// #include diff --git a/share/kernelcompat.h b/share/kernelcompat.h index 6396488..c03b408 100644 --- a/share/kernelcompat.h +++ b/share/kernelcompat.h @@ -1,10 +1,9 @@ #ifndef KERNELCOMPAT_H #define KERNELCOMPAT_H +#include #include -#include "compiler.h" - #include #include diff --git a/ust/Makefile.am b/ust/Makefile.am index e26a121..9f5a94b 100644 --- a/ust/Makefile.am +++ b/ust/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = ust ust_SOURCES = ust.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h #INCLUDES = -I$(top_builddir)/share -#INCLUDES += -I@URCU_PATH@ -INCLUDES = -I@KCOMPAT_PATH@ +INCLUDES = -I@URCU_PATH@ +INCLUDES += -I@KCOMPAT_PATH@ #INCLUDES += -I$(top_builddir)/libust INCLUDES += -I$(top_builddir)/libustcomm diff --git a/ustd/Makefile.am b/ustd/Makefile.am index f2cb959..723b9df 100644 --- a/ustd/Makefile.am +++ b/ustd/Makefile.am @@ -3,7 +3,7 @@ ustd_SOURCES = lowlevel.c localerr.h ustd.c ustd.h $(top_builddir)/libustcomm/us ustd_LDFLAGS = -lpthread INCLUDES = -I$(top_builddir)/share -#INCLUDES += -I@URCU_PATH@ +INCLUDES += -I@URCU_PATH@ INCLUDES += -I@KCOMPAT_PATH@ INCLUDES += -I$(top_builddir)/libust INCLUDES += -I$(top_builddir)/libustcomm -- 2.34.1 From fd2fb4f99b55b49eab921fd5ef174fcbb539d2cf Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Wed, 10 Jun 2009 10:28:15 -0400 Subject: [PATCH 09/16] ust: move function location to remove warning --- ust/ust.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ust/ust.c b/ust/ust.c index 8752dbd..79db498 100644 --- a/ust/ust.c +++ b/ust/ust.c @@ -12,6 +12,24 @@ struct ust_opts { int take_reply; }; +char *progname = NULL; + +void usage(void) +{ + fprintf(stderr, "usage: %s [OPTIONS] COMMAND PID...\n", progname); + fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\ +\n\ +Commands:\n\ + --start-trace\t\t\tStart tracing\n\ + --stop-trace\t\t\tStop tracing\n\ + --destroy-trace\t\t\tDestroy the trace\n\ + --enable-marker CHANNEL/MARKER\tEnable a marker\n\ + --disable-marker CHANNEL/MARKER\tDisable a marker\n\ + --list-markers\tList the markers of the process and their state\n\ +\n\ +"); +} + int parse_opts_long(int argc, char **argv, struct ust_opts *opts) { int c; @@ -99,24 +117,6 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) return 0; } -char *progname = NULL; - -void usage(void) -{ - fprintf(stderr, "usage: %s [OPTIONS] COMMAND PID...\n", progname); - fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\ -\n\ -Commands:\n\ - --start-trace\t\t\tStart tracing\n\ - --stop-trace\t\t\tStop tracing\n\ - --destroy-trace\t\t\tDestroy the trace\n\ - --enable-marker CHANNEL/MARKER\tEnable a marker\n\ - --disable-marker CHANNEL/MARKER\tDisable a marker\n\ - --list-markers\tList the markers of the process and their state\n\ -\n\ -"); -} - int main(int argc, char *argv[]) { pid_t *pidit; -- 2.34.1 From a6de76185dd1e98838d6801e34356f012df7544c Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 11 Jun 2009 13:38:27 -0400 Subject: [PATCH 10/16] libust: put offset macros in buffer.h This is to resolve a dependency issue. --- libust/buffer.h | 22 ++++++++++++++++++++++ libust/tracer.h | 18 +----------------- 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 libust/buffer.h diff --git a/libust/buffer.h b/libust/buffer.h new file mode 100644 index 0000000..c974a0b --- /dev/null +++ b/libust/buffer.h @@ -0,0 +1,22 @@ +#ifndef UST_BUFFER_H +#define UST_BUFFER_H + +/* Buffer offset macros */ + +/* + * BUFFER_TRUNC zeroes the subbuffer offset and the subbuffer number parts of + * the offset, which leaves only the buffer number. + */ +#define BUFFER_TRUNC(offset, chan) \ + ((offset) & (~((chan)->alloc_size-1))) +#define BUFFER_OFFSET(offset, chan) ((offset) & ((chan)->alloc_size - 1)) +#define SUBBUF_OFFSET(offset, chan) ((offset) & ((chan)->subbuf_size - 1)) +#define SUBBUF_ALIGN(offset, chan) \ + (((offset) + (chan)->subbuf_size) & (~((chan)->subbuf_size - 1))) +#define SUBBUF_TRUNC(offset, chan) \ + ((offset) & (~((chan)->subbuf_size - 1))) +#define SUBBUF_INDEX(offset, chan) \ + (BUFFER_OFFSET((offset), chan) >> (chan)->subbuf_size_order) + + +#endif /* UST_BUFFER_H */ diff --git a/libust/tracer.h b/libust/tracer.h index 079e467..1644327 100644 --- a/libust/tracer.h +++ b/libust/tracer.h @@ -16,6 +16,7 @@ #include //#include "list.h" #include "kernelcompat.h" +#include "buffer.h" #include "relay.h" #include "channels.h" #include "tracercore.h" @@ -430,23 +431,6 @@ static inline size_t ltt_write_event_header(struct ltt_trace_struct *trace, /* Lockless LTTng */ -/* Buffer offset macros */ - -/* - * BUFFER_TRUNC zeroes the subbuffer offset and the subbuffer number parts of - * the offset, which leaves only the buffer number. - */ -#define BUFFER_TRUNC(offset, chan) \ - ((offset) & (~((chan)->alloc_size-1))) -#define BUFFER_OFFSET(offset, chan) ((offset) & ((chan)->alloc_size - 1)) -#define SUBBUF_OFFSET(offset, chan) ((offset) & ((chan)->subbuf_size - 1)) -#define SUBBUF_ALIGN(offset, chan) \ - (((offset) + (chan)->subbuf_size) & (~((chan)->subbuf_size - 1))) -#define SUBBUF_TRUNC(offset, chan) \ - ((offset) & (~((chan)->subbuf_size - 1))) -#define SUBBUF_INDEX(offset, chan) \ - (BUFFER_OFFSET((offset), chan) >> (chan)->subbuf_size_order) - /* * ltt_reserve_slot * -- 2.34.1 From 64d9b80b1e4dfbb0c8329ed950d1c0d4de3e4c7a Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 11 Jun 2009 14:02:21 -0400 Subject: [PATCH 11/16] libust: fix problem in computation of offset in buffer --- libust/relay.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libust/relay.h b/libust/relay.h index 7d582a8..6b3a8b7 100644 --- a/libust/relay.h +++ b/libust/relay.h @@ -21,6 +21,8 @@ //ust// #include //ust// #include //ust// #include +#include +#include "tracer.h" #include "kref.h" //#include "list.h" #include "channels.h" @@ -290,13 +292,16 @@ static inline int ltt_relay_write(struct rchan_buf *buf, size_t offset, //ust// _ltt_relay_write(buf, offset, src, len, page, pagecpy); //ust// return len; - size_t cpy; - cpy = min_t(size_t, len, buf->buf_size - offset); - ltt_relay_do_copy(buf->buf_data + offset, src, cpy); + size_t buf_offset = BUFFER_OFFSET(offset, buf->chan); + + assert(buf_offset < buf->chan->subbuf_size*buf->chan->n_subbufs); + + cpy = min_t(size_t, len, buf->buf_size - buf_offset); + ltt_relay_do_copy(buf->buf_data + buf_offset, src, cpy); if (unlikely(len != cpy)) - _ltt_relay_write(buf, offset, src, len, cpy); + _ltt_relay_write(buf, buf_offset, src, len, cpy); return len; } -- 2.34.1 From 0a58610fc313f7f8a0d7be5ac56154a56ab7a79f Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 12 Jun 2009 01:41:10 -0400 Subject: [PATCH 12/16] tracectl.c: send error when put_subbuf fails this happens when the reader is pushed by a write --- libust/tracectl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libust/tracectl.c b/libust/tracectl.c index 3b9d3d3..8be2cd0 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -570,12 +570,13 @@ int listener_main(void *p) result = ltt_do_put_subbuf(rbuf, lttbuf, consumed_old); if(result < 0) { - WARN("ltt_do_put_subbuf: error"); + WARN("ltt_do_put_subbuf: error (subbuf=%s)", channel_name); + asprintf(&reply, "%s", "ERROR", consumed_old); } else { - DBG("ltt_do_put_subbuf: success"); + DBG("ltt_do_put_subbuf: success (subbuf=%s)", channel_name); + asprintf(&reply, "%s", "OK", consumed_old); } - asprintf(&reply, "%s", "OK", consumed_old); result = ustcomm_send_reply(&ustcomm_app.server, reply, &src); if(result) { -- 2.34.1 From 0d6c445c5bd70d1c52b5378f7bf1a95661ce4873 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 12 Jun 2009 01:42:12 -0400 Subject: [PATCH 13/16] hello/run: update library paths --- hello/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello/run b/hello/run index ecc0bf2..c2655f6 100755 --- a/hello/run +++ b/hello/run @@ -1,3 +1,3 @@ #!/bin/sh -UST_AUTOPROBE=1 UST_TRACE=1 LD_LIBRARY_PATH=../libtracectl:../libmarkers:../libtracing $1 ./hello +UST_AUTOPROBE=1 UST_TRACE=1 LD_LIBRARY_PATH=../libust/.libs $1 .libs/hello -- 2.34.1 From 7add38980ed134a423ff02bb553efcb5f930eda9 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 12 Jun 2009 01:46:16 -0400 Subject: [PATCH 14/16] relay.h: change includes --- libust/relay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libust/relay.h b/libust/relay.h index 6b3a8b7..3df1275 100644 --- a/libust/relay.h +++ b/libust/relay.h @@ -22,10 +22,10 @@ //ust// #include //ust// #include #include -#include "tracer.h" #include "kref.h" //#include "list.h" #include "channels.h" +#include "buffer.h" /* Needs a _much_ better name... */ #define FIX_SIZE(x) ((((x) - 1) & PAGE_MASK) + PAGE_SIZE) -- 2.34.1 From 899b596702867527642bc495819239ecaee6526d Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 12 Jun 2009 01:48:03 -0400 Subject: [PATCH 15/16] libust: deactivate trace-stopping destructor --- libust/tracectl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libust/tracectl.c b/libust/tracectl.c index 8be2cd0..e9907fc 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -871,6 +871,8 @@ static void __attribute__((constructor(1000))) init() /* This is only called if we terminate normally, not with an unhandled signal, * so we cannot rely on it. */ +/* This destructor probably isn't needed, because ustd can do crash recovery. */ +#if 0 static void __attribute__((destructor)) fini() { int result; @@ -889,9 +891,6 @@ static void __attribute__((destructor)) fini() ERR("ltt_trace_destroy error"); } - /* FIXME: wait for the consumer to be done */ - //DBG("waiting 5 sec for consume"); - //sleep(5); - destroy_socket(); } +#endif -- 2.34.1 From d748a7de2e2a43fb576d67668a8c105f863051e7 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Fri, 12 Jun 2009 01:54:25 -0400 Subject: [PATCH 16/16] ustd/lowlevel.c: make the post crash buffer recovery more robust --- ustd/lowlevel.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/ustd/lowlevel.c b/ustd/lowlevel.c index 7c5dc3d..ff38759 100644 --- a/ustd/lowlevel.c +++ b/ustd/lowlevel.c @@ -4,6 +4,7 @@ #include "ustd.h" #include "localerr.h" +/* This truncates to an offset in the buffer. */ #define USTD_BUFFER_TRUNC(offset, bufinfo) \ ((offset) & (~(((bufinfo)->subbuf_size*(bufinfo)->n_subbufs)-1))) @@ -20,40 +21,61 @@ void finish_consuming_dead_subbuffer(struct buffer_info *buf) DBG("consumed offset is %ld", consumed_offset); DBG("write offset is %ld", write_offset); + /* First subbuf that we need to consume now. It is not modulo'd. + * Consumed_offset is the next byte to consume. */ long first_subbuf = consumed_offset / buf->subbuf_size; - long last_subbuf = write_offset / buf->subbuf_size; + /* Last subbuf that we need to consume now. It is not modulo'd. + * Write_offset is the next place to write so write_offset-1 is the + * last place written. */ + long last_subbuf = (write_offset - 1) / buf->subbuf_size; - if(last_subbuf - first_subbuf > buf->n_subbufs) { + DBG("first_subbuf=%d", first_subbuf); + DBG("last_subbuf=%d", last_subbuf); + + if(last_subbuf - first_subbuf >= buf->n_subbufs) { DBG("an overflow has occurred, nothing can be recovered"); return; } + /* Iterate on subbuffers to recover. */ for(i_subbuf=first_subbuf; ; i_subbuf++, i_subbuf %= buf->n_subbufs) { void *tmp; + /* commit_seq is the offset in the buffer of the end of the last sequential commit. + * Bytes beyond this limit cannot be recovered. This is a free-running counter. */ long commit_seq = local_read(<t_buf->commit_seq[i_subbuf]); unsigned long valid_length = buf->subbuf_size; long n_subbufs_order = get_count_order(buf->n_subbufs); long commit_seq_mask = (~0UL >> n_subbufs_order); - if((commit_seq & commit_seq_mask) == 0) + struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem+i_subbuf*buf->subbuf_size); + + if((commit_seq & commit_seq_mask) == 0) { + /* There is nothing to do. */ + /* FIXME: is this needed? */ break; + } - /* check if subbuf was fully written */ - if (!((commit_seq - buf->subbuf_size) & commit_seq_mask) + /* Check if subbuf was fully written. This is from Mathieu's algorithm/paper. */ + if (((commit_seq - buf->subbuf_size) & commit_seq_mask) - (USTD_BUFFER_TRUNC(consumed_offset, buf) >> n_subbufs_order) - != 0) { - struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size; + == 0) { + /* If it was, we only check the lost_size. This is the lost padding at the end of + * the subbuffer. */ valid_length = (unsigned long)buf->subbuf_size - header->lost_size; } else { - struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size; + /* If the subbuffer was not fully written, then we don't check lost_size because + * it hasn't been written yet. Instead we check commit_seq and use it to choose + * a value for lost_size. The viewer will need this value when parsing. + */ - valid_length = commit_seq; + valid_length = commit_seq & (buf->subbuf_size-1); header->lost_size = buf->subbuf_size-valid_length; - assert(i_subbuf == last_subbuf); + assert(i_subbuf == (last_subbuf % buf->n_subbufs)); } + patient_write(buf->file_fd, buf->mem + i_subbuf * buf->subbuf_size, valid_length); /* pad with empty bytes */ @@ -62,7 +84,7 @@ void finish_consuming_dead_subbuffer(struct buffer_info *buf) patient_write(buf->file_fd, tmp, buf->subbuf_size-valid_length); free(tmp); - if(i_subbuf == last_subbuf) + if(i_subbuf == last_subbuf % buf->n_subbufs) break; } } -- 2.34.1