From: Mathieu Desnoyers Date: Tue, 9 Jun 2015 13:55:07 +0000 (+0200) Subject: Implement demo-tracelog example X-Git-Tag: v2.7.0-rc1~33 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=eb8246a0e43cf5a762dfeb47746c8788f8594277;p=lttng-ust.git Implement demo-tracelog example Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am index 0ae14b98..0d226021 100644 --- a/doc/examples/Makefile.am +++ b/doc/examples/Makefile.am @@ -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 index 00000000..cc6843a8 --- /dev/null +++ b/doc/examples/demo-tracelog/Makefile @@ -0,0 +1,38 @@ +# Copyright (C) 2013 Jérémie Galarneau +# Copyright (C) 2014 Mathieu Desnoyers +# +# 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 index 00000000..46fe7679 --- /dev/null +++ b/doc/examples/demo-tracelog/README @@ -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 index 00000000..aeeb6211 --- /dev/null +++ b/doc/examples/demo-tracelog/demo-tracelog.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011-2014 Mathieu Desnoyers + * + * 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 +#include +#include + +#include + +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; +}