tracer_cuda.sh.in 1.94 KB
Newer Older
Brice Videau's avatar
Brice Videau committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
exec_prefix=@prefix@
libdir=@libdir@
pkglibdir=$libdir/@PACKAGE@

# Find all location of a `.so`
whichlib() {
  # Output of ldconfig:
  #/usr/lib32:
  #       libstdc++.so.6 -> libstdc++.so.6.0.26
  # After the awk:
  # -> /usr/lib32/libstdc++.so.6

  # In OpenSUSE ldconfig, is in '/sbin'.
  PATH=$PATH:/sbin ldconfig -vNX $(echo $LD_LIBRARY_PATH | sed 's/:/ /g') 2>/dev/null |
  awk -v p=$1 'match($1, ":")                    { header=substr($1, 1, length($1)-1)} \
               match($1, "^lib") && match($1, p) { print header "/" $1}'
}

while true; do
  case "$1" in
    --cudart) shift; cudart=1;;
    -v | --visualize) shift; lttng_view=1;;
    -- ) shift; break ;;
    * ) break ;;
  esac
done
lttng-sessiond --daemonize --quiet
if [ ! -z "$lttng_view" ]
then
  lttng-relayd --daemonize
  lttng create my-userspace-ze-session --live
else
  lttng create my-userspace-ze-session
fi
lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
lttng add-context --userspace --channel=blocking-channel -t vtid -t pthread_id
lttng enable-event --channel=blocking-channel --userspace lttng_ust_cuda:*
if [ ! -z "$cudart" ]
then
  lttng enable-event --channel=blocking-channel --userspace lttng_ust_cudart:*
fi
if [ -z "$LTTNG_UST_CUDA_LIBCUDA" ]
then
  export LTTNG_UST_CUDA_LIBCUDA=$(whichlib libcuda.so | head -n 1)
fi
export LTTNG_UST_ALLOW_BLOCKING=1
export LD_PRELOAD=$libdir/libTracerCUDA.so:$LD_PRELOAD
49
export LD_LIBRARY_PATH=$pkglibdir/cuda:$LD_LIBRARY_PATH
Brice Videau's avatar
Brice Videau committed
50
51
52
53
54
55
56
if [ ! -z "$cudart" ]
then
  if [ -z "$LTTNG_UST_CUDA_LIBCUDART" ]
  then
    export LTTNG_UST_CUDART_LIBCUDART=$(whichlib libcudart.so | head -n 1)
  fi
  export LD_PRELOAD=$libdir/libTracerCUDART.so:$LD_PRELOAD
57
  export LD_LIBRARY_PATH=$pkglibdir/cudart:$LD_LIBRARY_PATH
Brice Videau's avatar
Brice Videau committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fi
lttng start

ctrl_c() {
  lttng stop
  lttng destroy
  exit
}

trap ctrl_c INT

if [ ! -z "$lttng_view" ]
then
  lttng view &
  PID=$!
fi
"$@"
lttng stop
lttng destroy
if [ ! -z "$lttng_view" ]
then
  wait $PID
fi