Skip to content

Commit 8a70495

Browse files
[ESP32] Add Version-Independent Generic APIs for Insights (project-chip#41021) (project-chip#41242)
* feat(insights_trace): add version-independent generic APIs * Update api names
1 parent a9f4e57 commit 8a70495

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/tracing/esp32_trace/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ static_library("backend") {
3333
"counter.h",
3434
"esp32_tracing.cpp",
3535
"esp32_tracing.h",
36+
"matter_esp_insights.h",
3637
]
38+
3739
if (matter_enable_esp_insights_system_stats) {
3840
sources += [
3941
"insights_sys_stats.cpp",

src/tracing/esp32_trace/esp32_tracing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "matter_esp_insights.h"
1920
#include <algorithm>
2021
#include <esp_err.h>
2122
#include <esp_heap_caps.h>
22-
#include <esp_insights.h>
2323
#include <esp_log.h>
2424
#include <memory>
2525
#include <tracing/backend.h>
@@ -201,17 +201,17 @@ void ESP32Backend::LogMetricEvent(const MetricEvent & event)
201201
{
202202
case ValueType::kInt32:
203203
ESP_LOGI("mtr", "The value of %s is %ld ", event.key(), event.ValueInt32());
204-
esp_diag_metrics_add_int(event.key(), event.ValueInt32());
204+
matter_esp_insights_add_int("SYS_MTR", event.key(), event.ValueInt32());
205205
break;
206206

207207
case ValueType::kUInt32:
208208
ESP_LOGI("mtr", "The value of %s is %lu ", event.key(), event.ValueUInt32());
209-
esp_diag_metrics_add_uint(event.key(), event.ValueUInt32());
209+
matter_esp_insights_add_uint("SYS_MTR", event.key(), event.ValueUInt32());
210210
break;
211211

212212
case ValueType::kChipErrorCode:
213213
ESP_LOGI("mtr", "The value of %s is error with code %lu ", event.key(), event.ValueErrorCode());
214-
esp_diag_metrics_add_uint(event.key(), event.ValueErrorCode());
214+
matter_esp_insights_add_uint("SYS_MTR", event.key(), event.ValueErrorCode());
215215
break;
216216

217217
case ValueType::kUndefined:

src/tracing/esp32_trace/insights_sys_stats.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#include "insights_sys_stats.h"
19-
#include <esp_diagnostics_metrics.h>
19+
#include "matter_esp_insights.h"
2020
#include <esp_err.h>
2121
#include <esp_log.h>
2222
#include <platform/CHIPDeviceLayer.h>
@@ -39,7 +39,7 @@ void InsightsSystemMetrics::SamplingHandler(Layer * systemLayer, void * context)
3939
count_t * highwatermarks = GetHighWatermarks();
4040
for (int i = 0; i < System::Stats::kNumEntries; i++)
4141
{
42-
esp_err_t err = esp_diag_metrics_add_uint(instance->mLabels[i], static_cast<uint32_t>(highwatermarks[i]));
42+
esp_err_t err = matter_esp_insights_add_uint("SYS_MTR", instance->mLabels[i], static_cast<uint32_t>(highwatermarks[i]));
4343
if (err != ESP_OK)
4444
{
4545
ESP_LOGE(kTag, "Failed to add the metric:%s, err:%d", instance->mLabels[i], err);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
*/
13+
14+
#pragma once
15+
#include <esp_diagnostics_metrics.h>
16+
17+
esp_err_t matter_esp_insights_add_uint([[maybe_unused]] const char * tag, const char * key, uint32_t u)
18+
{
19+
#ifdef CONFIG_ESP_INSIGHTS_META_VERSION_10
20+
return esp_diag_metrics_add_uint(key, u);
21+
#else
22+
return esp_diag_metrics_report_uint(tag, key, u);
23+
#endif
24+
}
25+
26+
esp_err_t matter_esp_insights_add_int([[maybe_unused]] const char * tag, const char * key, int32_t i)
27+
{
28+
#ifdef CONFIG_ESP_INSIGHTS_META_VERSION_10
29+
return esp_diag_metrics_add_int(key, i);
30+
#else
31+
return esp_diag_metrics_report_int(tag, key, i);
32+
#endif
33+
}

0 commit comments

Comments
 (0)