Implementation:Vllm project Vllm Report Build Time Ninja
| Knowledge Sources | |
|---|---|
| Domains | Build_System, Diagnostics |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Command-line tool that parses ninja build logs to identify build bottlenecks by computing weighted build times that account for task parallelism.
Description
report_build_time_ninja.py analyzes .ninja_log files to produce a summary of the longest build steps in a ninja-based compilation. Originally derived from Chromium's post_build_ninja_summary.py, it calculates "weighted duration" for each build step -- the elapsed time divided by the number of concurrently running tasks. This weighted metric reveals the true critical-path impact of each step, distinguishing between steps that are slow because they are serialized versus those that merely have long elapsed times but overlap with many other parallel tasks.
The tool groups build steps by file extension (e.g., .cu.o, .cpp.o, .so) and reports the top longest steps per group along with overall parallelism statistics.
Usage
Developers use this tool after building vLLM to understand which compilation steps are bottlenecks. It is especially useful for optimizing CUDA kernel compilation times (e.g., identifying that scaled_mm_c2x.cu or attention kernels dominate the build). Run it with the -C flag pointing at the CMake build directory.
Code Reference
Source Location
- Repository: vllm
- File: tools/report_build_time_ninja.py
- Lines: 1-325
Signature
class Target:
def __init__(self, start: float, end: float) -> None: ...
def Duration(self) -> float: ...
def SetWeightedDuration(self, weighted_duration: float) -> None: ...
def WeightedDuration(self) -> float: ...
def DescribeTargets(self) -> str: ...
def ReadTargets(log, show_all) -> list[Target]: ...
def GetExtension(target: Target, extra_patterns) -> str: ...
def SummarizeEntries(entries: list[Target], extra_step_types) -> None: ...
def main() -> int | None: ...
Import
# This is a standalone CLI tool, not typically imported.
# Run directly:
# python3 tools/report_build_time_ninja.py -C build/temp.linux-x86_64-cpython-312
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| -C / --build-directory | str | No | Path to the build directory containing .ninja_log |
| --log-file | str | No | Explicit path to a specific .ninja_log file to analyze |
| -s / --step-types | str | No | Semicolon-separated fnmatch patterns for custom build-step grouping |
Outputs
| Name | Type | Description |
|---|---|---|
| stdout summary | text | Formatted report of longest build steps per extension, weighted times, parallelism ratio, and build step count |
| return code | int | 0 on success, errno.ENOENT if log file is not found |
Usage Examples
# Analyze the default build directory
# $ python3 tools/report_build_time_ninja.py -C build/temp.linux-x86_64-cpython-312
# Analyze a specific ninja log file
# $ python3 tools/report_build_time_ninja.py --log-file /path/to/.ninja_log
# Group by custom step type patterns
# $ python3 tools/report_build_time_ninja.py -C build/ -s "machete_mm;scaled_mm"
# Example output:
# Longest build steps for .cu.o:
# 344.8 weighted s to build ...attention_...cu.o (1087.2 s elapsed time)
# 1110.0 s weighted time (10120.4 s elapsed time sum, 9.1x parallelism)
# 134 build steps completed, average of 0.12/s