Build Profiling
There are three ways to get information about compile times:- Using
time ninja installfor overall timing - Reading Ninja’s log files for per-file compile times
- 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 expectspythonto be available)- Make
ninjatracingexecutable and available in your PATH
Usage
Generate build trace
Generate build trace
Step 1: Clean the buildClean build artifacts and ccache to ensure every file is compiled:Step 2: Build with NinjaStep 3: Convert log to JSONThe log is written to Step 4: VisualizeDrag and drop
.ninja_log in the current directory:trace.json onto Speedscope or any compatible flamegraph visualizer.Compiler Time Reports
GCC -ftime-report
Adding the-ftime-report flag to GCC outputs a breakdown for each compiled file.
Enable GCC time reporting
Enable GCC time reporting
Edit Optionally add
CMakeLists.txt in the Serenity root directory and add around line 220:-ftime-report-details for more detail.Example GCC output
Example GCC output
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
Theprofile command records profiling information that can be viewed with ProfileViewer.
Basic Usage
Profile a specific process
Profile a specific process
System-wide profiling
System-wide profiling
/sys/kernel/profile.Event-specific profiling
Event-specific profiling
Track specific event types with the Available event types:
-t flag:sample- Sampling eventscontext_switch- Context switchespage_fault- Page faultssyscall- System callsread- Read operationskmalloc- Kernel memory allocationskfree- Kernel memory frees
Options
| Option | Description |
|---|---|
-p PID | Target specific process ID |
-a | Profile all processes (super-user only) |
-e | Enable profiling |
-d | Disable profiling |
-f | Free the profiling buffer |
-w | Enable profiling and wait for user input to disable |
-t event_type | Track specific event type |
ProfileViewer
ProfileViewer is a GUI application for viewing profiling data produced byprofile.
Launch it from the Applications menu or command line:
- Flame graphs of execution time
- Call tree analysis
- Timeline views
- Per-function statistics
