3 # usttrace by Pierre-Marc Fournier 2009
4 # Distributed under the GPLv2.
7 echo "$0: error: $1" 2>/dev
/stderr
10 function sighandler
() {
12 if [ -z "$USTDPID" ]; then
13 USTDPID
="$(<$pidfilepath)"
15 # Tell the daemon to die
16 kill -SIGTERM "$USTDPID"
18 echo "Waiting for ustd to shutdown..."
26 USTTRACE_DIR
="$(dirname $0)"
27 if [ -x "${USTTRACE_DIR}/ustd/ustd" ] ; then
28 # Use the not installed libraries instead
29 USTD
="${USTTRACE_DIR}/ustd/ustd"
30 LIBINTERFORK_PATH
="${USTTRACE_DIR}/libustfork/.libs/libustfork.so"
31 LIBMALLOCWRAP_PATH
="${USTTRACE_DIR}/libustinstr-malloc/.libs/libustinstr-malloc.so"
32 LIBUST_PATH
="${USTTRACE_DIR}/libust/.libs/libust.so"
34 # Use the libraries that the dynamic link finds
36 if [ ! -x "$(which ustd 2>/dev/null)" ]; then
37 error
"cannot find an executable ustd; make sure its location is in the PATH"
40 LIBINTERFORK_PATH
="libustfork.so"
41 LIBMALLOCWRAP_PATH
="libustinstr-malloc.so"
42 LIBUST_PATH
="libust.so.0"
45 BASE_TRACE_DIR
="${HOME}/.usttraces"
48 echo "usage: $0 OPTIONS COMMAND" 2>/dev
/stderr
50 echo "Options:" 2>/dev
/stderr
51 echo " -l Runtime link with UST library." 2>/dev
/stderr
52 echo " (Needed only if program was not linked at compile time with libust.)" 2>/dev
/stderr
53 echo " -L Add path to ust libraries to LD_LIBRARY_PATH." 2>/dev
/stderr
54 echo " -m Instrument malloc calls." 2>/dev
/stderr
55 echo " -f Also trace forked processes." 2>/dev
/stderr
56 echo " -s Use system-wide daemon instead of creating one for this session." 2>/dev
/stderr
57 echo " -S Specify the subbuffer size." 2>/dev
/stderr
58 echo " -N Specify the number of subbuffers." 2>/dev
/stderr
61 while getopts ":hlLmfsWS:N:" options
; do
63 l
) arg_preload_libust
=1;;
65 m
) arg_preload_malloc
=1;;
66 f
) arg_preload_fork
=1;;
67 s
) arg_syswide_daemon
=1;;
69 S
) export UST_SUBBUF_SIZE
=$OPTARG;;
70 N
) export UST_SUBBUF_NUM
=$OPTARG;;
79 shift $
(($OPTIND - 1))
81 if [ -n "$where" ]; then
82 echo $BASE_TRACE_DIR/$
(ls "$BASE_TRACE_DIR" |
tail -n 1)
92 error
"no home specified"
97 error
"no command specified"
102 # Create directory for trace output
103 DATESTRING
="$(hostname)-$(date +%Y%m%d%H%M%S%N)"
104 OUTDIR
="$BASE_TRACE_DIR/$DATESTRING"
107 # Choose ustd socket path
108 USTDSOCKPATH
="/tmp/ustd-sock-$$"
110 if [ "$arg_syswide_daemon" != "1" ];
112 pidfilepath
="/tmp/usttrace-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid"
113 trap "sighandler $pidfilepath" SIGINT
114 mkfifo -m 0600 "$pidfilepath"
116 $USTD --pidfile "$pidfilepath" -s "$USTDSOCKPATH" -o "$OUTDIR" >"$OUTDIR/ustd.log" 2>&1 &
117 # ustd sets up its server socket
118 # ustd opens the pidfile, blocks because no one has opened it
120 # we block reading pidfile
121 # ustd writes to pidfile
122 # ustd closes pidfile
123 # we unblock reading pidfile
124 USTDPID
="$(<$pidfilepath)"
125 export UST_DAEMON_SOCKET
="$USTDSOCKPATH"
128 # Establish the environment for the command
131 export UST_AUTOPROBE
=1
133 if [ "$arg_preload_libust" = "1" ];
135 if [ -n "${LIBUST_PATH%libust.so}" ] ; then
136 export LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:${LIBUST_PATH%libust.so}"
138 export LD_PRELOAD
="$LD_PRELOAD:$LIBUST_PATH"
141 if [ "$arg_ld_std_ust" = "1" ];
143 if [ -n "$${LIBUST_PATH%libust.so}" ] ; then
144 export LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:${LIBUST_PATH%libust.so}"
148 if [ "$arg_preload_malloc" = "1" ];
150 export LD_PRELOAD
="$LD_PRELOAD:$LIBMALLOCWRAP_PATH"
153 if [ "$arg_preload_fork" = "1" ];
155 export LD_PRELOAD
="$LD_PRELOAD:$LIBINTERFORK_PATH"
158 # Execute the command
160 ) |
tee "$OUTDIR/app.log"
162 ## Because of the keepalive mechanism, we're sure that by the time
163 ## we get here, the daemon is connected to all the buffers that still exist.
164 ## Therefore we can politely ask it to die when it's done.
166 if [ "$arg_syswide_daemon" != "1" ];
168 # Tell the daemon to die
169 kill -SIGTERM "$USTDPID"
171 echo "Waiting for ustd to shutdown..."
177 echo "Trace was output in: " $OUTDIR
This page took 0.035648 seconds and 4 git commands to generate.