add usttrace script
[lttng-ust.git] / usttrace
CommitLineData
eb6adb25
PMF
1#!/bin/bash
2
3USTD="./ustd/ustd"
4LIBINTERFORK="./libinterfork/.libs/libinterfork.so"
5
6BASE_TRACE_DIR="$HOME/.usttraces"
7
8function usage () {
9 echo "usage: $0 COMMAND" 2>/dev/stderr
10}
11
12function error() {
13 echo "$0: error: $1" 2>/dev/stderr
14}
15
16# Prepare vars
17CMD=$1
18
19# Validate input
20if [ -z "$HOME" ];
21then
22 error "no home specified"
23fi
24
25if [ -z "$CMD" ];
26then
27 error "no command specified"
28 usage;
29 exit 1
30fi
31
32# Create directory for trace output
33DATESTRING="$(hostname)-$(date +%Y%m%d%H%M%S)"
34OUTDIR="$BASE_TRACE_DIR/$DATESTRING"
35mkdir -p "$OUTDIR"
36
37# Choose socket path
38SOCKPATH="/tmp/ust-sock-$$"
39
40# Start daemon
41$USTD -s "$SOCKPATH" -o "$OUTDIR" >"$OUTDIR/ustd.log" 2>&1 &
42USTDPID=$!
43
44# Establish the environment for the command
45export UST_TRACE=1
46export UST_AUTOPROBE=1
47export UST_DAEMON_SOCKET="$SOCKPATH"
48
49# Execute the command
50bash -c "$CMD"
51
52## Because of the keepalive mechanism, we're sure that by the time
53## we get here, the daemon is connected to all the buffers that still exist.
54## Therefore we can politely ask it to die when it's done.
55
56kill -SIGTERM "$USTDPID"
57
58# Tell the daemon to die
59echo "Waiting for ustd to shutdown..."
60wait "$USTDPID"
This page took 0.025393 seconds and 4 git commands to generate.