3 # usttrace by Pierre-Marc Fournier 2009
4 # Distributed under the GPLv2.
6 USTTRACE_DIR
="$(dirname $0)"
7 USTD
="${USTTRACE_DIR}/ustd/ustd"
8 LIBINTERFORK_PATH
="${USTTRACE_DIR}/libinterfork/.libs/libinterfork.so"
9 LIBMALLOCWRAP_PATH
="${USTTRACE_DIR}/libmallocwrap/.libs/libmallocwrap.so"
11 STD_LDLIBRARY_UST
="${USTTRACE_DIR}/libust/.libs"
13 BASE_TRACE_DIR
="${HOME}/.usttraces"
16 echo "usage: $0 OPTIONS COMMAND" 2>/dev
/stderr
18 echo "Options:" 2>/dev
/stderr
19 echo " -l Runtime link with UST library." 2>/dev
/stderr
20 echo " (Needed only if program was not linked at compile time with libust.)" 2>/dev
/stderr
21 echo " -L Add path to ust libraries to LD_LIBRARY_PATH." 2>/dev
/stderr
22 echo " -m Instrument malloc calls." 2>/dev
/stderr
23 echo " -f Also trace forked processes." 2>/dev
/stderr
24 echo " -s Use system-wide daemon instead of creating one for this session." 2>/dev
/stderr
28 echo "$0: error: $1" 2>/dev
/stderr
31 while getopts ":hlLmfs" options
; do
33 l
) arg_preload_libust
=1;;
35 m
) arg_preload_malloc
=1;;
36 f
) arg_preload_fork
=1;;
37 s
) arg_syswide_daemon
=1;;
46 shift $
(($OPTIND - 1))
50 error
"specified path to ustd not executable ($USTD)"
60 error
"no home specified"
65 error
"no command specified"
70 # Create directory for trace output
71 DATESTRING
="$(hostname)-$(date +%Y%m%d%H%M%S)"
72 OUTDIR
="$BASE_TRACE_DIR/$DATESTRING"
76 SOCKPATH
="/tmp/ust-sock-$$"
78 if [ "$arg_syswide_daemon" != "1" ];
81 $USTD -s "$SOCKPATH" -o "$OUTDIR" 2>&1 >"$OUTDIR/ustd.log" &
83 export UST_DAEMON_SOCKET
="$SOCKPATH"
86 # Wait for the daemon to settle
87 # If we don't, the process may try to connect to its socket before
89 # FIXME: is there a way to make sure this works every time? Yes,
90 # we could have a mode where ustd daemonizes itself. Therefore
91 # by the time the control returns to the console, it's ready.
95 # Establish the environment for the command
97 export UST_AUTOPROBE
=1
99 if [ "$arg_preload_libust" = "1" ];
101 export LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:./libust/.libs"
102 export LD_PRELOAD
="$LD_PRELOAD:./libust/.libs/libust.so"
105 if [ "$arg_ld_std_ust" = "1" ];
107 export LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:$STD_LDLIBRARY_UST"
110 if [ "$arg_preload_malloc" = "1" ];
112 export LD_PRELOAD
="$LD_PRELOAD:./libmallocwrap/.libs/libmallocwrap.so"
115 if [ "$arg_preload_fork" = "1" ];
117 export LD_PRELOAD
="$LD_PRELOAD:$LIBINTERFORK_PATH"
120 # Install a handler for SIGIO. This is the signal that will be sent by ustd to
121 # the traced program to trigger the creation of its listener thread. However,
122 # it is possible that the SIGIO will be sent after the shell fork, but before
123 # the exec of the command. If this handler isn't there, bash might terminate
124 # because of a unhandled signal.
126 # Execute the command
127 bash
-c "$CMD" 2>&1 |
tee "$OUTDIR/app.log"
129 ## Because of the keepalive mechanism, we're sure that by the time
130 ## we get here, the daemon is connected to all the buffers that still exist.
131 ## Therefore we can politely ask it to die when it's done.
133 if [ "$arg_syswide_daemon" != "1" ];
135 # Tell the daemon to die
136 kill -SIGTERM "$USTDPID"
138 echo "Waiting for ustd to shutdown..."
142 echo "Trace was output in: " $OUTDIR
This page took 0.034559 seconds and 6 git commands to generate.