profile-a-worker
Installation
SKILL.md
Profile a Worker
Cloudflare can sample a deployed Worker or Durable Object while it serves traffic. The result is a pprof file. Each frame is a function. Wider frames cost more CPU time or allocate more memory.
Source: Profiling in production.
Terms used here
- Isolate: one running copy of a Worker. A profile samples one isolate that is already loaded.
- CPU profile: where CPU time goes. It samples about every millisecond.
- Heap profile: where code allocates memory. It records a stack every 512 kB allocated. It does not show retained memory, so it cannot prove a leak by itself.
- Flat: cost in the function itself. Cum: cost in the function and everything it calls.
1. Pick the target
- Find the deployed script name. Alchemy names it from the app, resource, stage, and a suffix. Read it from the Alchemy state or the dashboard; do not guess it.
- Pick the version.
latestis the newest uploaded version, which may not be deployed. After an upload without a deploy, use the deployed version's id. - For a Durable Object, use the Worker that owns the namespace, the namespace id, and the 64-character instance id.