Download a monitoring script
After setting up PhotoTalk, set up assets for performance monitoring. Assets include Perfetto monitoring files and a Jupyter notebook.
The Jupyter Notebook will call a script to collect device data for a specified duration over wireless adb. Review the comments in the script to understand each section.
Download the script:
cd $WORK
curl -fL -O "$BASE_URL/run-device-monitor.sh"
Download the monitoring configuration and queries
Without explicit instructions, the Perfetto tracing daemon doesn’t know what to capture, where to store it, or how to manage memory.
Download the following .cfg file to configure your Perfetto trace:
cd "$WORK"
curl -fL -O "$BASE_URL/device-monitor-perfetto.cfg"
After monitoring is complete, the Bash script creates a .pftrace file on the device and pulls it into $WORK/data/. It uses SQL to extract memory and power data from the trace. If the trace doesn’t contain usable current and voltage samples, the script uses readable battery sysfs nodes as a fallback. The nodes are sampled in parallel.
Download these queries into $WORK/sql/:
mkdir -p $WORK/sql
cd $WORK/sql
curl -fL -O "$BASE_URL/monitor-memory.sql"
curl -fL -O "$BASE_URL/power-battery.sql"
Read through the comments of both the Perfetto config and SQL queries to understand how they function.
Start up JupyterLab
From your working directory, start up a local JupyterLab server and create a new notebook file:
cd $WORK
jupyter lab
Create a new notebook and rename it to something appropriate.
JupyterLab notebook launcher
Initiate device monitoring
In your notebook, create a section titled Runtime Monitoring and add the following code:
from pathlib import Path
from datetime import datetime
import os
import shlex
import subprocess
ROOT = Path.cwd().resolve()
DATA_DIR = ROOT / "data"
MONITOR_SCRIPT = ROOT / "run-device-monitor.sh"
DURATION_SECONDS = 60
# Update if multiple devices are connected to the host machine
MULTIPLE_DEVICES = False
DEVICE_SERIAL = "" # You can find this using `adb devices`
run_output = DATA_DIR / (
f"runtime-perf-{datetime.now():%Y%m%d-%H%M%S}"
)
command = ["sh", str(MONITOR_SCRIPT)]
if MULTIPLE_DEVICES:
command.extend(["--serial", DEVICE_SERIAL])
command.extend([str(DURATION_SECONDS), str(run_output)])
environment = os.environ.copy()
print(shlex.join(command))
print(f"Results: {run_output}")
subprocess.run(command, cwd=ROOT, env=environment, check=True)
This cell monitors the target device for the specified number of seconds. The monitoring script collects the following data:
- Large language model (LLM) inference measurements such as prefill, decode, and time to first token (TTFT)
- Whole-device battery power estimates, when the device exposes current and voltage counters
- Memory measurements
- Temperature measurements
Set DURATION_SECONDS=10, then run the monitoring cell to perform a short smoke test. After ten seconds, a timestamped results directory appears in $WORK/data.
The directory should contain the following files:
- Perfetto trace and logs
- CSV files containing inference, memory, power, and temperature data
- Text files containing job information, including a summary
If any files are missing, review the output after the monitoring cell for errors. Confirm that you completed the previous steps correctly.
You won’t see any data in the LLM performance CSV file. This is because you’ve not performed any inference as part of this smoke test.
What you’ve accomplished and what’s next
You’ve now prepared and tested the necessary monitoring assets for your performance analysis pipeline.
Next, you’ll initiate a full monitoring run and collect some data from your device.