Cloudflare Launches On-Demand CPU and Memory Profiling for Workers
Cloudflare introduces on-demand CPU and memory profiling with interactive flamegraphs for Workers and Durable Objects, enabling production performance analysis.
Before you start: versions, package names and storage identifiers change over time. Check the commands against the official documentation for your setup before running them, especially anything that creates, deletes or overwrites data.
Real-World Production Profiling for Serverless Code
Cloudflare has announced native support for on-demand CPU and memory profiling for Cloudflare Workers and Durable Objects. Developers can now capture live performance traces of production applications, inspect them via interactive flamegraphs, and export profile data for deeper analysis.
Understanding resource utilization constraints like CPU spikes or unexpected memory usage has traditionally relied on aggregate metrics and logs. The new profiling tools allow developers to trace execution down to individual function calls while applications handle real-world traffic at the edge.
How to Capture Profiles via Dashboard and CLI
Developers can trigger profiling sessions using either the Cloudflare dashboard or the command-line interface. To capture profiles through the CLI, users with the cf package installed can run a version profile command specifying the worker identifier, duration, and profile type. Alternatively, navigating to the Cloudflare dashboard under Build, Compute, and Workers & Pages provides access to the Observability tab, where users can select the flamegraph view.
Sessions require active traffic to generate meaningful insights. Users can choose a target duration—such as 5000 milliseconds—and select specific deployed versions of their worker script. TypeScript users are advised to enable source maps to ensure function names appear clearly in the resulting visualization rather than as obfuscated identifiers.
Targeting Durable Objects and Isolates
Because Workers are globally distributed across edge data centers and physical servers, profiling requests target specific runtime isolates. For stateless Workers, the platform routes profiling actions to active instances handling live requests. Stateful Durable Objects allow developers to target specific named actors globally, routing commands directly to the underlying physical server hosting that object’s isolate.
To maintain application responsiveness during diagnostics, the Workers Runtime acquires locks only briefly during the profiler’s lifecycle initialization and teardown phases. This isolation strategy prevents execution blocking while gathering sampling data at one-millisecond intervals.
Current Limitations and Future Plans
While on-demand profiling provides immediate diagnostic utility, the current implementation carries specific constraints. Developers must manually initiate sessions, meaning transient or unexpected errors occurring outside the capture window might be missed. Additionally, memory profiling only captures allocations occurring during the active session window rather than during startup sequences.
Cloudflare has indicated that ongoing development is addressing these boundaries through planned support for continuous profiling, which will automatically capture telemetry samples for passive dashboard exploration.
Source
Official announcement or documentation
Some links on this page may be affiliate links. If you buy through them we may earn a commission at no extra cost to you. See our affiliate disclosure.