xtest: stats: report heap fragmentation metric #781
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.
A new field is added to struct pta_stats_alloc, free2_sum, the sum of size^2 of each free chunk. This can be used to calculate a fragmentation metric for the heap [1]. Some examples with xtest --stats --alloc:
When booted:
Pool: Heap
Bytes allocated: 21376
Fragmentation: 3 %
Max bytes allocated: 21488
Size of pool: 202608
At some point during xtest:
Pool: Heap
Bytes allocated: 31616
Fragmentation: 54 %
Max bytes allocated: 101312
Size of pool: 202608
When xtest has completed:
Pool: Heap
Bytes allocated: 25824
Fragmentation: 33 %
Max bytes allocated: 101312
Size of pool: 202608
Link: [1] https://asawicki.info/news_1757_a_metric_for_memory_fragmentation