Skip to content

Tools: Testbench: Track and print heap usage for modules#10593

Open
singalsu wants to merge 1 commit intothesofproject:mainfrom
singalsu:testbench_print_heap_usage
Open

Tools: Testbench: Track and print heap usage for modules#10593
singalsu wants to merge 1 commit intothesofproject:mainfrom
singalsu:testbench_print_heap_usage

Conversation

@singalsu
Copy link
Collaborator

@singalsu singalsu commented Mar 3, 2026

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.

Example of output (sof-hda-generic.tplg):

Heap usage for module gain.1.1: 708 bytes
Heap usage for module mixin.1.1: 164 bytes
Heap usage for module gain.2.1: 708 bytes
Heap usage for module eqiir.2.1: 316 bytes
Heap usage for module eqfir.2.1: 388 bytes
Heap usage for module drc.2.1: 4316 bytes
Heap usage for module mixout.2.1: 252 bytes

@singalsu singalsu marked this pull request as ready for review March 3, 2026 17:08
Copilot AI review requested due to automatic review settings March 3, 2026 17:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (count >= TB_NUM_WIDGETS_SUPPORTED) {
fprintf(stderr, "Error: Too many components for heap records, max %d.\n",
TB_NUM_WIDGETS_SUPPORTED);
break;
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tb_collect_heap_usage() caps heap records at TB_NUM_WIDGETS_SUPPORTED (16) and breaks out, which will silently drop heap usage for remaining modules on larger topologies. Consider sizing the record buffer to the actual number of non-AIF/DAI components (e.g., first pass to count, then allocate), or introduce a dedicated "max components" constant that is large enough for real-world IPC4 topologies.

Suggested change
break;
*count_out = count;
return -EINVAL;

Copilot uses AI. Check for mistakes.
@singalsu singalsu force-pushed the testbench_print_heap_usage branch from 8fc72b9 to 59b2044 Compare March 4, 2026 16:13
@singalsu singalsu requested a review from Copilot March 4, 2026 16:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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>
@singalsu singalsu force-pushed the testbench_print_heap_usage branch from 59b2044 to e2ea25b Compare March 4, 2026 17:18
@singalsu singalsu requested a review from Copilot March 4, 2026 17:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +706 to +707
void tb_collect_heap_usage(struct testbench_prm *tp, struct tb_heap_usage_record *records,
int *count_out)
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API takes only a pointer to records but doesn't take a capacity/length parameter; instead it hard-codes TB_NUM_WIDGETS_SUPPORTED. This makes the function easy to misuse (potential overflow if a caller passes a smaller array) and couples it to a specific constant. Consider updating the API to accept a records_capacity argument and use that for bounds checks (and optionally return an error code when capacity is exceeded).

Copilot uses AI. Check for mistakes.
Comment on lines +728 to +732
if (count >= TB_NUM_WIDGETS_SUPPORTED) {
fprintf(stderr, "Error: Too many components for heap records, max %d.\n",
TB_NUM_WIDGETS_SUPPORTED);
break;
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API takes only a pointer to records but doesn't take a capacity/length parameter; instead it hard-codes TB_NUM_WIDGETS_SUPPORTED. This makes the function easy to misuse (potential overflow if a caller passes a smaller array) and couples it to a specific constant. Consider updating the API to accept a records_capacity argument and use that for bounds checks (and optionally return an error code when capacity is exceeded).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants