Skip to main content
SerenityOS provides multiple profiling approaches for analyzing both build performance and runtime behavior.

Build Profiling

There are three ways to get information about compile times:
  1. Using time ninja install for overall timing
  2. Reading Ninja’s log files for per-file compile times
  3. Enabling GCC/Clang flags for detailed compiler pass breakdowns

Ninja Log Analysis

Ninja produces a log file with per-cpp-file compilation times, useful for identifying slow-to-compile files.

Prerequisites

  • ninjatracing - Python script to convert Ninja logs
  • python3 (the script expects python to be available)
  • Make ninjatracing executable and available in your PATH

Usage

Step 1: Clean the buildClean build artifacts and ccache to ensure every file is compiled:
Step 2: Build with Ninja
Step 3: Convert log to JSONThe log is written to .ninja_log in the current directory:
Step 4: VisualizeDrag and drop trace.json onto Speedscope or any compatible flamegraph visualizer.
Ninja trace analysis helps identify which files take the most time, making them good targets for optimization.

Compiler Time Reports

GCC -ftime-report

Adding the -ftime-report flag to GCC outputs a breakdown for each compiled file.
Edit CMakeLists.txt in the Serenity root directory and add around line 220:
Optionally add -ftime-report-details for more detail.
Compiler time reports are most useful if you understand compiler internals. For general use, Ninja log analysis is recommended.

Clang -ftime-report

Clang also supports -ftime-report flag with similar functionality.

Runtime Profiling

SerenityOS includes a built-in profiler for analyzing application and system performance.

The profile Command

The profile command records profiling information that can be viewed with ProfileViewer.

Basic Usage

Results are saved to /sys/kernel/profile.
Track specific event types with the -t flag:
Available event types:
  • sample - Sampling events
  • context_switch - Context switches
  • page_fault - Page faults
  • syscall - System calls
  • read - Read operations
  • kmalloc - Kernel memory allocations
  • kfree - Kernel memory frees

Options

ProfileViewer

ProfileViewer is a GUI application for viewing profiling data produced by profile. Launch it from the Applications menu or command line:
It provides:
  • Flame graphs of execution time
  • Call tree analysis
  • Timeline views
  • Per-function statistics

Performance Tips

For accurate profiling results:
  • Use release builds (-DCMAKE_BUILD_TYPE=Release)
  • Disable debug macros that add logging overhead
  • Profile on real hardware when possible, as VM performance varies
On Linux, QEMU is significantly faster with KVM. Ensure /dev/kvm exists and is readable/writable by your user.

See Also

  • Debugging - Debugging tools and techniques
  • Testing - Running and debugging tests
  • strace - System call tracer