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