Back to Docs
Recipe

CPU Profiling

Identify hot paths, diagnose frame drops, and ship a buttery-smooth experience. This recipe walks through sampling-based profiling with Meridian's built-in instrumentation.

Prerequisites

  • Meridian SDK v3.2+ installed in your project
  • Debug build with symbols enabled
  • At least one reproducible workload to profile

Step 1 — Attach the Sampler

Call Meridian.profile.start() before your workload begins. The sampler defaults to 1 kHz and writes compressed call stacks to a ring buffer.

Step 2 — Run the Workload

Execute the exact scenario you want to analyze. Keep the run under 60 seconds for manageable trace sizes. The ring buffer preserves the last 30 seconds of samples.

Step 3 — Stop and Export

Call Meridian.profile.stop() then export with Meridian.profile.export("trace.mprof"). The file is compatible with the Meridian Visualizer and pprof-compatible toolchains.

Step 4 — Analyze the Flame Graph

Open the trace in the Meridian dashboard. The flame graph view highlights functions by cumulative CPU time. Look for wide plateaus — those are your optimization targets. Click any frame to drill into source-level attribution.

Common Pitfalls

  • Profiling a release build without symbols — you'll see raw addresses instead of function names.
  • Sampling too briefly — runs under 5 seconds produce noisy data.
  • Forgetting to stop the sampler — it drains battery and skews subsequent measurements.