-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathheap_monitor.cpp
More file actions
97 lines (89 loc) · 2.57 KB
/
heap_monitor.cpp
File metadata and controls
97 lines (89 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "heap_monitor.hpp"
#include "esp_idf_version.h"
// MALLOC_CAP_TCM was renamed to MALLOC_CAP_SPM in ESP-IDF v6.0
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
#define ESPP_MALLOC_CAP_TCM MALLOC_CAP_SPM
#define ESPP_MALLOC_CAP_TCM_NAME "SPM "
#else
#define ESPP_MALLOC_CAP_TCM MALLOC_CAP_TCM
#define ESPP_MALLOC_CAP_TCM_NAME "TCM "
#endif
using namespace espp;
std::string HeapMonitor::get_region_name(int heap_flags) {
std::string name = "Heap( ";
if (heap_flags & MALLOC_CAP_DEFAULT) {
name += "DEFAULT ";
}
if (heap_flags & MALLOC_CAP_INTERNAL) {
name += "INTERNAL ";
}
if (heap_flags & MALLOC_CAP_SPIRAM) {
name += "SPIRAM ";
}
if (heap_flags & MALLOC_CAP_DMA) {
name += "DMA ";
}
if (heap_flags & MALLOC_CAP_8BIT) {
name += "8BIT ";
}
if (heap_flags & MALLOC_CAP_32BIT) {
name += "32BIT ";
}
if (heap_flags & MALLOC_CAP_RTCRAM) {
name += "RTCRAM ";
}
if (heap_flags & ESPP_MALLOC_CAP_TCM) {
name += ESPP_MALLOC_CAP_TCM_NAME;
}
if (heap_flags & MALLOC_CAP_DMA_DESC_AHB) {
name += "DMA AHB ";
}
if (heap_flags & MALLOC_CAP_DMA_DESC_AXI) {
name += "DMA AXI ";
}
if (heap_flags & MALLOC_CAP_CACHE_ALIGNED) {
name += "CACHE_ALIGNED ";
}
if (heap_flags & MALLOC_CAP_SIMD) {
name += "SIMD ";
}
name += ")";
return name;
}
HeapMonitor::HeapInfo HeapMonitor::get_info(int heap_flags) {
multi_heap_info_t info;
heap_caps_get_info(&info, heap_flags);
HeapInfo heap_info;
heap_info.heap_flags = heap_flags;
heap_info.free_bytes = info.total_free_bytes;
heap_info.min_free_bytes = info.minimum_free_bytes;
heap_info.largest_free_block = info.largest_free_block;
heap_info.allocated_bytes = info.total_allocated_bytes;
heap_info.total_size = heap_caps_get_total_size(heap_flags);
return heap_info;
}
std::vector<HeapMonitor::HeapInfo> HeapMonitor::get_info(const std::vector<int> &heap_flags) {
std::vector<HeapInfo> heap_info_list;
for (const auto &flags : heap_flags) {
heap_info_list.push_back(get_info(flags));
}
return heap_info_list;
}
std::string HeapMonitor::get_table(const std::vector<int> &heap_flags) {
std::string table;
table += get_table_header() + "\n";
auto info_list = get_info(heap_flags);
for (const auto &info : info_list) {
table += fmt::format("{:t}\n", info);
}
return table;
}
std::string HeapMonitor::get_csv(const std::vector<int> &heap_flags) {
std::string table;
table += get_csv_header() + "\n";
auto info_list = get_info(heap_flags);
for (const auto &info : info_list) {
table += fmt::format("{:c}\n", info);
}
return table;
}