Hasty Briefsbeta

Bilingual

Pyro Caml Continuous Profiler for OCaml

5 hours ago
  • #OCaml
  • #Performance Monitoring
  • #Continuous Profiling
  • Semgrep's core SAST engine is written in OCaml, which lacks extensive libraries for observability, a challenge for industrial-scale operation.
  • Pyro Caml, a continuous profiler for OCaml, is introduced to address the need for profiling in production environments without direct developer access.
  • Continuous profiling differs from normal profiling by running in production, sampling data continuously, and reporting to a central location, crucial for Semgrep's performance monitoring.
  • Requirements for a continuous profiler in Semgrep include compatibility with gVisor (excluding perf_event_open), OCaml support, maturity, and minimal performance overhead (<5%).
  • Pyro Caml uses Memprof for call stack sampling based on allocations, compensating for time-based inaccuracies by adjusting sampling rates and leveraging OCaml's Runtime Events for low-overhead event emission.
  • The profiler integrates with Pyroscope via Rust FFI using caml-rs, allowing OCaml code to call into the Pyroscope SDK for data reporting.
  • Despite caveats like missing samples in FFI calls and deeply nested recursion, Pyro Caml has proven effective in production, helping identify performance bottlenecks with acceptable overhead.
  • Future improvements may include better handling of FFI and garbage collector events, memory profiling integration, and addressing recursive function depth limits.