Callback timing reportsο
Generate Markdown timing reports from recorded ROS callback traces using pandas and tracetools_analysis.
src.beambot.scripts.perf_trace_summarize Β· Source
Task execution Β· Guide Β· Symbol index
How it is usedο
Use main() to read an existing ros2_tracing CTF directory and produce a Markdown report. collect_callback_stats() builds the underlying table; the other helpers format the report. No robot or ROS node is started by this script.
Interpret the values as callback execution durations and cumulative callback time. They are not message transport latency or end-to-end task duration; overlapping callbacks can contribute time concurrently.
Start hereο
Callable |
Purpose |
|---|---|
Load a CTF trace, compute callback statistics and emit top cumulative-time callbacks, p95 callbacks with at least three samples, and owner rollups. |
|
For callback objects present in the trace instances table, collect duration statistics and resolve symbols/owners with fallbacks for missing registration data. |
Exampleο
From a sourced workspace, summarise an existing trace:
ros2 run beambot perf_trace_summarize.py trace_session --out report.md
The report lists the top 20 entries in each table by default. --out replaces an existing report at that path.
Functionsο
main()ο
Load a CTF trace, compute callback statistics and emit top cumulative-time callbacks, p95 callbacks with at least three samples, and owner rollups.
Entry point Β· Source
main() -> int
Returns: 0 after report output, 1 for no callback data, 2 for missing trace path.
Errors: Trace load/process and report-write errors propagate; argparse handles CLI syntax. βtop is not range-checked and inherits pandas.head behavior.
Side effects: Reads trace files, prints progress to stderr and writes Markdown to stdout or overwrites βout.
collect_callback_stats()ο
For callback objects present in the trace instances table, collect duration statistics and resolve symbols/owners with fallbacks for missing registration data.
Function Β· Source
collect_callback_stats(util: Ros2DataModelUtil) -> pd.DataFrame
Parameter |
Meaning |
|---|---|
|
Ros2DataModelUtil with callback_instances, callback_symbols, duration and owner lookup support. |
Returns: DataFrame with symbol, owner, count, mean_s, p50_s, p95_s, max_s, total_s; all duration columns are seconds. No valid callbacks yields an empty DataFrame without fixed columns.
Errors: Duration lookup Exceptions skip that callback; missing symbol KeyError/AttributeError uses a synthetic name; owner lookup Exceptions use (unknown). Duration conversion/aggregation errors propagate.
Side effects: Reads trace data and allocates a DataFrame; no ROS runtime work.
Referenced in source (1)
mainβ src.beambot.scripts.perf_trace_summarize
Internal callbacks and helpersο
format_duration()ο
Convert a timedelta or numeric seconds into microseconds below one millisecond, milliseconds below one second, otherwise seconds.
Internal helper Β· Source
format_duration(td: pd.Timedelta | np.timedelta64 | float) -> str
Parameter |
Meaning |
|---|---|
|
pandas.Timedelta, NumPy timedelta64 or float-convertible seconds. |
Returns: Formatted string: one decimal for us, two for ms or s. Negative values also follow the us branch.
Errors: Invalid timedelta/numeric conversion errors propagate; no finite-value validation.
Side effects: Pure formatting.
Example
assert format_duration(0.00025) == "250.0 us"
assert format_duration(0.25) == "250.00 ms"
assert format_duration(2) == "2.00 s"
truncate()ο
Preserve text within width, otherwise keep width-1 characters and append a Unicode ellipsis.
Internal helper Β· Source
truncate(text: str, width: int) -> str
Parameter |
Meaning |
|---|---|
|
String to shorten. |
|
Nominal character count; zero/negative widths still return an ellipsis for most nonempty input. |
Returns: Original or truncated string; character count rather than display-column width.
Errors: Nonstring inputs/invalid width types can raise.
Example
assert truncate("abcdef", 4) == "abcβ¦"
assert truncate("abc", 3) == "abc"
Referenced in source (1)
md_tableβ src.beambot.scripts.perf_trace_summarize
md_table()ο
Render selected DataFrame columns as a Markdown table, formatting float columns ending in _s as durations and truncating headers/text.
Internal helper Β· Source
md_table(df: pd.DataFrame, columns: list[tuple[str, str, int]]) -> str
Parameter |
Meaning |
|---|---|
|
DataFrame whose rows contain all named source columns. |
|
Sequence of (column_name, header_text, character_width) tuples. |
Returns: Markdown table string without a trailing newline. Integer cells are not truncated; pipes/newlines in strings are not escaped.
Errors: Missing columns and formatting/type errors propagate.
Side effects: Creates text only.
Referenced in source (1)
mainβ src.beambot.scripts.perf_trace_summarize