1+ #include " sdkconfig.h"
2+ #ifdef CONFIG_ESP_INSIGHTS_ENABLED
3+ #include " Metrics.h"
4+ #include " esp_diagnostics_metrics.h"
5+ #include " esp_diagnostics_system_metrics.h"
6+
7+ static esp_err_t err;
8+
9+ esp_err_t MetricsClass::init (esp_diag_metrics_config_t *config)
10+ {
11+ return esp_diag_metrics_init (config);
12+ }
13+
14+ esp_err_t MetricsClass::registerMetric (const char *tag, const char *key, const char *label, const char *path, esp_diag_data_type_t type)
15+ {
16+ err = esp_diag_metrics_register (tag, key, label, path, type);
17+ if (err != ESP_OK) {
18+ log_e (" Failed to register metric. key: %s, err:0x%x" , key, err);
19+ }
20+ return err;
21+ }
22+
23+ esp_err_t MetricsClass::unregister (const char *key)
24+ {
25+ err = esp_diag_metrics_unregister (key);
26+ if (err != ESP_OK) {
27+ log_e (" Failed to unregister metric. key: %s, err:0x%x" , key, err);
28+ }
29+ return err;
30+ }
31+
32+ esp_err_t MetricsClass::unregisterAll ()
33+ {
34+ return esp_diag_metrics_unregister_all ();
35+ }
36+
37+ esp_err_t MetricsClass::add (esp_diag_data_type_t data_type, const char *key, const void *val, size_t val_sz, uint64_t ts)
38+ {
39+ return esp_diag_metrics_add (data_type, key, val, val_sz, ts);
40+ }
41+
42+ esp_err_t MetricsClass::addBool (const char *key, bool b)
43+ {
44+ return esp_diag_metrics_add_bool (key, b);
45+ }
46+
47+ esp_err_t MetricsClass::addInt (const char *key, int32_t i)
48+ {
49+ return esp_diag_metrics_add_int (key, i);
50+ }
51+
52+ esp_err_t MetricsClass::addUint (const char *key, uint32_t u)
53+ {
54+ return esp_diag_metrics_add_uint (key, u);
55+ }
56+
57+ esp_err_t MetricsClass::addFloat (const char *key, float f)
58+ {
59+ return esp_diag_metrics_add_float (key, f);
60+ }
61+
62+ esp_err_t MetricsClass::addIPv4 (const char *key, uint32_t ip)
63+ {
64+ return esp_diag_metrics_add_ipv4 (key, ip);
65+ }
66+
67+ esp_err_t MetricsClass::addMAC (const char *key, uint8_t *mac)
68+ {
69+ return esp_diag_metrics_add_mac (key, mac);
70+ }
71+
72+ esp_err_t MetricsClass::addString (const char *key, const char *str)
73+ {
74+ return esp_diag_metrics_add_str (key, str);
75+ }
76+
77+ esp_err_t MetricsClass::initHeapMetrics ()
78+ {
79+ err = esp_diag_heap_metrics_init ();
80+ if (err != ESP_OK) {
81+ log_e (" Failed to initialize heap metrics, err=0x%x" , err);
82+ }
83+ return err;
84+ }
85+
86+ esp_err_t MetricsClass::dumpHeapMetrics ()
87+ {
88+ err = esp_diag_heap_metrics_dump ();
89+ if (err != ESP_OK) {
90+ log_e (" Failed to dump heap metrics, err=0x%x" , err);
91+ }
92+ return err;
93+ }
94+
95+ esp_err_t MetricsClass::initWiFiMetrics ()
96+ {
97+ err = esp_diag_wifi_metrics_init ();
98+ if (err != ESP_OK) {
99+ log_e (" Failed to initialize WiFi metrics, err=0x%x" , err);
100+ }
101+ return err;
102+ }
103+
104+ esp_err_t MetricsClass::dumpWiFiMetrics ()
105+ {
106+ err = esp_diag_wifi_metrics_dump ();
107+ if (err != ESP_OK) {
108+ log_e (" Failed to dump heap metrics, err=0x%x" , err);
109+ }
110+ return err;
111+ }
112+
113+ esp_err_t MetricsClass::deinit ()
114+ {
115+ return esp_diag_metrics_deinit ();
116+ }
117+
118+ void MetricsClass::resetHeapMetricsInterval (uint32_t period)
119+ {
120+ return esp_diag_heap_metrics_reset_interval (period);
121+ }
122+
123+ void MetricsClass::resetWiFiMetricsInterval (uint32_t period)
124+ {
125+ return esp_diag_wifi_metrics_reset_interval (period);
126+ }
127+
128+ esp_err_t MetricsClass::deinitHeapMetrics ()
129+ {
130+ return esp_diag_heap_metrics_deinit ();
131+ }
132+
133+ esp_err_t MetricsClass::deinitWiFiMetrics ()
134+ {
135+ return esp_diag_wifi_metrics_deinit ();
136+ }
137+
138+ MetricsClass Metrics;
139+ #endif
0 commit comments