Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/MicroOcpp/Core/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void mo_mem_print_stats() {

for (const auto& heapEntry : memBlocks) {
size += heapEntry.second.size;
#if MO_DBG_LEVEL >= MO_DL_DEBUG
#if MO_DBG_LEVEL >= MO_DL_VERBOSE
{
MO_CONSOLE_PRINTF("@%p - %zu B (%s)\n", heapEntry.first, heapEntry.second.size, heapEntry.second.tag.c_str());
}
Expand Down Expand Up @@ -254,6 +254,41 @@ void mo_mem_print_stats() {
#endif
}

int mo_mem_write_stats_json(char *buf, size_t size) {
DynamicJsonDocument doc {size * 2};

doc["total_current"] = memTotal;
doc["total_max"] = memTotalMax;
doc["total_blocks"] = memBlocks.size();

JsonArray by_tag = doc.createNestedArray("by_tag");
for (const auto& tag : memTags) {
JsonObject entry = by_tag.createNestedObject();
entry["tag"] = tag.first.c_str();
entry["current"] = tag.second.current_size;
entry["max"] = tag.second.max_size;
}

size_t untagged = 0, untagged_size = 0;

for (const auto& heapEntry : memBlocks) {
if (heapEntry.second.tag.empty()) {
untagged ++;
untagged_size += heapEntry.second.size;
}
}

doc["untagged_blocks"] = untagged;
doc["untagged_size"] = untagged_size;

if (doc.overflowed()) {
MO_DBG_ERR("exceeded JSON capacity");
return -1;
}

return (int)serializeJson(doc, buf, size);
}

#endif //MO_OVERRIDE_ALLOCATION && MO_ENABLE_HEAP_PROFILER

namespace MicroOcpp {
Expand Down
Loading