3 # usttrace by Pierre-Marc Fournier 2009
4 # Distributed under the GPLv2.
7 echo "$0: error: $1" 1>&2
12 if [ -z "${UST_CONSUMERD_PID}" ]; then
13 UST_CONSUMERD_PID
=`cat $pidfilepath`
15 # Tell the daemon to die
16 kill -TERM "${UST_CONSUMERD_PID}"
18 echo "Waiting for ust-consumerd to shutdown..."
19 wait "${UST_CONSUMERD_PID}"
26 USTTRACE_DIR
="$(dirname $0)"
27 if [ -x "${USTTRACE_DIR}/ust-consumerd/ust-consumerd" ] ; then
28 # Use the not installed libraries instead
29 UST_CONSUMERD
="${USTTRACE_DIR}/ust-consumerd/ust-consumerd"
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
35 UST_CONSUMERD
="ust-consumerd"
36 if [ ! -x "$(which ust-consumerd 2>/dev/null)" ]; then
37 error
"cannot find an executable ust-consumerd; 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" 1>&2
51 echo " -l Runtime link with UST library." 1>&2
52 echo " (Needed only if program was not linked at compile time with libust.)" 1>&2
53 echo " -L Add path to ust libraries to LD_LIBRARY_PATH." 1>&2
54 echo " -m Instrument malloc calls." 1>&2
55 echo " -f Also trace forked processes." 1>&2
56 echo " -s Use system-wide daemon instead of creating one for this session." 1>&2
57 echo " -S Specify the subbuffer size." 1>&2
58 echo " -N Specify the number of subbuffers." 1>&2
59 echo " -o Output directory of the trace." 1>&2
62 while getopts ":hlLmfsWS:N:o:" options
; do
64 l
) arg_preload_libust
=1;;
66 m
) arg_preload_malloc
=1;;
67 f
) arg_preload_fork
=1;;
68 s
) arg_syswide_daemon
=1;;
70 S
) export UST_SUBBUF_SIZE
=$OPTARG;;
71 N
) export UST_SUBBUF_NUM
=$OPTARG;;
72 o
) OUTPUT_DIR
=$OPTARG;;
81 shift $
(($OPTIND - 1))
83 if [ -n "$where" ]; then
84 echo $BASE_TRACE_DIR/$
(ls "$BASE_TRACE_DIR" |
tail -n 1)
94 error
"no home specified"
99 error
"no command specified"
104 # Create directory for trace output
105 if [ -n "$OUTPUT_DIR" ]; then
108 DATESTRING
="$(hostname)-$(date +%Y%m%d%H%M%S%N)"
109 OUTDIR
="$BASE_TRACE_DIR/$DATESTRING"
112 # Check if directory exist
113 if [ ! -d "$OUTDIR" ]; then
115 if [ $?
-eq 1 ]; then
120 # Choose ust-consumerd socket path
121 UST_CONSUMERD_SOCKPATH
="/tmp/ust-consumerd-sock-$$"
123 if [ "$arg_syswide_daemon" != "1" ];
125 pidfilepath
="/tmp/usttrace-$USER-$(date +%Y%m%d%H%M%S%N)-ust-consumerd-pid"
126 trap "sighandler $pidfilepath" INT
127 mkfifo -m 0600 "$pidfilepath"
129 ${UST_CONSUMERD} --pidfile "$pidfilepath" -s "${UST_CONSUMERD_SOCKPATH}" -o "$OUTDIR" >"$OUTDIR/ust-consumerd.log" 2>&1 &
130 # ust-consumerd sets up its server socket
131 # ust-consumerd opens the pidfile, blocks because no one has opened it
133 # we block reading pidfile
134 # ust-consumerd writes to pidfile
135 # ust-consumerd closes pidfile
136 # we unblock reading pidfile
137 UST_CONSUMERD_PID
=`cat $pidfilepath`
138 export UST_DAEMON_SOCKET
="${UST_CONSUMERD_SOCKPATH}"
141 # Establish the environment for the command
144 export UST_AUTOPROBE
=1
146 if [ "$arg_preload_libust" = "1" ];
148 if [ -n "${LIBUST_PATH%libust.so}" ];
150 if [ -n "$LD_LIBRARY_PATH" ];
152 export LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:${LIBUST_PATH%libust.so}"
154 export LD_LIBRARY_PATH
="${LIBUST_PATH%libust.so}"
157 if [ -n "$LIBUST_PATH" ];
159 if [ -n "$LD_PRELOAD" ];
161 export LD_PRELOAD
="$LD_PRELOAD:$LIBUST_PATH"
163 export LD_PRELOAD
="$LIBUST_PATH"
168 if [ "$arg_ld_std_ust" = "1" ] && [ -n "${LIBUST_PATH%libust.so}" ];
170 if [ -n "$LD_LIBRARY_PATH" ];
172 export LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:${LIBUST_PATH%libust.so}"
174 export LD_LIBRARY_PATH
="${LIBUST_PATH%libust.so}"
178 if [ "$arg_preload_malloc" = "1" ] && [ -n "$LIBMALLOCWRAP_PATH" ];
180 if [ -n "$LD_PRELOAD" ];
182 export LD_PRELOAD
="$LD_PRELOAD:$LIBMALLOCWRAP_PATH"
184 export LD_PRELOAD
="$LIBMALLOCWRAP_PATH"
188 if [ "$arg_preload_fork" = "1" ] && [ -n "$LIBINTERFORK_PATH" ];
190 if [ -n "$LD_PRELOAD" ];
192 export LD_PRELOAD
="$LD_PRELOAD:$LIBINTERFORK_PATH"
194 export LD_PRELOAD
="$LIBINTERFORK_PATH"
198 # Execute the command
200 ) |
tee "$OUTDIR/app.log"
202 ## Because of the keepalive mechanism, we're sure that by the time
203 ## we get here, the daemon is connected to all the buffers that still exist.
204 ## Therefore we can politely ask it to die when it's done.
206 if [ "$arg_syswide_daemon" != "1" ];
208 # Tell the daemon to die
209 kill -TERM "${UST_CONSUMERD_PID}"
211 echo "Waiting for ust-consumerd to shutdown..."
212 wait "${UST_CONSUMERD_PID}"
217 echo "Trace was output in: " $OUTDIR
This page took 0.033315 seconds and 4 git commands to generate.