feat: add ProfileCallback for per-invocation profiling#91
Open
acere wants to merge 1 commit into
Open
Conversation
Adds a new ProfileCallback that instruments each request during a Runner run to capture detailed timing phases, token counts, cache hit info, retries, and throughput metrics. Key features: - Per-invocation profiles with TTFT, generation time (server decode), TPOT, tokens/second, cache hit ratio, reasoning tokens, and retries - Aggregated ProfileReport with time accounting (server vs client), cache hit rate, retry stats, and percentile statistics - Saves profile_report.json and profile_invocations.jsonl alongside run results for post-hoc analysis - Contributes stats to result.stats under the profile_ prefix Also adds plotting utilities in llmeter.plotting for profiling data: - plot_phase_breakdown: stacked bar (TTFT vs generation per request) - plot_request_timeline: Gantt-style concurrency view - plot_throughput_over_time: tok/s scatter with rolling average - plot_time_accounting: pie chart of time split - plot_tpot_distribution: TPOT histogram - plot_ttft_vs_input_tokens: scatter with cache hits highlighted - plot_profile_summary: 2x2 multi-panel dashboard Includes 29 unit tests, API reference docs, and example notebook.
athewsey
force-pushed
the
feat/profile-callback
branch
from
June 24, 2026 08:32
dacb97f to
dc2be88
Compare
Collaborator
|
(Note, seems like this PR depends on plotting.defaults introduced in #89) Just seen a weird intermittent error while testing the example notebook here... Requests failing with: The same happens with Will come back to it later |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #90
Summary
Adds a built-in
ProfileCallbackthat captures per-invocation timing data during a Runner run and produces a structured profiling report.Changes
New:
llmeter/callbacks/profiling.pyInvocationProfiledataclass — per-request record with timing phases, token counts, cache info, retriesProfileReportdataclass — aggregated summary with time accounting, cache hit rate, retry stats, percentile statisticsProfileCallback— lifecycle hooks that collect data and generate the report inafter_runprofile_report.json+profile_invocations.jsonlalongside run resultsNew:
llmeter/plotting/profiling.pyplot_phase_breakdown— stacked bar (TTFT vs generation per request)plot_request_timeline— Gantt-style concurrency viewplot_throughput_over_time— tok/s scatter with rolling averageplot_time_accounting— pie chart (server prefill vs decode vs client overhead)plot_tpot_distribution— TPOT histogramplot_ttft_vs_input_tokens— scatter with cache hits highlightedplot_profile_summary— 2×2 multi-panel dashboardSupporting changes
llmeter/callbacks/__init__.py— exportsProfileCallbackllmeter/plotting/__init__.py— exports profiling plot functionsmkdocs.yml— nav entries for new API reference pagesdocs/reference/callbacks/profiling.md+docs/reference/plotting/profiling.mdexamples/Profiling.ipynb— full walkthrough notebookTests
tests/unit/callbacks/test_profiling.py— 29 tests covering serialization, lifecycle, report computation, stats contribution, file saving, and edge casesTerminology
Clear server/client separation in naming:
Testing
uv run pytest tests/unit/callbacks/test_profiling.py -v # 29 passed uv run ruff check llmeter/callbacks/profiling.py llmeter/plotting/profiling.py