Tools: Testbench: Track and print heap usage for modules#10593
Tools: Testbench: Track and print heap usage for modules#10593singalsu wants to merge 1 commit intothesofproject:mainfrom
Conversation
This patch adds to end to sof-testbench4 run print of peak heap consumption for each module. The information is retrieved from heap_high_water_mark data that is tracked by module adapter for each module. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
There was a problem hiding this comment.
Pull request overview
This PR adds reporting of per-module peak heap consumption at the end of a sof-testbench4 run by reading each module’s heap_high_water_mark tracked by the module adapter.
Changes:
- Collect IPC4 module heap high-water marks by iterating the IPC4 widget list and resolving component devices.
- Print per-module heap usage in the test summary output.
- Introduce a small record struct (
tb_heap_usage_record) to pass heap usage data to the stats printer.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tools/testbench/testbench.c | Adds IPC4-only collection of module heap HWM and prints the results in the pipeline stats output. |
| tools/testbench/include/testbench/utils.h | Introduces tb_heap_usage_record used to carry module name and heap HWM to the stats function. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| records[count].module_name = info->name; | ||
| records[count].heap_max = (int)dev->mod->priv.resources.heap_high_water_mark; |
There was a problem hiding this comment.
heap_high_water_mark is a size_t (see src/include/sof/audio/module_adapter/module/generic.h), but it’s being cast to int and printed with %d. This can truncate/overflow and report incorrect (even negative) values on 64-bit hosts. Consider storing heap_max as size_t (or uint64_t) in tb_heap_usage_record and printing with the matching format specifier (e.g., %zu).
| records[count].heap_max = (int)dev->mod->priv.resources.heap_high_water_mark; | |
| /* heap_high_water_mark is size_t; clamp to INT_MAX to avoid overflow */ | |
| { | |
| size_t heap_high_water_mark = dev->mod->priv.resources.heap_high_water_mark; | |
| if (heap_high_water_mark > (size_t)INT_MAX) | |
| records[count].heap_max = INT_MAX; | |
| else | |
| records[count].heap_max = (int)heap_high_water_mark; | |
| } |
| list_for_item(item, &tp->widget_list) | ||
| { | ||
| struct tplg_comp_info *info = container_of(item, struct tplg_comp_info, item); | ||
| uint32_t comp_id = IPC4_COMP_ID(info->module_id, info->instance_id); | ||
| struct comp_dev *dev = ipc4_get_comp_dev(comp_id); | ||
|
|
There was a problem hiding this comment.
Brace placement for list_for_item() is inconsistent with the surrounding testbench codebase (e.g., tools/testbench/topology_ipc4.c:1493 uses list_for_item(...) {). To match the established style, keep the opening { on the same line as the list_for_item(...) statement.
| list_for_item(item, &tp->widget_list) | |
| { | |
| struct tplg_comp_info *info = container_of(item, struct tplg_comp_info, item); | |
| uint32_t comp_id = IPC4_COMP_ID(info->module_id, info->instance_id); | |
| struct comp_dev *dev = ipc4_get_comp_dev(comp_id); | |
| list_for_item(item, &tp->widget_list) { | |
| struct tplg_comp_info *info = container_of(item, struct tplg_comp_info, item); | |
| uint32_t comp_id = IPC4_COMP_ID(info->module_id, info->instance_id); | |
| struct comp_dev *dev = ipc4_get_comp_dev(comp_id); |
|
|
||
| struct tb_heap_usage_record { | ||
| char *module_name; | ||
| int heap_max; |
There was a problem hiding this comment.
heap_max is defined as int, but the source field (heap_high_water_mark) is a size_t. Using size_t heap_max; here (and printing with %zu) avoids truncation/overflow on 64-bit builds and matches the underlying data type.
| int heap_max; | |
| size_t heap_max; |
This patch adds to end to sof-testbench4 run print of peak heap consumption for each module. The information is retrieved from heap_high_water_mark data that is tracked by module adapter for each module.