add usttrace script
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 9 Sep 2009 17:32:45 +0000 (13:32 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 9 Sep 2009 17:32:45 +0000 (13:32 -0400)
usttrace [new file with mode: 0755]

diff --git a/usttrace b/usttrace
new file mode 100755 (executable)
index 0000000..385abc6
--- /dev/null
+++ b/usttrace
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+USTD="./ustd/ustd"
+LIBINTERFORK="./libinterfork/.libs/libinterfork.so"
+
+BASE_TRACE_DIR="$HOME/.usttraces"
+
+function usage () {
+       echo "usage:  $0 COMMAND" 2>/dev/stderr
+}
+
+function error() {
+       echo "$0: error: $1" 2>/dev/stderr
+}
+
+# Prepare vars
+CMD=$1
+
+# Validate input
+if [ -z "$HOME" ];
+then
+       error "no home specified"
+fi
+
+if [ -z "$CMD" ];
+then
+       error "no command specified"
+       usage;
+       exit 1
+fi
+
+# Create directory for trace output
+DATESTRING="$(hostname)-$(date +%Y%m%d%H%M%S)"
+OUTDIR="$BASE_TRACE_DIR/$DATESTRING"
+mkdir -p "$OUTDIR"
+
+# Choose socket path
+SOCKPATH="/tmp/ust-sock-$$"
+
+# Start daemon
+$USTD -s "$SOCKPATH" -o "$OUTDIR" >"$OUTDIR/ustd.log" 2>&1 &
+USTDPID=$!
+
+# Establish the environment for the command
+export UST_TRACE=1
+export UST_AUTOPROBE=1
+export UST_DAEMON_SOCKET="$SOCKPATH"
+
+# Execute the command
+bash -c "$CMD"
+
+## Because of the keepalive mechanism, we're sure that by the time
+## we get here, the daemon is connected to all the buffers that still exist.
+## Therefore we can politely ask it to die when it's done.
+
+kill -SIGTERM "$USTDPID"
+
+# Tell the daemon to die
+echo "Waiting for ustd to shutdown..."
+wait "$USTDPID"
This page took 0.023592 seconds and 4 git commands to generate.