Inspect runtime events with ETDump

This optional activity records ExecuTorch runtime events on the Raspberry Pi. It uses ExecuTorch Inspector for a tabular profile and Model Explorer for a graph overlay.

ETRecord, ETDump, ExecuTorch Inspector, and Model Explorer

ETRecord is an artifact that can be created when the model is exported. It stores the exported graph, debug handles, and delegate mappings needed to associate runtime events with graph nodes. It does not contain runtime measurements.

ETDump is an artifact that can be created when an ExecuTorch program runs with event tracing enabled. The resulting .etdp file contains profiling and debugging events recorded by that execution.

ExecuTorch Inspector is a Python API and command-line tool that reads ETDump data. When you also provide the matching ETRecord, Inspector can associate runtime events with operators and delegate metadata from the exported graph.

The ExecuTorch extension for Model Explorer opens the graph stored in an ETRecord and overlays per-node timings from the matching ETDump. The overlay does not currently include delegate timings, so use ExecuTorch Inspector to measure the XNNPACK delegate calls in this activity.

ArtifactCreatedUsed in this activity
.ptemodel exportprogram executed on the Raspberry Pi
.etrecordmodel exportgraph context for interpreting runtime events
.etdpruntimeevents and timings recorded while the .pte runs

The ETRecord and ETDump must come from the same exported program. Debug handles stored in both files allow Inspector and Model Explorer to associate runtime events with the exported graph.

Create the profiling artifacts

Run on the development machine with .cpu_aot_venv active:

    

        
        
module-2-cnn-inference-with-quantization/scripts/aot/lower_mobilenetv2_xnnpack.py \
  --spec module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/model_spec.json \
  --profiling-artifacts

    

In addition to rebuilding mobilenetv2_xnnpack.pte, the script writes:

    

        
        
mobilenetv2_xnnpack.etrecord
mobilenetv2_portable.pte
mobilenetv2_portable.etrecord

    

Earlier steps did not generate a portable-kernel .pte for MobileNetV2. This script generates one so that you can compare portable and XNNPACK runtime profiles.

From the development machine, copy the .pte files to the Raspberry Pi, substituting your username and IP address into the command:

    

        
        
scp \
  module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/mobilenetv2_xnnpack.pte \
  module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/mobilenetv2_portable.pte \
  <user>@<pi>:~/executorch_on_arm/module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/

    

Build ExecuTorch with event tracing

The prebuilt Python runtime used for the benchmarks does not record ETDump data. Instead you will build ExecuTorch from source with ETDump enabled, using the provided script:

    

        
        
cd ~/executorch_on_arm
source .cpu_lab_venv/bin/activate
sudo apt update
sudo apt install -y cmake ninja-build

module-2-cnn-inference-with-quantization/scripts/pi/build_etdump_runtime.sh

    
Note

On a Raspberry Pi 5, the first build can take 15–20 minutes and uses roughly 2 GB for the source checkout and build files. Allow at least 3 GB of free disk space.

The script checks out ExecuTorch v1.3.1 to match the course artifacts and supplies these CMake options to the Python runtime build:

    

        
        
-DEXECUTORCH_BUILD_XNNPACK=ON
-DEXECUTORCH_BUILD_DEVTOOLS=ON
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON

    

Capture the runtime traces

Run capture_etdump.py once for each artifact. Each invocation performs ten forward executions and writes one ETDump file, using the same image and preprocessing as the benchmark:

    

        
        
module-2-cnn-inference-with-quantization/scripts/pi/capture_etdump.py \
  --spec module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/model_spec.json \
  --pte module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/mobilenetv2_xnnpack.pte \
  --image module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/sample.jpg \
  --runs 10 \
  --out module-2-cnn-inference-with-quantization/results/mobilenetv2_xnnpack.etdp

module-2-cnn-inference-with-quantization/scripts/pi/capture_etdump.py \
  --spec module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/model_spec.json \
  --pte module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/mobilenetv2_portable.pte \
  --image module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/sample.jpg \
  --runs 10 \
  --out module-2-cnn-inference-with-quantization/results/mobilenetv2_portable.etdp

    

Back on the development machine, copy the traces from the Raspberry Pi, substituting your username and IP address:

    

        
        
mkdir -p module-2-cnn-inference-with-quantization/results
scp \
  <user>@<pi>:~/executorch_on_arm/module-2-cnn-inference-with-quantization/results/mobilenetv2_xnnpack.etdp \
  <user>@<pi>:~/executorch_on_arm/module-2-cnn-inference-with-quantization/results/mobilenetv2_portable.etdp \
  module-2-cnn-inference-with-quantization/results/

    

Read delegate timing with Inspector

Run on the development machine with .cpu_aot_venv active:

    

        
        
python -m executorch.devtools.inspector.inspector_cli \
  --etdump_path module-2-cnn-inference-with-quantization/results/mobilenetv2_xnnpack.etdp \
  --etrecord_path module-2-cnn-inference-with-quantization/artifacts/mobilenetv2/mobilenetv2_xnnpack.etrecord \
  --tsv_path module-2-cnn-inference-with-quantization/results/mobilenetv2_xnnpack_inspector.tsv

    

Inspector groups the ten runs and reports average, percentile, minimum, and maximum durations. Look for DELEGATE_CALL with XnnpackBackend in the delegate column. This row measures the complete delegated region. Backend events such as XNNPACK convolutions may also appear, but they are not mapped to individual exported graph nodes in this trace.

Overlay portable operator timings in Model Explorer

Install the Model Explorer profiling packages:

    

        
        
python -m pip install -r module-2-cnn-inference-with-quantization/requirements-model-explorer-profiling.txt

model-explorer \
  --port 8081 \
  --extensions=etrecord_adapter_model_explorer,etdump_data_provider_model_explorer

    

Open http://localhost:8081, then open mobilenetv2_portable.etrecord. In Node data providers, select ETDump Profiling Overlay, upload mobilenetv2_portable.etdp, and run the provider. The graph should offer these overlays:

  • Runtime Total Avg (ms)
  • Runtime Total P50 (ms)
  • Runtime Total Min (ms)
  • Runtime Total Max (ms)
  • Runtime Event Count

The portable trace maps timings to operations such as convolutions and activations.

Stop Model Explorer with Ctrl+C.

Previous page Complete and continue