-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][feat] Add request timing breakdown option in benchmark_serving #8128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: nv-yilinf <206948969+nv-yilinf@users.noreply.github.com>
Signed-off-by: nv-yilinf <206948969+nv-yilinf@users.noreply.github.com>
|
/bot run --disable-fail-fast |
📝 WalkthroughWalkthroughAdds a new time_breakdown tool (library + CLI) for visualizing request timing metrics, integrates optional metrics fetching/diagram generation into benchmark_serving via a new flag, and introduces corresponding tests and docs. Includes an async perf-metrics fetcher, HTML diagram generation with Plotly, and statistics reporting. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant Benchmark as benchmark_serving.py
participant Server as TRT-LLM Server
participant FS as File System
participant TBT as RequestTimeBreakdown
User->>Benchmark: run benchmark (optional --save-request-time-breakdown)
Benchmark->>Server: GET /perf_metrics (aiohttp) [optional]
alt Metrics available
Server-->>Benchmark: 200 JSON (per-request timing)
Benchmark->>FS: save perf_metrics.json
Benchmark->>TBT: create_timing_diagram(perf_metrics.json)
TBT->>FS: write time_breakdown.html
else Error / disabled
Server-->>Benchmark: error or skipped
Benchmark->>Benchmark: log warning/info
end
sequenceDiagram
autonumber
participant User
participant CLI as python -m tensorrt_llm.serve.scripts.time_breakdown
participant Parser as RequestDataParser
participant Analyzer as RequestTimeBreakdown
participant FS as File System
participant Plotly as Plotly
User->>CLI: time_breakdown --input metrics.json [--diagram] [--stats]
CLI->>FS: read metrics.json
CLI->>Parser: parse (agg or disagg)
Parser-->>CLI: normalized per-request timings
CLI->>Analyzer: compute durations
opt --diagram
Analyzer->>Plotly: build stacked bar chart
Plotly-->>Analyzer: figure
Analyzer->>FS: write time_breakdown.html
end
opt --stats
Analyzer-->>User: print statistics
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
tensorrt_llm/serve/scripts/time_breakdown/__init__.py (1)
13-19: Consider sorting__all__alphabetically.While the current logical grouping is reasonable, sorting
__all__alphabetically can improve maintainability and follows isort conventions.Apply this diff to sort alphabetically:
__all__ = [ - 'TimingMetric', - 'TimingMetricsConfig', 'RequestDataParser', 'RequestTimeBreakdown', + 'TimingMetric', + 'TimingMetricsConfig', 'main', ]tensorrt_llm/serve/scripts/time_breakdown/README.md (1)
137-158: Add language specifiers to fenced code blocks.Adding language identifiers to code blocks improves rendering, enables syntax highlighting, and helps documentation tooling properly parse the content.
Apply these changes:
Line 137 - Add
yamlidentifier:-``` +```yaml return_perf_metrics: TrueLine 145 - Add
bashidentifier:-``` +```bash python -m tensorrt_llm.serve.scripts.benchmark_serving \tensorrt_llm/serve/scripts/benchmark_serving.py (1)
602-628: Consider more specific exception handling.The function correctly fetches performance metrics, but the broad
Exceptioncatch at line 625 could mask unexpected errors. Consider catching more specific exceptions likeaiohttp.ClientErrororasyncio.TimeoutError.Apply this diff to improve exception handling:
else: print( f"Failed to fetch performance metrics. Status: {response.status}" ) return {} - except Exception as e: + except (aiohttp.ClientError, asyncio.TimeoutError) as e: print(f"Error fetching performance metrics: {e}") return {} + except Exception as e: + print(f"Unexpected error fetching performance metrics: {e}") + return {}tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (2)
231-244: Consider raising exceptions instead of calling sys.exit().The file error handling works correctly for CLI usage, but calling
sys.exit(1)makes this code unsuitable for library usage. Consider raising exceptions that callers can handle appropriately. The broadExceptioncatch at line 242 is also worth making more specific.For better library design, apply this diff:
def parse_json_file(self, json_file_path: str) -> List[Dict]: """Parse JSON performance metrics file and extract timing information.""" try: with open(json_file_path, 'r') as f: data = json.load(f) except FileNotFoundError: - print(f"Error: File '{json_file_path}' not found.") - sys.exit(1) + raise FileNotFoundError(f"File '{json_file_path}' not found.") except json.JSONDecodeError as e: - print(f"Error parsing JSON file '{json_file_path}': {e}") - sys.exit(1) + raise ValueError(f"Error parsing JSON file '{json_file_path}': {e}") from e - except Exception as e: - print(f"Error reading file '{json_file_path}': {e}") - sys.exit(1) + except OSError as e: + raise OSError(f"Error reading file '{json_file_path}': {e}") from eThen update the CLI
main()function to catch and print these exceptions with sys.exit(1).
270-392: Remove unnecessary f-string prefix at line 391.Line 391 uses an f-string without any placeholders. The visualization logic itself is well-implemented with appropriate Plotly configuration and HTML generation.
Apply this diff to remove the unnecessary f-prefix:
print(f"Interactive time breakdown diagram saved to: {output_file}") - print(f"Open the file in your web browser to interact with the chart!") + print("Open the file in your web browser to interact with the chart!")
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
docs/source/media/request_time_breakdown_example.pngis excluded by!**/*.png
📒 Files selected for processing (7)
tensorrt_llm/serve/scripts/benchmark_serving.py(4 hunks)tensorrt_llm/serve/scripts/time_breakdown/README.md(1 hunks)tensorrt_llm/serve/scripts/time_breakdown/__init__.py(1 hunks)tensorrt_llm/serve/scripts/time_breakdown/__main__.py(1 hunks)tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py(1 hunks)tests/integration/test_lists/test-db/l0_a10.yml(1 hunks)tests/unittest/others/test_time_breakdown.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
tensorrt_llm/serve/scripts/time_breakdown/__main__.pytensorrt_llm/serve/scripts/time_breakdown/__init__.pytests/unittest/others/test_time_breakdown.pytensorrt_llm/serve/scripts/benchmark_serving.pytensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.
Files:
tensorrt_llm/serve/scripts/time_breakdown/__main__.pytensorrt_llm/serve/scripts/time_breakdown/__init__.pytests/unittest/others/test_time_breakdown.pytensorrt_llm/serve/scripts/benchmark_serving.pytensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
tensorrt_llm/serve/scripts/time_breakdown/__main__.pytensorrt_llm/serve/scripts/time_breakdown/__init__.pytests/unittest/others/test_time_breakdown.pytensorrt_llm/serve/scripts/benchmark_serving.pytensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py
🧬 Code graph analysis (5)
tensorrt_llm/serve/scripts/time_breakdown/__main__.py (2)
tensorrt_llm/serve/scripts/benchmark_serving.py (1)
main(630-953)tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (1)
main(482-540)
tensorrt_llm/serve/scripts/time_breakdown/__init__.py (1)
tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (5)
RequestDataParser(160-221)RequestTimeBreakdown(224-479)TimingMetric(32-52)TimingMetricsConfig(55-157)main(482-540)
tests/unittest/others/test_time_breakdown.py (1)
tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (13)
RequestDataParser(160-221)RequestTimeBreakdown(224-479)TimingMetric(32-52)TimingMetricsConfig(55-157)calculate_duration(43-52)get_metric_by_name(143-145)get_metrics_by_server(147-149)add_metric(151-153)remove_metric(155-157)parse_request(163-221)parse_json_file(231-268)create_timing_diagram(270-391)show_statistics(464-479)
tensorrt_llm/serve/scripts/benchmark_serving.py (2)
tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (3)
RequestTimeBreakdown(224-479)parse_json_file(231-268)create_timing_diagram(270-391)tensorrt_llm/serve/openai_disagg_server.py (1)
perf_metrics(200-251)
tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (2)
tensorrt_llm/executor/result.py (1)
request_id(568-569)tensorrt_llm/serve/scripts/benchmark_serving.py (1)
main(630-953)
🪛 markdownlint-cli2 (0.18.1)
tensorrt_llm/serve/scripts/time_breakdown/README.md
137-137: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
145-145: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🪛 Ruff (0.13.3)
tensorrt_llm/serve/scripts/time_breakdown/__main__.py
1-1: Shebang is present but file is not executable
(EXE001)
tensorrt_llm/serve/scripts/time_breakdown/__init__.py
1-1: Shebang is present but file is not executable
(EXE001)
13-19: __all__ is not sorted
Apply an isort-style sorting to __all__
(RUF022)
tests/unittest/others/test_time_breakdown.py
1-1: Shebang is present but file is not executable
(EXE001)
tensorrt_llm/serve/scripts/benchmark_serving.py
625-625: Do not catch blind exception: Exception
(BLE001)
949-949: Do not catch blind exception: Exception
(BLE001)
tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py
1-1: Shebang is present but file is not executable
(EXE001)
242-242: Do not catch blind exception: Exception
(BLE001)
272-272: PEP 484 prohibits implicit Optional
Convert to Optional[T]
(RUF013)
391-391: f-string without any placeholders
Remove extraneous f prefix
(F541)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (20)
tests/integration/test_lists/test-db/l0_a10.yml (1)
22-22: LGTM!The test addition follows the correct format and appropriately integrates the new time_breakdown test into the pre-merge CI pipeline.
tensorrt_llm/serve/scripts/time_breakdown/__init__.py (2)
1-8: LGTM!The module header, license, and docstring are properly formatted. The shebang warning from static analysis can be safely ignored as
__init__.pyfiles are not meant to be executable.
10-11: LGTM!The import statement correctly brings in all public API components from the internal module.
tensorrt_llm/serve/scripts/time_breakdown/__main__.py (1)
1-13: LGTM!The module entry point is correctly implemented, following standard Python conventions for
python -mexecution. The shebang warning can be ignored as this file is designed to be run as a module, not directly executed.tensorrt_llm/serve/scripts/time_breakdown/README.md (1)
1-131: LGTM!The documentation is comprehensive, well-structured, and provides clear explanations of the timing metrics, input formats, and usage patterns.
tensorrt_llm/serve/scripts/benchmark_serving.py (3)
48-48: LGTM!The import is correctly placed and follows the project's import structure.
909-954: LGTM!The integration logic correctly fetches and saves performance metrics, then attempts diagram generation. The broad exception handling at line 949 is appropriate here as it ensures the benchmark results are preserved even if diagram creation fails, which is the correct resilience strategy for this auxiliary feature.
1338-1343: LGTM!The CLI argument is well-defined with a clear help message that accurately describes the functionality.
tests/unittest/others/test_time_breakdown.py (6)
1-22: LGTM!The file header, docstring, and imports are properly structured. The shebang warning can be ignored as test files are typically executed via test runners, not directly.
24-100: LGTM!The TimingMetric tests provide comprehensive coverage including edge cases for missing timestamps and negative durations. The test structure and assertions are appropriate.
102-174: LGTM!The TimingMetricsConfig tests thoroughly exercise the configuration class including default metrics, retrieval methods, and metric management operations.
176-284: LGTM!The RequestDataParser tests comprehensively cover both aggregated and disaggregated data formats, along with edge cases for missing fields and request IDs.
286-462: LGTM!The RequestTimeBreakdown tests provide excellent coverage of the main analysis class, including JSON parsing, error handling, visualization, statistics, and configuration. The use of mocking for plotly operations is appropriate.
464-518: LGTM!The integration test provides comprehensive end-to-end coverage of the complete workflow, with proper temporary file management and cleanup. The test design is robust and follows best practices.
tensorrt_llm/serve/scripts/time_breakdown/time_breakdown.py (6)
1-29: LGTM!The module header, documentation, and imports are well-structured. The comprehensive docstring provides clear usage examples for both CLI and library usage patterns.
31-53: LGTM!The TimingMetric class is well-designed with appropriate use of dataclass and correct duration calculation logic that handles edge cases (missing timestamps and negative durations).
55-158: LGTM!The TimingMetricsConfig class provides a well-structured configuration with comprehensive default metrics and a clean API for metric management. The metric definitions are clear and appropriate for the use case.
160-222: LGTM!The RequestDataParser class correctly handles both aggregated and disaggregated data formats with robust error handling through default values. The parsing logic is clear and comprehensive.
393-480: LGTM!The helper methods are well-implemented. The statistics calculation uses numpy appropriately, HTML generation is clean, and the statistics display provides useful information. All methods properly handle empty or missing data.
482-544: LGTM!The CLI entry point is well-designed with clear argument definitions, helpful examples, and appropriate control flow. The use of
sys.exit(1)is correct in this CLI context.
|
PR_Github #20690 [ run ] triggered by Bot |
|
PR_Github #20690 [ run ] completed with state |
Signed-off-by: nv-yilinf <206948969+nv-yilinf@users.noreply.github.com>
Signed-off-by: nv-yilinf <206948969+nv-yilinf@users.noreply.github.com>
|
/bot run |
|
PR_Github #20741 [ run ] triggered by Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Minor comments.
Signed-off-by: nv-yilinf <206948969+nv-yilinf@users.noreply.github.com>
|
/bot run |
|
PR_Github #20742 [ run ] triggered by Bot |
|
PR_Github #20741 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #20744 [ run ] triggered by Bot |
|
PR_Github #20742 [ run ] completed with state |
Signed-off-by: nv-yilinf <206948969+nv-yilinf@users.noreply.github.com>
|
/bot run --disable-fail-fast |
|
PR_Github #20749 [ run ] triggered by Bot |
|
PR_Github #20744 [ run ] completed with state |
|
PR_Github #20749 [ run ] completed with state |
Summary by CodeRabbit
New Features
Documentation
Tests
Description
The Time Breakdown tool analyzes performance metrics from TensorRT-LLM servers and creates interactive visualizations showing how time is spent processing each request. It supports both aggregated and disaggregated server configurations.
The tool generates:
Interactive HTML Diagram: A stacked bar chart showing timing breakdown per request with hover tooltips

Statistics: Median times for each timing segment (optional)
README
Test Coverage
tests/unittest/others/test_time_breakdown.pyPR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.