From 4d5f8223acb7ab90af7fc4b8aa1c391838c1af21 Mon Sep 17 00:00:00 2001 From: Manuel Traut Date: Fri, 25 Aug 2017 15:44:50 +0200 Subject: add a userspace tracing example using lttng-ust, perf and tshark traces can be shown in tracecompass Signed-off-by: Manuel Traut --- application-devel/tracing/lttng-c/AUTHORS | 0 application-devel/tracing/lttng-c/ChangeLog | 0 application-devel/tracing/lttng-c/Makefile.am | 4 ++ application-devel/tracing/lttng-c/NEWS | 0 application-devel/tracing/lttng-c/README | 0 application-devel/tracing/lttng-c/configure.ac | 25 +++++++++ application-devel/tracing/lttng-c/hello-tp.c | 4 ++ application-devel/tracing/lttng-c/hello-tp.h | 27 ++++++++++ application-devel/tracing/lttng-c/hellolttngust.c | 42 +++++++++++++++ application-devel/tracing/lttng-c/trace.sh | 62 +++++++++++++++++++++++ lx-trainer-vm/lx-trainer-vm.xml | 5 +- 11 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 application-devel/tracing/lttng-c/AUTHORS create mode 100644 application-devel/tracing/lttng-c/ChangeLog create mode 100644 application-devel/tracing/lttng-c/Makefile.am create mode 100644 application-devel/tracing/lttng-c/NEWS create mode 100644 application-devel/tracing/lttng-c/README create mode 100644 application-devel/tracing/lttng-c/configure.ac create mode 100644 application-devel/tracing/lttng-c/hello-tp.c create mode 100644 application-devel/tracing/lttng-c/hello-tp.h create mode 100644 application-devel/tracing/lttng-c/hellolttngust.c create mode 100755 application-devel/tracing/lttng-c/trace.sh diff --git a/application-devel/tracing/lttng-c/AUTHORS b/application-devel/tracing/lttng-c/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/application-devel/tracing/lttng-c/ChangeLog b/application-devel/tracing/lttng-c/ChangeLog new file mode 100644 index 0000000..e69de29 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 diff --git a/application-devel/tracing/lttng-c/README b/application-devel/tracing/lttng-c/README new file mode 100644 index 0000000..e69de29 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 + +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 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 +#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/* diff --git a/lx-trainer-vm/lx-trainer-vm.xml b/lx-trainer-vm/lx-trainer-vm.xml index 42c38fe..e9933e2 100644 --- a/lx-trainer-vm/lx-trainer-vm.xml +++ b/lx-trainer-vm/lx-trainer-vm.xml @@ -135,7 +135,7 @@ cp -a /etc/default/useradd /etc/default/useradd.orig echo 'SKEL=/etc/skel.devel' | tee -a /etc/default/useradd - devel + devel mv -f /etc/default/useradd.orig /etc/default/useradd var/cache/apt/archives/*.deb @@ -197,6 +197,9 @@ tftpd-hpa strace ltrace + liblttng-ust-dev + lttng-tools + tshark gdb gdbserver rt-tests -- cgit v1.2.3