Files
sdk/runtime/tools/profiling
Jens Johansen ced0ee901c [vm] Fix set_uprobe script after offsets_extractor was coverted to json
Also add a '--dry-run' parameter as running it as sudo doesn't work
for me (it times out when it tries to build because of the RBE stuff I
think).

Now I can run something like

```
pkg/vm/tool/precompiler2 --dwarf-stack-traces --generate-probe-points path/to/file.dart path/to/file.aot
out/ReleaseX64/dart-sdk/bin/dart runtime/tools/profiling/bin/set_uprobe.dart alloc AllocationProbePoint path/to/file.aot --dry-run | sudo tee "/sys/kernel/tracing/uprobe_events"
cp out/ReleaseX64/dartaotruntime out/ReleaseX64/dart-sdk/bin/dartaotruntimeNotProduct
sudo perf record -g -e uprobes:alloc out/ReleaseX64/dart-sdk/bin/dartaotruntimeNotProduct path/to/file.aot <args>
sudo chmod 0755 perf.data
```

Change-Id: I189c2c08ec9cef5e61698e4fb9c9444494d20815
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450040
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-09-19 00:55:40 -07:00
..

Various tools for low level profing of code running on the Dart VM.

Uprobe based profiling

uprobes is a user-space dynamic tracing mechanism. Using this mechanism the kernel can be instructed to place a tracepoint at a particular file offset within a specific binary. Whenever this tracepoint is hit the kernel will fetch values from the execution context based on the uprobe's description and emit an event. A developer can subscribe to uprobe events in a few different ways including perf_event_open syscall. uprobes have been enabled by default on all newish Linux kernels (4.14+), however they are only truly usable on Android/ARM64 starting from 5.10+. bin/set_uprobe.dart is a helper script for placing uprobes inside binaries and using this for profiling.

The core workflow looks like this:

$ sudo $(which dart) runtime/tools/profiling/bin/set_uprobe.dart probeName symbol binary

This will create an uprobe with name probeName which triggers whenever the given symbol inside the given binary is called. You can then record an event (and collect the call stack) using:

$ sudo perf record -g -e uprobes:probeName ...

Allocation profiling with uprobes

AOT compiler can emit a special probe point (stub AllocationProbePoint) which triggers for each new space allocation from generated code. set_uprobe script has special support for this probe point: it will configure probe point to record additional information (address of allocated object, allocation top and cid of the allocated object) allowing to post process collected data into an actual allocation profile.

Start by compiling your application with --generate-probe-points:

$ pkg/vm/tool/precompiler2 --generate-probe-points test.dart test.aot

Then install uprobe on AllocationProbePoint:

$ sudo $(which dart) runtime/tools/profiling/bin/set_uprobe.dart alloc AllocationProbePoint test.aot

Record the profile:

$ sudo perf record -g -e uprobes:alloc out/ReleaseX64/dartaotruntime test.aot
$ sudo chmod 0755 perf.data

Produce a coalesced allocation profile from the recording:

$ dart runtime/tools/profiling/bin/convert_allocation_profile.dart perf.data
$ pprof -flame pprof.profile