Introducing Swift Profile Recorder

Profiling enables you to understand where your Swift application spends its time — whether it’s computing, waiting for a lock acquisition, or blocked in file I/O. Profiling is achieved by collecting samples of activity, which provide insight into how it’s being used.

Modern operating systems have tooling available to profile your applications or even the whole system. Examples include Apple’s Instruments, sample, and Linux’s perf. Furthermore, there are kernel systems like DTrace or eBPF that can be used to profile your applications.

swift.org/blog/swift-profile-recorder

Apple has open-sourced Swift Profile Recorder, an in-process sampling profiler for Swift services, enabling easy performance analysis without external tools or special privileges. It runs within the application process, supporting macOS and Linux, and integrates via a Swift package with a simple HTTP endpoint for collecting samples using curl.

Profiles output in industry-standard formats like Linux perf, pprof, and collapsed stacks, compatible with tools like Speedscope, Firefox Profiler, and FlameGraph for visualisation. Used at Apple for years to debug latency-sensitive services, it addresses challenges in sandboxed or restricted environments where tools like eBPF are unavailable.

The package supports continuous profiling and can feed data to systems like Parca or Pyroscope, complementing swift-parca for broader ecosystem use. Developers can add it to projects with minimal setup, start the server via environment variables, and collect samples for analysis, with community feedback welcomed on GitHub.

This tool lowers barriers to profiling Swift server applications, enhancing performance insights across deployment environments.


Category:

Tag:

Year: