tracer_cuda.sh.in 2.26 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
#!/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;;
23
    -a | --arguments ) shift; arguments=1;;
Brice Videau's avatar
Brice Videau committed
24
    -p | --profiling ) shift; profiling=1; LTTNG_UST_CUDA_PROFILE=1;;
25
    -v | --visualize ) shift; lttng_view=1;;
Brice Videau's avatar
Brice Videau committed
26
27
28
29
30
31
32
33
    -- ) shift; break ;;
    * ) break ;;
  esac
done
lttng-sessiond --daemonize --quiet
if [ ! -z "$lttng_view" ]
then
  lttng-relayd --daemonize
Brice Videau's avatar
Brice Videau committed
34
  lttng create thapi-cuda-session --live
Brice Videau's avatar
Brice Videau committed
35
else
Brice Videau's avatar
Brice Videau committed
36
  lttng create thapi-cuda-session
Brice Videau's avatar
Brice Videau committed
37
38
fi
lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
Brice Videau's avatar
Brice Videau committed
39
lttng add-context --userspace --channel=blocking-channel -t vpid -t vtid
Brice Videau's avatar
Brice Videau committed
40
41
42
43
44
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
45
46
47
48
if [ ! -z "$arguments" ]
then
  lttng enable-event --channel=blocking-channel --userspace lttng_ust_cuda_args:*
fi
Brice Videau's avatar
Brice Videau committed
49
50
51
52
if [ ! -z "$profiling" ]
then
  lttng enable-event --channel=blocking-channel --userspace lttng_ust_cuda_profiling:*
fi
Brice Videau's avatar
Brice Videau committed
53
54
55
56
57
58
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
59
export LD_LIBRARY_PATH=$pkglibdir/cuda:$LD_LIBRARY_PATH
Brice Videau's avatar
Brice Videau committed
60
61
62
63
64
65
66
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
67
  export LD_LIBRARY_PATH=$pkglibdir/cudart:$LD_LIBRARY_PATH
Brice Videau's avatar
Brice Videau committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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