xprof.sh.erb.in 7.29 KB
Newer Older
1
#!/usr/bin/env bash
Brice Videau's avatar
Brice Videau committed
2
3
exec_prefix=@prefix@
libdir=@libdir@
Brice Videau's avatar
Brice Videau committed
4
bindir=@bindir@
Brice Videau's avatar
Brice Videau committed
5
6
pkglibdir=$libdir/@PACKAGE@

7
display_help() {
Thomas Applencourt's avatar
Thomas Applencourt committed
8
9
10
11
12
13
14
<% if languages.include?("opencl") and  languages.include?("ze")%>
    echo "$(basename $0): a tracer / summarizer of OpenCL and L0 calls"
<% elsif languages.include?("opencl") %>
    echo "$(basename $0): a tracer / summarizer of OpenCL calls"
<% elsif languages.include?("ze") %>
    echo "$(basename $0): a tracer / summarizer of L0 calls"
<% end %>
15
16
17
18
19
20
21
22
23
    echo "Usage:"
    echo " $(basename $0) -h | --help "
    echo " $(basename $0) [option]... <application> <application-arguments>"
    echo " $(basename $0) [option]... -r [<trace>]..."
    echo
    echo "  -h, --help         Show this screen"
    echo "  -e, --extended     Print information for each Hostname / Process / Thread / Device"
    echo "  -t, --trace        Display the trace"
    echo "  -a, --asm          Dump in your current directory low level kernels informations (asm,isa,visa,...)."
Thomas Applencourt's avatar
Thomas Applencourt committed
24
25
    echo "  -r, --replay       <application> <application-arguments> will be traited as pathes to traces folders ($HOME/lttng-traces/...)"
    echo "                     If no arguments are provided, will use the latest trace available"
26
27
28
29
    echo
    echo " Example:"
    echo " $(basename $0) ./a.out"
    echo
Thomas Applencourt's avatar
Thomas Applencourt committed
30
    echo "$(basename $0) will save the trace in $HOME/lttng-traces/"
31
32
33
34
35
36
37
38
39
    echo " Please tidy up from time to time"
    echo "                                                   __ "
    echo "For complain, praise, bug repport please use:    <(o )___"
    echo "   https://xgitlab.cels.anl.gov/heteroflow/tracer ( ._> /"
    echo "   or send email to {apl,bvideau}@anl.gov          \`---'"
    exit 1
}

# Find all location of a `.so`
Brice Videau's avatar
Brice Videau committed
40
whichlib() {
41
42
43
44
45
46
47
48
49
50
51
52
53
  # 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}'
}

trace_and_summary() {
Thomas Applencourt's avatar
Thomas Applencourt committed
54
55
56
57
    if [ -z "$@" ]; then
        display_help
    fi

58
    mkdir -p ${LTTNG_HOME:-$HOME}
59
    lttng-sessiond $quiet --daemonize
Thomas Applencourt's avatar
Thomas Applencourt committed
60
<% if languages.include?("opencl") and  languages.include?("ze")%>
61
    lttng $quiet create iprof
Thomas Applencourt's avatar
Thomas Applencourt committed
62
63
64
65
66
67
<% elsif languages.include?("opencl") %>
    lttng $quiet create thapi-opencl-session
<% elsif languages.include?("ze") %>
    lttng $quiet create thapi-ze-session
<% end %>

68
69
70
    #Using blocking more to trace event record loss
    lttng $quiet enable-channel --userspace --blocking-timeout=inf blocking-channel

Thomas Applencourt's avatar
Thomas Applencourt committed
71
<% if languages.include?("opencl") %>
72
73
74
75
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_opencl:*
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_opencl_build:infos*
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_opencl_profiling:*
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_opencl_arguments:kernel_info
76
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_opencl_devices:*
Thomas Applencourt's avatar
Thomas Applencourt committed
77
78
<% end %>
<% if languages.include?("ze") %>
79
80
81
82
83
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_ze:*
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_zet:*
    export LTTNG_UST_ZE_PROFILE=1
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_ze_profiling:*
    lttng $quiet enable-event --channel=blocking-channel --userspace lttng_ust_ze_properties:*
Thomas Applencourt's avatar
Thomas Applencourt committed
84
<% end %>
85
86
87

    lttng $quiet add-context --userspace --channel=blocking-channel -t vpid -t vtid

Brice Videau's avatar
Brice Videau committed
88
    #Preventing trace event record loss
Thomas Applencourt's avatar
Thomas Applencourt committed
89
<% if languages.include?("opencl") %>
Brice Videau's avatar
Brice Videau committed
90
91
92
93
    if [ -z "$LTTNG_UST_OPENCL_LIBOPENCL" ]
    then
      export LTTNG_UST_OPENCL_LIBOPENCL=$(whichlib libOpenCL.so | head -n 1)
    fi
Thomas Applencourt's avatar
Thomas Applencourt committed
94
95
<% end %>
<% if languages.include?("ze") %>
Brice Videau's avatar
Brice Videau committed
96
97
98
99
    if [ -z "$LTTNG_UST_ZE_LIBZE_LOADER" ]
    then
      export LTTNG_UST_ZE_LIBZE_LOADER=$(whichlib libze_loader.so | head -n 1)
    fi
Thomas Applencourt's avatar
Thomas Applencourt committed
100
<% end %>
101
102
    #Preventing trace event record loss
    export LTTNG_UST_ALLOW_BLOCKING=1
Thomas Applencourt's avatar
Thomas Applencourt committed
103
104
105
106
107
108
109
110
<% if languages.include?("opencl") %>
    export LD_PRELOAD=$libdir/libTracerOpenCL.so:$LD_PRELOAD
    export LD_LIBRARY_PATH=$pkglibdir/opencl:$LD_LIBRARY_PATH
<% end %>
<% if languages.include?("ze") %>
    export LD_PRELOAD=$libdir/libTracerZE.so:$LD_PRELOAD
    export LD_LIBRARY_PATH=$pkglibdir/ze:$LD_LIBRARY_PATH 
<% end %>
111
112
113
114
115
116
117
118
119
120
121
122
123
124

    lttng $quiet start
    trap 'trace_epilogue' EXIT SIGABRT SIGSEGV
    "$@"
}

trace_epilogue() {
  lttng $quiet stop
  lttng $quiet destroy
  summary
}


summary() {
Thomas Applencourt's avatar
Thomas Applencourt committed
125
    if [ -z "$@" ]; then
Thomas Applencourt's avatar
Thomas Applencourt committed
126
<% if languages.include?("opencl") and  languages.include?("ze")%>
127
        lttng_last_session=$(ls -dt ${LTTNG_HOME:-$HOME}/lttng-traces/* | head -1)
Thomas Applencourt's avatar
Thomas Applencourt committed
128
<% elsif languages.include?("opencl") %>
129
        lttng_last_session=$(ls -dt ${LTTNG_HOME:-$HOME}/lttng-traces/thapi-opencl-session* | head -1)
Thomas Applencourt's avatar
Thomas Applencourt committed
130
<% elsif languages.include?("ze") %>
131
        lttng_last_session=$(ls -dt ${LTTNG_HOME:-$HOME}/lttng-traces/thapi-ze-session* | head -1)
Thomas Applencourt's avatar
Thomas Applencourt committed
132
133
<% end %>
        echo "Trace location:" $lttng_last_session
134
135
        echo
    else
Thomas Applencourt's avatar
Thomas Applencourt committed
136
        lttng_last_session=$@
137
138
    fi
    # Check that the argument are trace.
Thomas Applencourt's avatar
Thomas Applencourt committed
139
    # We don't quote the $lttng_last_session, to be able to loop over hit.
140
    # Should be cleaner to use bash arrays.
Thomas Applencourt's avatar
Thomas Applencourt committed
141
    for f in  $lttng_last_session; do
142
143
144
145
        if [ ! -d "$f" ]; then
            echo "$f is not a trace folder"
            exit 1
        fi
Thomas Applencourt's avatar
Thomas Applencourt committed
146
    done
147
148
149

    if [ -n "$trace" ]; then
        # Todo filter direcly in the babeltrace
Thomas Applencourt's avatar
Thomas Applencourt committed
150
151
152
153
154
155
<% if languages.include?("opencl") %>
        $bindir/babeltrace_opencl $lttng_last_session | grep lttng_ust_opencl
<% end %>
<% if languages.include?("ze") %>
        $bindir/babeltrace_ze $lttng_last_session | grep lttng_ust_ze
<% end %>
156
157
    fi

Thomas Applencourt's avatar
Thomas Applencourt committed
158
159
<% if languages.include?("opencl") %>
    ocl_output=$(babeltrace2 --plugin-path=$libdir --component=sink.clprof.dispatch  --params="display=$display" ${lttng_last_session})
160
161
162
163
    if [ -n "$ocl_output" ]; then
        echo "== OpenCL == "
        echo "$ocl_output"
    fi
Thomas Applencourt's avatar
Thomas Applencourt committed
164
165
166
<% end %>
<% if languages.include?("ze") %>
    ze_output=$(babeltrace2 --plugin-path=$libdir --component=sink.zeprof.dispatch  --params="display=$display" ${lttng_last_session})
167
168
169
170
    if [ -n "$ze_output" ]; then
        echo "== Level0 == "
        echo "$ze_output"
    fi
Thomas Applencourt's avatar
Thomas Applencourt committed
171
<% end %>
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
}

#  _
# |_) _. ._ _ o ._   _     /\  ._ _
# |  (_| | _> | | | (_|   /--\ | (_| \/
#                    _|           _|
display="compact";
if [[ $# -eq 0 ]]; then
    display_help
fi

while (( "$#" )); do
    case "$1" in
        -h | --help)     display_help; exit ;;
        -e | --extented) shift; display="extended"   ;;
Thomas Applencourt's avatar
Thomas Applencourt committed
187
        -r | --replay)   shift; replay=true ;;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
        -d | --debug)    shift; debug=true ;;
        -a | --asm)      shift; asm=true ;;
        -t | --trace)    shift; trace=true ;;
        --)              shift; break ;;
        *)               break  ;;
    esac
done

if [ -n "$debug" ]; then
    export LIBBABELTRACE2_INIT_LOG_LEVEL=WARNING
    export BABELTRACE_CLI_LOG_LEVEL=WARNING
else
    quiet="--quiet"
fi

if [ -n "$asm" ]; then
    export IGC_ShaderDumpEnable=1
    export IGC_DumpToCurrentDir=1
fi

if [ -n "$replay" ]; then
Thomas Applencourt's avatar
Thomas Applencourt committed
209
    summary "$@"
210
211
212
else
    trace_and_summary "$@"
fi