Skip to content

Commit f5d96b0

Browse files
authored
bench: Document how to use cross platform Samply profiler (#15481)
* bench: Introduce cross platform Samply profiler
1 parent 1171574 commit f5d96b0

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,20 @@ strip = false # Retain debug info for flamegraphs
191191
inherits = "dev"
192192
incremental = false
193193

194-
# ci turns off debug info, etc for dependencies to allow for smaller binaries making caching more effective
194+
# ci turns off debug info, etc. for dependencies to allow for smaller binaries making caching more effective
195195
[profile.ci.package."*"]
196196
debug = false
197197
debug-assertions = false
198198
strip = "debuginfo"
199199
incremental = false
200200

201+
# release inherited profile keeping debug information and symbols
202+
# for mem/cpu profiling
203+
[profile.profiling]
204+
inherits = "release"
205+
debug = true
206+
strip = false
207+
201208
[workspace.lints.clippy]
202209
# Detects large stack-allocated futures that may cause stack overflow crashes (see threshold in clippy.toml)
203210
large_futures = "warn"

benchmarks/bench.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ run_tpch() {
412412
echo "Running tpch benchmark..."
413413
# Optional query filter to run specific query
414414
QUERY=$([ -n "$ARG3" ] && echo "--query $ARG3" || echo "")
415+
# debug the target command
416+
set -x
415417
$CARGO_COMMAND --bin tpch -- benchmark datafusion --iterations 5 --path "${TPCH_DIR}" --prefer_hash_join "${PREFER_HASH_JOIN}" --format parquet -o "${RESULTS_FILE}" $QUERY
418+
set +x
416419
}
417420

418421
# Runs the tpch in memory
@@ -427,9 +430,13 @@ run_tpch_mem() {
427430
RESULTS_FILE="${RESULTS_DIR}/tpch_mem_sf${SCALE_FACTOR}.json"
428431
echo "RESULTS_FILE: ${RESULTS_FILE}"
429432
echo "Running tpch_mem benchmark..."
433+
# Optional query filter to run specific query
430434
QUERY=$([ -n "$ARG3" ] && echo "--query $ARG3" || echo "")
435+
# debug the target command
436+
set -x
431437
# -m means in memory
432438
$CARGO_COMMAND --bin tpch -- benchmark datafusion --iterations 5 --path "${TPCH_DIR}" --prefer_hash_join "${PREFER_HASH_JOIN}" -m --format parquet -o "${RESULTS_FILE}" $QUERY
439+
set +x
433440
}
434441

435442
# Runs the cancellation benchmark

docs/source/library-user-guide/profiling.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
The section contains examples how to perform CPU profiling for Apache DataFusion on different operating systems.
2323

24-
## Building a flamegraph
24+
## Building a flame graph
2525

2626
[Video: how to CPU profile DataFusion with a Flamegraph](https://youtu.be/2z11xtYw_xs)
2727

@@ -82,6 +82,43 @@ CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root --bench sql_planner --
8282

8383
[Video: how to CPU profile DataFusion with XCode Instruments](https://youtu.be/P3dXH61Kr5U)
8484

85-
## Linux
85+
## Profiling using Samply cross platform profiler
8686

87-
## Windows
87+
There is an opportunity to build flamegraphs, call trees and stack charts on any platform using
88+
[Samply](https://github.com/mstange/samply)
89+
90+
Install Samply profiler
91+
92+
```shell
93+
cargo install --locked samply
94+
```
95+
96+
More Samply [installation options](https://github.com/mstange/samply?tab=readme-ov-file#installation)
97+
98+
Run the profiler
99+
100+
```shell
101+
samply record --profile profiling ./my-application my-arguments
102+
```
103+
104+
### Profile the benchmark
105+
106+
[Set up benchmarks](https://github.com/apache/datafusion/blob/main/benchmarks/README.md#running-the-benchmarks) if not yet done
107+
108+
Example: Profile Q22 query from TPC-H benchmark.
109+
Note: `--profile profiling` to profile release optimized artifact with debug symbols
110+
111+
```shell
112+
cargo build --profile profiling --bin tpch
113+
samply record ./target/profiling/tpch benchmark datafusion --iterations 5 --path datafusion/benchmarks/data/tpch_sf10 --prefer_hash_join true --format parquet -o datafusion/benchmarks/results/dev2/tpch_sf10.json --query 22
114+
```
115+
116+
After sampling has completed the Samply starts a local server and navigates to the profiler
117+
118+
```shell
119+
Local server listening at http://127.0.0.1:3000
120+
```
121+
122+
![img.png](samply_profiler.png)
123+
124+
Note: The Firefox profiler cannot be opened in Safari, please use Chrome or Firefox instead
Loading

0 commit comments

Comments
 (0)