From eb6adb25b8492bcfd0e72153708166563a109015 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Wed, 9 Sep 2009 13:32:45 -0400 Subject: [PATCH] add usttrace script --- usttrace | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 usttrace diff --git a/usttrace b/usttrace new file mode 100755 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" -- 2.34.1