diff --git a/projects/rocprofiler-systems/README.md b/projects/rocprofiler-systems/README.md new file mode 100755 index 0000000000..67abb66310 --- /dev/null +++ b/projects/rocprofiler-systems/README.md @@ -0,0 +1,63 @@ +# hosttrace: application tracing with static/dynamic binary instrumentation and perfetto + + +## 1. load necessary modules +``` +module load julia +module load dyninst +module load rocm/VERSION +``` + +## 2. to install julia packages, only need it the first time. +``` +$ julia +type ']' to get into pkg mode, then +(@v1.6) pkg> add JSON, DataFrames, Dates, CSV, Chain, PrettyTables +``` + +## 3. hosttrace usage +``` +export PATH=$PATH:$HTRACE_PATH/bin +hosttrace --help +``` + +## 4. instrument the binaries +``` +hosttrace -L $HTRACE_PATH/bin/libhosttrace.so -o app.inst -- path_to_your_app + +hosttrace -L $HTRACE_PATH/bin/libhosttrace.so -E 'hipApiName|hipGetCmdName' -o libamdhip64.so.4 -- /opt/rocm-VERSION/lib/libamdhip64.so.4 + +hosttrace -L $HTRACE_PATH/bin/libhosttrace.so -E 'rocr::atomic|rocr::core|rocr::HSA' -o libhsa-runtime64.so.1 -- /opt/rocm-VERSION/lib/libhsa-runtime64.so.1 +``` +## 5. run the app +``` +export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH +rocprof --hip-trace --roctx-trace --stats ./app.inst +``` + +## 6. you may need to increase the buffer size if the hosttrace.perfetto-trace file is close to 1GB. for example to set it to 10GB. +``` +export HOSTTRACE_BUFFER_SIZE_KB=10240000 +``` + +## 7. merge the traces from rocprof and hosttrace +``` +julia $HTRACE_PATH/bin/merge-trace.jl results.json hosttrace.perfetto-trace* +``` + +## 8. another mode of Perfetto tracing is to use system backend. To do it: + +### in a separate window +``` + pkill traced; traced --background; perfetto --out ./htrace.out --txt -c $HTRACE/roctrace.cfg +``` + +### then in the app running window do this before running rocprof or other app +``` + export HOSTTRACE_BACKEND_SYSTEM=1 +``` + +### for the merge use the htrace.out +``` +julia $HTRACE_PATH/bin/merge-trace.jl results.json htrace.out +``` \ No newline at end of file diff --git a/projects/rocprofiler-systems/scripts/merge-trace.jl b/projects/rocprofiler-systems/scripts/merge-trace.jl new file mode 100755 index 0000000000..46fe5cf9ec --- /dev/null +++ b/projects/rocprofiler-systems/scripts/merge-trace.jl @@ -0,0 +1,37 @@ +using Base: String +using JSON, DataFrames, Dates, CSV + +function check_input_args() + message = "Needs only one json file and at least one trace data file(s)." + @assert length(ARGS) >= 2 && occursin(".json", join(ARGS)) message + json_file, trace_files = nothing, String[] + for arg in ARGS + @assert Base.Filesystem.ispath(arg) "'$(arg)' not found!" + if endswith(arg, ".json") + json_file = arg + else + push!(trace_files, arg) + end + end + json_file, trace_files +end + +json_file, trace_files = check_input_args() + +out = JSON.parsefile(json_file) +for trace in trace_files + @info "processing $(trace) ..." + f = tempname() * ".json" + run(`trace_to_text json $trace $f`) + todo = JSON.parsefile(f) + out["traceEvents"] = vcat( + out["traceEvents"], + todo["traceEvents"]) +end + +output_file = replace("$(string(now())).json", ":" => "-") +open(output_file, "w") do f + write(f, JSON.json(out)) + @info "output file: $(output_file)" +end + diff --git a/projects/rocprofiler-systems/src/library.cpp b/projects/rocprofiler-systems/src/library.cpp index 337fa80b9b..cec382ea70 100644 --- a/projects/rocprofiler-systems/src/library.cpp +++ b/projects/rocprofiler-systems/src/library.cpp @@ -221,7 +221,10 @@ hosttrace_init_perfetto() perfetto::TraceConfig cfg{}; perfetto::protos::gen::TrackEventConfig track_event_cfg{}; - cfg.add_buffers()->set_size_kb(buffer_size); + auto *buffer_config = cfg.add_buffers(); + buffer_config->set_size_kb(buffer_size); + buffer_config->set_fill_policy(perfetto::protos::gen::TraceConfig_BufferConfig_FillPolicy_DISCARD); + auto* ds_cfg = cfg.add_data_sources()->mutable_config(); ds_cfg->set_name("track_event"); ds_cfg->set_track_event_config_raw(track_event_cfg.SerializeAsString());