Implement demo-tracelog example
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 9 Jun 2015 13:55:07 +0000 (15:55 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 9 Jun 2015 14:22:41 +0000 (16:22 +0200)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
doc/examples/Makefile.am
doc/examples/demo-tracelog/Makefile [new file with mode: 0644]
doc/examples/demo-tracelog/README [new file with mode: 0644]
doc/examples/demo-tracelog/demo-tracelog.c [new file with mode: 0644]

index 0ae14b98eb00ad330b1fdf0bd1cf25987a571f4f..0d226021adfb32149b93aa2f210304ef049c33a3 100644 (file)
@@ -4,6 +4,7 @@ doc_examples_gen_tpdir = ${docdir}/examples/gen-tp
 doc_examples_demodir = ${docdir}/examples/demo
 doc_examples_hello_static_libdir = ${docdir}/examples/hello-static-lib
 doc_examples_demo_tracefdir = ${docdir}/examples/demo-tracef
+doc_examples_demo_tracelogdir = ${docdir}/examples/demo-tracelog
 doc_examples_clock_overridedir = ${docdir}/examples/clock-override
 doc_examples_getcpu_overridedir = ${docdir}/examples/getcpu-override
 
@@ -45,6 +46,10 @@ dist_doc_examples_demo_tracef_DATA = demo-tracef/Makefile \
        demo-tracef/demo-tracef.c \
        demo-tracef/README
 
+dist_doc_examples_demo_tracelog_DATA = demo-tracelog/Makefile \
+       demo-tracelog/demo-tracelog.c \
+       demo-tracelog/README
+
 dist_doc_examples_clock_override_DATA = clock-override/Makefile \
        clock-override/lttng-ust-clock-override-example.c \
        clock-override/run-clock-override \
@@ -61,7 +66,7 @@ if NO_SHARED
 else
 # Copies are for VPATH build support
 SUBDIRS_PROXY = easy-ust demo hello-static-lib demo-tracef clock-override \
-               getcpu-override
+               getcpu-override demo-tracelog
 
 if BUILD_GEN_TP_EXAMPLES
 SUBDIRS_PROXY += gen-tp
diff --git a/doc/examples/demo-tracelog/Makefile b/doc/examples/demo-tracelog/Makefile
new file mode 100644 (file)
index 0000000..cc6843a
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2013  Jérémie Galarneau <jeremie.galarneau@efficios.com>
+# Copyright (C) 2014  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+#
+# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+# OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
+#
+# Permission is hereby granted to use or copy this program for any
+# purpose, provided the above notices are retained on all copies.
+# Permission to modify the code and to distribute modified code is
+# granted, provided the above notices are retained, and a notice that
+# the code was modified is included with the above copyright notice.
+#
+# This Makefile is not using automake so that users may see how to build
+# a program with tracepoint provider probes as stand-alone shared objects.
+#
+# This makefile is purposefully kept simple to support GNU and BSD make.
+
+ifdef AM_CC
+       CC = $(AM_CC)
+endif
+
+LIBS = -ldl -llttng-ust        # On Linux
+#LIBS = -lc    # On BSD
+LOCAL_CPPFLAGS += -I.
+
+all: demo-tracelog
+
+demo-tracelog.o: demo-tracelog.c
+       $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) $(AM_CPPFLAGS) \
+               $(AM_CFLAGS) -c -o $@ $<
+
+demo-tracelog: demo-tracelog.o
+       $(CC) $(LDFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(AM_CFLAGS) \
+               -o $@ $< $(LIBS)
+
+.PHONY: clean
+clean:
+       rm -f *.o *.a demo-tracelog
diff --git a/doc/examples/demo-tracelog/README b/doc/examples/demo-tracelog/README
new file mode 100644 (file)
index 0000000..46fe767
--- /dev/null
@@ -0,0 +1,20 @@
+This is a demo application showing how to trace logging statements into
+LTTng-UST.
+
+The simplest commands to trace the demo program are:
+
+lttng create
+lttng enable-event -u "lttng_ust_tracelog:*"
+lttng start
+./demo-tracelog
+lttng stop
+lttng view
+lttng destroy
+
+The resulting lttng view output should look like this:
+
+[15:54:19.454863179] (+?.?????????) thinkos lttng_ust_tracelog:err: { cpu_id = 0 }, { line = 45, file = "demo-tracelog.c", func = "main", _msg_length = 17, msg = "Error condition 0" }
+[15:54:19.454871660] (+0.000008481) thinkos lttng_ust_tracelog:err: { cpu_id = 0 }, { line = 45, file = "demo-tracelog.c", func = "main", _msg_length = 17, msg = "Error condition 1" }
+[15:54:19.454872838] (+0.000001178) thinkos lttng_ust_tracelog:err: { cpu_id = 0 }, { line = 45, file = "demo-tracelog.c", func = "main", _msg_length = 17, msg = "Error condition 2" }
+[15:54:19.454873541] (+0.000000703) thinkos lttng_ust_tracelog:err: { cpu_id = 0 }, { line = 45, file = "demo-tracelog.c", func = "main", _msg_length = 17, msg = "Error condition 3" }
+[15:54:19.454874283] (+0.000000742) thinkos lttng_ust_tracelog:err: { cpu_id = 0 }, { line = 45, file = "demo-tracelog.c", func = "main", _msg_length = 17, msg = "Error condition 4" }
diff --git a/doc/examples/demo-tracelog/demo-tracelog.c b/doc/examples/demo-tracelog/demo-tracelog.c
new file mode 100644 (file)
index 0000000..aeeb621
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009  Pierre-Marc Fournier
+ * Copyright (C) 2011-2014  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1 of
+ * the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <lttng/tracelog.h>
+
+int main(int argc, char **argv)
+{
+       int i;
+       int delay = 0;
+
+       if (argc == 2)
+               delay = atoi(argv[1]);
+
+       fprintf(stderr, "Demo program starting.\n");
+
+       sleep(delay);
+
+       fprintf(stderr, "Tracing... ");
+       for (i = 0; i < 5; i++) {
+               tracelog(err, "Error condition %d", i);
+       }
+       fprintf(stderr, " done.\n");
+       return 0;
+}
This page took 0.027291 seconds and 4 git commands to generate.