diff options
| author | Manuel Traut <manut@linutronix.de> | 2017-08-25 15:44:50 +0200 |
|---|---|---|
| committer | John Ogness <john.ogness@linutronix.de> | 2017-12-19 11:38:06 +0100 |
| commit | 4d5f8223acb7ab90af7fc4b8aa1c391838c1af21 (patch) | |
| tree | 63ee8b04ff3285c73832058fb064f883bdc15574 /application-devel | |
| parent | 77a4d59ce232c27b63068390401e723488630c3c (diff) | |
add a userspace tracing example
using lttng-ust, perf and tshark
traces can be shown in tracecompass
Signed-off-by: Manuel Traut <manut@linutronix.de>
Diffstat (limited to 'application-devel')
| -rw-r--r-- | application-devel/tracing/lttng-c/AUTHORS | 0 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/ChangeLog | 0 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/Makefile.am | 4 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/NEWS | 0 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/README | 0 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/configure.ac | 25 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/hello-tp.c | 4 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/hello-tp.h | 27 | ||||
| -rw-r--r-- | application-devel/tracing/lttng-c/hellolttngust.c | 42 | ||||
| -rwxr-xr-x | application-devel/tracing/lttng-c/trace.sh | 62 |
10 files changed, 164 insertions, 0 deletions
diff --git a/application-devel/tracing/lttng-c/AUTHORS b/application-devel/tracing/lttng-c/AUTHORS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/application-devel/tracing/lttng-c/AUTHORS diff --git a/application-devel/tracing/lttng-c/ChangeLog b/application-devel/tracing/lttng-c/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/application-devel/tracing/lttng-c/ChangeLog diff --git a/application-devel/tracing/lttng-c/Makefile.am b/application-devel/tracing/lttng-c/Makefile.am new file mode 100644 index 0000000..67f30b0 --- /dev/null +++ b/application-devel/tracing/lttng-c/Makefile.am @@ -0,0 +1,4 @@ +bin_PROGRAMS = hellolttngust +hellolttngust_SOURCES = hello-tp.c hellolttngust.c +hellolttngust_LDFLAGS = @LTTNG_LIBS@ +hellolttngust_CFLAGS = -g -Wall -Werror diff --git a/application-devel/tracing/lttng-c/NEWS b/application-devel/tracing/lttng-c/NEWS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/application-devel/tracing/lttng-c/NEWS diff --git a/application-devel/tracing/lttng-c/README b/application-devel/tracing/lttng-c/README new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/application-devel/tracing/lttng-c/README diff --git a/application-devel/tracing/lttng-c/configure.ac b/application-devel/tracing/lttng-c/configure.ac new file mode 100644 index 0000000..8269e50 --- /dev/null +++ b/application-devel/tracing/lttng-c/configure.ac @@ -0,0 +1,25 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([hello-lttngust], [1.0], [manut@linutronix.de]) +AM_INIT_AUTOMAKE +AC_CONFIG_SRCDIR([hello-tp.c]) +AC_CONFIG_HEADERS([config.h]) + +# Checks for programs. +AC_PROG_CC + +# Checks for libraries. +# FIXME: Replace `main' with a function in `-ldl': +AC_CHECK_LIB([dl], [dlopen]) +PKG_CHECK_MODULES(LTTNG, lttng-ust) + +# Checks for header files. + +# Checks for typedefs, structures, and compiler characteristics. + +# Checks for library functions. + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/application-devel/tracing/lttng-c/hello-tp.c b/application-devel/tracing/lttng-c/hello-tp.c new file mode 100644 index 0000000..e81db08 --- /dev/null +++ b/application-devel/tracing/lttng-c/hello-tp.c @@ -0,0 +1,4 @@ +#define TRACEPOINT_CREATE_PROBES +#define TRACEPOINT_DEFINE + +#include "hello-tp.h" diff --git a/application-devel/tracing/lttng-c/hello-tp.h b/application-devel/tracing/lttng-c/hello-tp.h new file mode 100644 index 0000000..6481d22 --- /dev/null +++ b/application-devel/tracing/lttng-c/hello-tp.h @@ -0,0 +1,27 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER hello_world + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./hello-tp.h" + +#if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _HELLO_TP_H + +#include <lttng/tracepoint.h> + +TRACEPOINT_EVENT( + hello_world, + my_first_tracepoint, + TP_ARGS( + int, my_integer_arg, + char*, my_string_arg + ), + TP_FIELDS( + ctf_string(my_string_field, my_string_arg) + ctf_integer(int, my_integer_field, my_integer_arg) + ) +) + +#endif /* _HELLO_TP_H */ + +#include <lttng/tracepoint-event.h> diff --git a/application-devel/tracing/lttng-c/hellolttngust.c b/application-devel/tracing/lttng-c/hellolttngust.c new file mode 100644 index 0000000..11c8bd7 --- /dev/null +++ b/application-devel/tracing/lttng-c/hellolttngust.c @@ -0,0 +1,42 @@ +#include <stdio.h> +#include "hello-tp.h" + +int main(int argc, char *argv[]) +{ + int x; + + puts("Hello, World!\nPress Enter to continue..."); + + /* + * The following getchar() call is only placed here for the purpose + * of this demonstration, to pause the application in order for + * you to have time to list its tracepoints. It is not + * needed otherwise. + */ + getchar(); + + /* + * A tracepoint() call. + * + * Arguments, as defined in hello-tp.h: + * + * 1. Tracepoint provider name (required) + * 2. Tracepoint name (required) + * 3. my_integer_arg (first user-defined argument) + * 4. my_string_arg (second user-defined argument) + * + * Notice the tracepoint provider and tracepoint names are + * NOT strings: they are in fact parts of variables that the + * macros in hello-tp.h create. + */ + tracepoint(hello_world, my_first_tracepoint, 23, "hi there!"); + + for (x = 0; x < argc; ++x) { + tracepoint(hello_world, my_first_tracepoint, x, argv[x]); + } + + puts("Quitting now!"); + tracepoint(hello_world, my_first_tracepoint, x * x, "x^2"); + + return 0; +} diff --git a/application-devel/tracing/lttng-c/trace.sh b/application-devel/tracing/lttng-c/trace.sh new file mode 100755 index 0000000..5a52bee --- /dev/null +++ b/application-devel/tracing/lttng-c/trace.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +USERID=`id -u` +TSTAMP=`date +%Y%m%d-%H%M%S` +UDIR=$HOME +CURDIR=`pwd` + +PERF_VERSION="$(uname -r)" +PERF_VERSION="${PERF_VERSION%%-*}" +case "$PERF_VERSION" in + *.*.*) + PERF_VERSION="${PERF_VERSION%.*}" + ;; +esac + + +sudo modprobe usbmon + +tshark -F pcap -i eth0 -w ~/lttng-traces/network-$TSTAMP.pcap & +#sudo and -F pcap is not working atm sudo is needed for usbmon +#sudo tshark -F pcap -i usbmon0 -w ~/lttng-traces/usb-$TSTAMP.pcap & + +lttng create lttng-ust +lttng list --userspace +lttng enable-event --userspace hello_world:my_first_tracepoint +lttng start + +mkdir -p uprobe-traces +cd uprobe-traces +sudo perf probe -x $CURDIR/hellolttngust MYEVENT=$CURDIR/hellolttngust.c:8 +sudo perf probe -x $CURDIR/hellolttngust EVNAME=$CURDIR/hellolttngust.c:35 +sudo perf record -e probe_hellolttngust:MYEVENT -e probe_hellolttngust:EVNAME & +cd - + +mkdir -p kernel-traces +cd kernel-traces +sudo perf record -e sched:sched_switch & +cd - + +./hellolttngust huhu haha hihi + +sudo killall perf_$PERF_VERSION +killall tshark +#sudo killall tshark + +lttng stop +lttng destroy + +echo wait for writing perf data +wait + +cd uprobe-traces +sudo perf data convert --to-ctf=$UDIR/lttng-traces/perf-uprobes-$TSTAMP +sudo perf probe -d probe_hellolttngust:MYEVENT +sudo perf probe -d probe_hellolttngust:EVNAME +cd - + +cd kernel-traces +sudo perf data convert --to-ctf=$UDIR/lttng-traces/perf-kernel-$TSTAMP +cd - + +sudo chown -R $USERID $UDIR/lttng-traces/* |
