News Developer Tools

Cloudflare adds on-demand profiling for Workers and Durable Objects

Cloudflare Workers profiling now lets users capture CPU or memory profiles of a live Worker and view them as interactive flamegraphs.

Cloudflare now lets users capture CPU or memory profiles of a running Worker or Durable Object and view them as interactive flamegraphs. Cloudflare says the feature sits on the Workers Observability page and works on live production traffic. A profile can also be downloaded for further analysis.

A profile records which functions use CPU time or allocate memory. In a flamegraph, each rectangle is a function call, and its width shows how much CPU time or memory that function uses. Users can click a function to focus on it, hover for details, or switch to a table view that shows which functions appear most often.

Profiles can be requested from the dashboard or a command-line tool. Users choose how long the profiler runs and which version of the Worker to profile. Cloudflare says the Worker needs plenty of traffic to be profiled successfully. TypeScript projects need source maps enabled, or the profile may show obfuscated function names.

Cloudflare says several of its own teams have used the profiler to optimize CPU and memory use and to fix out-of-memory errors. In one example, a 50-second CPU profile of the Worker behind its R2 binding flagged a function called genericR2JsonReplacer, which used over 5% of CPU time.

Source: Introducing on-demand CPU and memory profiling with flamegraphs for Workers and Durable Objects | Cloudflare Blog.