-
Notifications
You must be signed in to change notification settings - Fork 4
Adds a memory_stats metrics component #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,15 @@ void *bm_malloc(size_t size) { return pvPortMalloc(size); } | |
|
|
||
| void bm_free(void *ptr) { vPortFree(ptr); } | ||
|
|
||
| void bm_heap_stats(BmHeapStats *stats) { | ||
| HeapStats_t heap_stats; | ||
| vPortGetHeapStats(&heap_stats); | ||
| stats->free_bytes = (uint32_t)heap_stats.xAvailableHeapSpaceInBytes; | ||
| stats->min_free_bytes = (uint32_t)heap_stats.xMinimumEverFreeBytesRemaining; | ||
| stats->largest_free_block = | ||
| (uint32_t)heap_stats.xSizeOfLargestFreeBlockInBytes; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think having |
||
| } | ||
|
|
||
| BmQueue bm_queue_create(uint32_t queue_length, uint32_t item_size) { | ||
| return xQueueCreate(queue_length, item_size); | ||
| } | ||
|
|
||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #include "memory_metrics.h" | ||
| #include "bm_messages_helper.h" | ||
| #include "bm_os.h" | ||
| #include "metrics_service.h" | ||
| #include "util.h" | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| #define MEMORY_COMPONENT_KEY "memory_stats" | ||
|
|
||
| typedef struct { | ||
| uint32_t heap_free; // bytes currently available | ||
| uint32_t heap_min_free; // low-water mark of available bytes (leak signal) | ||
| uint32_t heap_largest_block; // largest contiguous free block (fragmentation) | ||
| } MemoryValues; | ||
|
|
||
| typedef struct { | ||
| const char *name; | ||
| BmField type; | ||
| size_t offset; // location of the value within MemoryValues | ||
| } MemoryFieldDesc; | ||
|
|
||
| static const MemoryFieldDesc mem_fields[] = { | ||
| {"heap_free", BM_FIELD_UINT32, offsetof(MemoryValues, heap_free)}, | ||
| {"heap_min_free", BM_FIELD_UINT32, offsetof(MemoryValues, heap_min_free)}, | ||
| {"heap_largest_block", BM_FIELD_UINT32, offsetof(MemoryValues, heap_largest_block)}, | ||
| }; | ||
|
|
||
| #define MEMORY_FIELD_COUNT array_size(mem_fields) | ||
|
|
||
| static MemoryValues mem_values; | ||
| static BmEncoderTableEntry mem_lut[MEMORY_FIELD_COUNT]; | ||
|
|
||
| static BmErr memory_metrics_data(const char *metric_key, const BmEncoderTableEntry **lut, | ||
| size_t *num_fields) { | ||
| (void)metric_key; | ||
| BmHeapStats stats; | ||
| bm_heap_stats(&stats); | ||
| mem_values.heap_free = stats.free_bytes; | ||
| mem_values.heap_min_free = stats.min_free_bytes; | ||
| mem_values.heap_largest_block = stats.largest_free_block; | ||
|
|
||
| *lut = mem_lut; | ||
| *num_fields = MEMORY_FIELD_COUNT; | ||
| return BmOK; | ||
| } | ||
|
|
||
| BmErr memory_metrics_init(void) { | ||
| for (size_t f = 0; f < MEMORY_FIELD_COUNT; f++) { | ||
| mem_lut[f].key = mem_fields[f].name; | ||
| mem_lut[f].type = mem_fields[f].type; | ||
| mem_lut[f].value_source = (const uint8_t *)&mem_values + mem_fields[f].offset; | ||
| } | ||
| return metrics_service_add_component(MEMORY_COMPONENT_KEY, memory_metrics_data, | ||
| MEMORY_FIELD_COUNT); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #include "util.h" | ||
|
|
||
| BmErr memory_metrics_init(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also probably update the
bm_posix.cfile to make surebm_sbcapps do not break.