CPS Profiler: A Complete Beginner’s Guide

CPS Profiler vs. Other Profilers: Which One Wins for Debugging?

What CPS Profiler is

  • Purpose: Focused on tracing continuation-passing-style (CPS) flows and asynchronous control paths in applications that use CPS-based frameworks or heavy async patterns.
  • Strengths: Excellent at visualizing async continuation chains, low overhead for instrumenting callbacks/promises, and good at attributing time to logical continuations rather than just stack frames.
  • Typical users: Developers debugging complex async orchestration, event-driven systems, or CPS-transformed code (compilers, transpilers, or frameworks that convert sync code to CPS).

How it differs from common profiler types

  • Sampling profilers (e.g., perf, Linux perf, Chrome CPU profiler):

    • Sampling captures stack snapshots at intervals.
    • Strength: low overhead and good for CPU hotspots.
    • Weakness: misses short-lived functions and can’t always reconstruct async flows.
    • CPS Profiler advantage: better at mapping asynchronous continuations and callback chains that sampling miss.
  • Instrumenting profilers (e.g., Xdebug, dotTrace with instrumentation):

    • Instrumentation records entry/exit for every function call.
    • Strength: very accurate timing per function.
    • Weakness: high overhead, can perturb timing, verbose traces.
    • CPS Profiler advantage: often strikes a balance—targets continuation points and async boundaries rather than every call, reducing overhead while preserving async context.
  • Tracing profilers / distributed tracing (e.g., Jaeger, Zipkin, OpenTelemetry):

    • Focus on end-to-end request traces across services, with spans and metadata.
    • Strength: excellent for cross-process latency and distributed systems.
    • Weakness: not always detailed about in-process call-stack shapes or micro-level CPU hotspots.
    • CPS Profiler advantage: deeper in-process view of async continuation topology; can complement distributed traces by resolving intra-process async behavior.
  • Memory profilers (e.g., Valgrind massif, dotMemory):

    • Focus on allocations, leaks, and memory lifetimes.
    • Strength: pinpoint memory usage issues.
    • Weakness: not focused on timing or async flow.
    • CPS Profiler advantage: not a memory tool—use alongside memory profilers when async behavior links to leaks (e.g., lingering closures).

When CPS Profiler wins for debugging

  • Your app heavily uses callbacks, promises, generators, or CPS-transformed code and bugs stem from unexpected continuation ordering, lost context, or callback chains.
  • You need to attribute latency to logical continuations instead of raw call stacks.
  • You want lower overhead than full instrumentation but richer async context than sampling.

When another profiler is better

  • You need CPU hotspot analysis for short-lived functions: use a sampling profiler.
  • You must measure exact per-function timings and call counts in synchronous code: use an instrumenting profiler.
  • Your problem is cross-service latency or end-to-end traces: use distributed tracing.
  • You’re diagnosing memory leaks: use a memory profiler.

Practical approach (recommended)

  1. Start with a sampling profiler to find coarse CPU hotspots.
  2. If issues involve async ordering or continuations, run CPS Profiler to inspect continuation chains and async context.
  3. Use distributed tracing to correlate in-process findings with external services.
  4. Run a memory profiler if you suspect allocations or leaks tied to async closures.

Quick comparison table

Focus Best for Overhead Async continuation visibility
CPS Profiler Complex async/CPS flows Low–moderate High
Sampling profiler CPU hotspots Low

Comments

Leave a Reply