Skip to content
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

[ESP32] Added new Matter Traces in esp32 platform for diagnosis #36873

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ee8624e
esp32 diagnostic trace
pimpalemahesh Oct 10, 2024
06ead62
esp32 diagnostic trace changes
pimpalemahesh Oct 25, 2024
6175cdf
example/temperature-measurement-app
pimpalemahesh Nov 14, 2024
1bd882a
backend: Add description for diagnosticstorage interface, remove unnc…
pimpalemahesh Nov 15, 2024
d83dc21
temperature_measurement_app: Review changes
pimpalemahesh Nov 19, 2024
168a5ac
esp32_diagnostic_trace: Review changes
pimpalemahesh Nov 26, 2024
a98b1f8
backend: Replace linkedlist with map for counter diagnostics
pimpalemahesh Nov 21, 2024
51b0772
backend: Pass diagnostic storage as a parameter to backend
pimpalemahesh Nov 27, 2024
3338979
esp32_diagnostic_trace: Return actual data size
pimpalemahesh Dec 1, 2024
321c392
temperature_measurement_app: Review changes
pimpalemahesh Nov 19, 2024
5a80c25
backend: Replace linkedlist with map for counter diagnostics
pimpalemahesh Nov 21, 2024
ec041b9
esp32_diagnostic_trace: add CircularDiagnosticBuffer class to improve…
pimpalemahesh Dec 6, 2024
0befb4f
esp32_diagnostic_trace: add extra tlv closing bytes check before copy…
pimpalemahesh Dec 9, 2024
7e88a79
diagnostic_storage: unify diagnostic entries into a single type
pimpalemahesh Dec 10, 2024
4ce5d09
diagnostic_storage: remove redundant code
pimpalemahesh Dec 10, 2024
48ad096
backend: Remove redundant code, allow only permited value to trace in…
pimpalemahesh Dec 11, 2024
e8db459
example: Remove redundant code
pimpalemahesh Dec 11, 2024
14cceae
esp32: add ble related diagnostics to platform
pimpalemahesh Nov 28, 2024
792af96
esp32: add wifi related diagnostics to platform
pimpalemahesh Nov 28, 2024
fd99413
esp32: add heap related diagnostics to platform
pimpalemahesh Dec 9, 2024
a3e478d
esp32: add freertos task related diagnostics to platform
pimpalemahesh Dec 17, 2024
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
14 changes: 14 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ if (CONFIG_ENABLE_ESP_INSIGHTS_TRACE)
chip_gn_arg_append("matter_trace_config" "\"${CHIP_ROOT}/src/tracing/esp32_trace:esp32_trace_tracing\"")
endif()

if (CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE)
chip_gn_arg_bool("matter_enable_tracing_support" "true")
chip_gn_arg_append("matter_trace_config" "\"${CHIP_ROOT}/src/tracing/esp32_diagnostic_trace:esp32_diagnostic_tracing\"")
endif()

if (CONFIG_ENABLE_ESP_INSIGHTS_SYSTEM_STATS)
chip_gn_arg_append("matter_enable_esp_insights_system_stats" "true")
endif()
Expand All @@ -310,6 +315,10 @@ if (CONFIG_ENABLE_ESP_INSIGHTS_TRACE)
target_include_directories(${COMPONENT_LIB} INTERFACE "${CHIP_ROOT}/src/tracing/esp32_trace/include")
endif()

if (CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE)
target_include_directories(${COMPONENT_LIB} INTERFACE "${CHIP_ROOT}/src/tracing/esp32_diagnostic_trace/include")
endif()

if (CONFIG_CHIP_DEVICE_ENABLE_DYNAMIC_SERVER)
chip_gn_arg_append("chip_build_controller_dynamic_server" "true")
endif()
Expand Down Expand Up @@ -371,6 +380,11 @@ if (CONFIG_ENABLE_ESP_INSIGHTS_TRACE)
list(APPEND chip_libraries "${CMAKE_CURRENT_BINARY_DIR}/lib/libEsp32TracingBackend.a")
endif()

if (CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE)
list(APPEND chip_libraries "${CMAKE_CURRENT_BINARY_DIR}/lib/libEsp32DiagnosticsBackend.a")
endif()


# When using the pregenerated files, there is a edge case where an error appears for
# undeclared argument chip_code_pre_generated_directory. To get around with it we are
# disabling the --fail-on-unused-args flag.
Expand Down
24 changes: 15 additions & 9 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,13 @@ menu "CHIP Device Layer"
NVS namespace. If this option is enabled, the application can use an API to set a CD,
the configured CD will be used for subsequent CD reads.

config ENABLE_ESP_DIAGNOSTICS_TRACE
bool "Enable ESP Platform Diagnostics for Matter"
default n
help
Enables the ESP Diagnostics platform to collect, store, and retrieve diagnostic data for the Matter protocol.
This feature helps monitor system health and performance by providing insights through diagnostics logs.

config ENABLE_ESP_INSIGHTS_TRACE
bool "Enable Matter ESP Insights"
depends on ESP_INSIGHTS_ENABLED
Expand All @@ -1015,15 +1022,14 @@ menu "CHIP Device Layer"
help
This option enables the system statistics to be sent to the insights cloud.

config MAX_PERMIT_LIST_SIZE
int "Set permit list size for Insights traces"
range 5 30
depends on ESP_INSIGHTS_ENABLED
default 20
help
Maximum number of group entries that can be included in the permit list for reporting
the traces to insights.

config MAX_PERMIT_LIST_SIZE
int "Set permit list size for Insights traces"
range 5 30
depends on ESP_INSIGHTS_ENABLED || ENABLE_ESP_DIAGNOSTICS_TRACE
default 20
help
Set the maximum number of group entries that can be included in the permit list for reporting
traces to Insights or diagnostics. This ensures proper management of trace reporting capacity.
endmenu


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,14 @@ depends on ENABLE_PW_RPC
about available pin numbers for UART.

endmenu

menu "Platform Diagnostics"

config END_USER_BUFFER_SIZE
int "Set buffer size for end user diagnostic data"
depends on ENABLE_ESP_DIAGNOSTICS_TRACE
default 4096
help
Defines the buffer size (in bytes) for storing diagnostic data related to end user activity.
This buffer will hold logs and traces relevant to user interactions with the Matter protocol.
endmenu
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ size_t LogProvider::GetSizeForIntent(IntentEnum intent)
{
switch (intent)
{
case IntentEnum::kEndUserSupport:
case IntentEnum::kEndUserSupport: {
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
return CircularDiagnosticBuffer::GetInstance().GetDataSize();
#else
return static_cast<size_t>(endUserSupportLogEnd - endUserSupportLogStart);
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
}
break;
case IntentEnum::kNetworkDiag:
return static_cast<size_t>(networkDiagnosticLogEnd - networkDiagnosticLogStart);
case IntentEnum::kCrashLogs:
Expand Down Expand Up @@ -108,8 +114,21 @@ CHIP_ERROR LogProvider::PrepareLogContextForIntent(LogContext * context, IntentE
switch (intent)
{
case IntentEnum::kEndUserSupport: {
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
CircularDiagnosticBuffer & diagnosticStorage = CircularDiagnosticBuffer::GetInstance();
MutableByteSpan endUserSupportSpan(endUserBuffer, CONFIG_END_USER_BUFFER_SIZE);

VerifyOrReturnError(!diagnosticStorage.IsEmptyBuffer(), CHIP_ERROR_NOT_FOUND,
ChipLogError(DeviceLayer, "Empty Diagnostic buffer"));
// Retrieve data from the diagnostic storage
CHIP_ERROR err = diagnosticStorage.Retrieve(endUserSupportSpan);
VerifyOrReturnError(err == CHIP_NO_ERROR, err,
ChipLogError(DeviceLayer, "Failed to retrieve data: %s", chip::ErrorStr(err)));
context->EndUserSupport.span = endUserSupportSpan;
#else
context->EndUserSupport.span =
ByteSpan(&endUserSupportLogStart[0], static_cast<size_t>(endUserSupportLogEnd - endUserSupportLogStart));
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@
#pragma once

#include <app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h>

#include <map>

#if defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF)
#include <esp_core_dump.h>
#endif // defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF)

#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
#include <tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h>
static uint8_t endUserBuffer[CONFIG_END_USER_BUFFER_SIZE];
using namespace chip::Tracing::Diagnostics;
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE

namespace chip {
namespace app {
namespace Clusters {
Expand Down
11 changes: 10 additions & 1 deletion examples/temperature-measurement-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include <DeviceInfoProviderImpl.h>
#endif // CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER

#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
#include <tracing/esp32_diagnostic_trace/DiagnosticTracing.h>
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE

namespace {
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
Expand All @@ -75,14 +79,19 @@ static AppDeviceCallbacks EchoCallbacks;
static void InitServer(intptr_t context)
{
Esp32AppServer::Init(); // Init ZCL Data Model and CHIP App Server AND Initialize device attestation config
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
CircularDiagnosticBuffer & diagnosticStorage = CircularDiagnosticBuffer::GetInstance();
diagnosticStorage.Init(endUserBuffer, CONFIG_END_USER_BUFFER_SIZE);
static ESP32Diagnostics diagnosticBackend(diagnosticStorage);
Tracing::Register(diagnosticBackend);
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
}

extern "C" void app_main()
{
#if CONFIG_ENABLE_PW_RPC
chip::rpc::Init();
#endif

ESP_LOGI(TAG, "Temperature sensor!");

// Initialize the ESP NVS layer.
Expand Down
3 changes: 3 additions & 0 deletions scripts/tools/check_includes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
'src/tracing/json/json_tracing.cpp': {'string', 'sstream'},
'src/tracing/json/json_tracing.h': {'fstream', 'unordered_map', 'string'},

# esp32 diagnostic tracing
'src/tracing/esp32_diagnostic_trace/Counter.h': {'map'},

# esp32 tracing
'src/tracing/esp32_trace/esp32_tracing.h': {'unordered_map'},

Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static_library("ESP32") {
"${chip_root}/src/lib/dnssd:platform_header",
"${chip_root}/src/platform/logging:headers",
"${chip_root}/src/setup_payload",
"${chip_root}/src/tracing:macros",
]

public = [
Expand Down
4 changes: 4 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
void OnStationDisconnected(void);
void ChangeWiFiStationState(WiFiStationState newState);
static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState);
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
void LogWiFiInfo(void);
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
WiFiAPMode _GetWiFiAPMode(void);
Expand Down Expand Up @@ -176,6 +179,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,

// ===== Members for internal use by the following friends.


friend ConnectivityManager & ConnectivityMgr(void);
friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);

Expand Down
Loading
Loading