Skip to content

Commit

Permalink
Integration of Silabs Tracing with matter log metric event as well as…
Browse files Browse the repository at this point in the history
… in our bootloader and at bootup, timer needs to be figured out.
  • Loading branch information
lpbeliveau-silabs committed Nov 22, 2024
1 parent e66991b commit b64e7b7
Show file tree
Hide file tree
Showing 15 changed files with 548 additions and 19 deletions.
24 changes: 24 additions & 0 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
#include "sl_power_manager.h"
#endif

#include <matter/tracing/build_config.h>
#if MATTER_TRACING_ENABLED
#include <platform/silabs/tracing/BackendImpl.h>
#include <platform/silabs/tracing/SilabsTracing.h>
#include <tracing/registry.h>
#endif // MATTER_TRACING_ENABLED

/**********************************************************
* Defines
*********************************************************/
Expand All @@ -101,6 +108,11 @@ using namespace ::chip::DeviceLayer;
using namespace ::chip::Credentials;
using namespace chip::DeviceLayer::Silabs;

#if MATTER_TRACING_ENABLED
using TimeTraceOperation = chip::Tracing::Silabs::TimeTraceOperation;
using SilabsTracer = chip::Tracing::Silabs::SilabsTracer;
#endif // MATTER_TRACING_ENABLED

#if CHIP_ENABLE_OPENTHREAD
#include <inet/EndPointStateOpenThread.h>
#include <openthread/cli.h>
Expand Down Expand Up @@ -205,6 +217,13 @@ void SilabsMatterConfig::AppInit()
sMainTaskHandle = osThreadNew(ApplicationStart, nullptr, &kMainTaskAttr);
ChipLogProgress(DeviceLayer, "Starting scheduler");
VerifyOrDie(sMainTaskHandle); // We can't proceed if the Main Task creation failed.

#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kMatterInit);
#endif // MATTER_TRACING_ENABLED
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kBootup);
#endif // MATTER_TRACING_ENABLED
GetPlatform().StartScheduler();

// Should never get here.
Expand Down Expand Up @@ -312,6 +331,11 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
// Init Matter Server and Start Event Loop
err = chip::Server::GetInstance().Init(initParams);

#if MATTER_TRACING_ENABLED
static Tracing::Silabs::BackendImpl backend;
Tracing::Register(backend);
#endif // MATTER_TRACING_ENABLED

chip::DeviceLayer::PlatformMgr().UnlockChipStack();

ReturnErrorOnFailure(err);
Expand Down
156 changes: 156 additions & 0 deletions examples/platform/silabs/MatterShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
#include <cmsis_os2.h>
#include <lib/core/CHIPCore.h>
#include <lib/shell/Engine.h>
#include <matter/tracing/build_config.h>
#include <sl_cmsis_os2_common.h>
#ifdef SL_CATALOG_CLI_PRESENT
#include "sl_cli.h"
#include "sl_cli_config.h"
#include "sli_cli_io.h"
#endif

#if MATTER_TRACING_ENABLED
#include <platform/silabs/tracing/SilabsTracing.h>
#endif // MATTER_TRACING_ENABLED

using namespace ::chip;
using chip::Shell::Engine;

Expand Down Expand Up @@ -112,6 +117,154 @@ void cmdSilabsInit()

#endif // SL_CATALOG_CLI_PRESENT

#if MATTER_TRACING_ENABLED
using TimeTraceOperation = Tracing::Silabs::TimeTraceOperation;

TimeTraceOperation StringToTimeTraceOperation(const char * str)
{
if (strcmp(str, "Spake2p") == 0)
{
return TimeTraceOperation::kSpake2p;
}
else if (strcmp(str, "Pake1") == 0)
{
return TimeTraceOperation::kPake1;
}
else if (strcmp(str, "Pake2") == 0)
{
return TimeTraceOperation::kPake2;
}
else if (strcmp(str, "Pake3") == 0)
{
return TimeTraceOperation::kPake3;
}
else if (strcmp(str, "OperationalCredentials") == 0)
{
return TimeTraceOperation::kOperationalCredentials;
}
else if (strcmp(str, "AttestationVerification") == 0)
{
return TimeTraceOperation::kAttestationVerification;
}
else if (strcmp(str, "CSR") == 0)
{
return TimeTraceOperation::kCSR;
}
else if (strcmp(str, "NOC") == 0)
{
return TimeTraceOperation::kNOC;
}
else if (strcmp(str, "TransportLayer") == 0)
{
return TimeTraceOperation::kTransportLayer;
}
else if (strcmp(str, "TransportSetup") == 0)
{
return TimeTraceOperation::kTransportSetup;
}
else if (strcmp(str, "FindOperational") == 0)
{
return TimeTraceOperation::kFindOperational;
}
else if (strcmp(str, "CaseSession") == 0)
{
return TimeTraceOperation::kCaseSession;
}
else if (strcmp(str, "Sigma1") == 0)
{
return TimeTraceOperation::kSigma1;
}
else if (strcmp(str, "Sigma2") == 0)
{
return TimeTraceOperation::kSigma2;
}
else if (strcmp(str, "Sigma3") == 0)
{
return TimeTraceOperation::kSigma3;
}
else if (strcmp(str, "OTA") == 0)
{
return TimeTraceOperation::kOTA;
}
else if (strcmp(str, "ImageUpload") == 0)
{
return TimeTraceOperation::kImageUpload;
}
else if (strcmp(str, "ImageVerification") == 0)
{
return TimeTraceOperation::kImageVerification;
}
else if (strcmp(str, "AppApplyTime") == 0)
{
return TimeTraceOperation::kAppApplyTime;
}
else if (strcmp(str, "Bootup") == 0)
{
return TimeTraceOperation::kBootup;
}
else if (strcmp(str, "SilabsInit") == 0)
{
return TimeTraceOperation::kSilabsInit;
}
else if (strcmp(str, "MatterInit") == 0)
{
return TimeTraceOperation::kMatterInit;
}
else if (strcmp(str, "BufferFull") == 0)
{
return TimeTraceOperation::kBufferFull;
}
else
{
return TimeTraceOperation::kNumTraces;
}
}

CHIP_ERROR CmdTracingDispatch(int argc, char ** argv)
{
CHIP_ERROR error = CHIP_NO_ERROR;

VerifyOrReturnError(argc > 1, error = CHIP_ERROR_INVALID_ARGUMENT);

if (strcmp(argv[0], "flush") == 0)
{
if (strcmp(argv[1], "all") == 0)
{
error = Tracing::Silabs::SilabsTracer::Instance().TraceBufferFlushAll();
}
else
{
TimeTraceOperation operation = StringToTimeTraceOperation(argv[1]);
error = Tracing::Silabs::SilabsTracer::Instance().TraceBufferFlushByOperation(operation);
}
}
else if (strcmp(argv[0], "watermarks") == 0)
{
if (strcmp(argv[1], "all") == 0)
{
error = Tracing::Silabs::SilabsTracer::Instance().OutputAllWaterMarks();
}
else
{
TimeTraceOperation operation = StringToTimeTraceOperation(argv[1]);
error = Tracing::Silabs::SilabsTracer::Instance().OutputWaterMark(operation);
}
}
else
{
error = CHIP_ERROR_INVALID_ARGUMENT;
}
return error;
}
static const Shell::shell_command_t cmds_silabs_tracing = { &CmdTracingDispatch, "tracing",
"Dispatch Silicon Labs Tracing command" };
void CmdTracingInit()
{
// Register tracing commands with the top-level shell.
Engine::Root().RegisterCommands(&cmds_silabs_tracing, 2);
}
#endif // MATTER_TRACING_ENABLED

void startShellTask()
{
int status = chip::Shell::Engine::Root().Init();
Expand All @@ -127,6 +280,9 @@ void startShellTask()
#ifdef SL_CATALOG_CLI_PRESENT
cmdSilabsInit();
#endif
#if MATTER_TRACING_ENABLED
CmdTracingInit();
#endif // MATTER_TRACING_ENABLED

shellTaskHandle = osThreadNew(MatterShellTask, nullptr, &kShellTaskAttr);
VerifyOrDie(shellTaskHandle);
Expand Down
13 changes: 12 additions & 1 deletion examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
import("${chip_root}/src/app/icd/icd.gni")
import("${chip_root}/src/lib/lib.gni")
import("${chip_root}/src/platform/device.gni")
import("${chip_root}/src/tracing/tracing_args.gni")
import("${silabs_sdk_build_root}/efr32_sdk.gni")
import("${silabs_sdk_build_root}/silabs_board.gni")

Expand Down Expand Up @@ -110,6 +111,9 @@ source_set("matter-shell") {
"${chip_root}/src/lib/shell:shell",
"${chip_root}/src/lib/shell:shell_core",
]
if (matter_enable_tracing_support) {
public_deps += [ "${chip_root}/src/platform/silabs/tracing:SilabsTracing" ]
}
}

config("efr32-common-config") {
Expand Down Expand Up @@ -141,7 +145,10 @@ config("efr32-common-config") {
}

source_set("efr32-common") {
deps = [ "${silabs_common_plat_dir}/provision:storage" ]
deps = [
"${chip_root}/src/tracing",
"${silabs_common_plat_dir}/provision:storage",
]
defines = []
public_deps = []
public_configs = [
Expand Down Expand Up @@ -233,4 +240,8 @@ source_set("efr32-common") {
if (app_data_model != "") {
public_deps += [ app_data_model ]
}

if (matter_enable_tracing_support) {
public_deps += [ "${chip_root}/src/platform/silabs/tracing:SilabsTracing" ]
}
}
23 changes: 22 additions & 1 deletion examples/platform/silabs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,31 @@
#include "sl_system_kernel.h"
#include <MatterConfig.h>

#include <matter/tracing/build_config.h>
#if MATTER_TRACING_ENABLED
#include <platform/silabs/tracing/SilabsTracing.h>
#endif // MATTER_TRACING_ENABLED

#if MATTER_TRACING_ENABLED
using TimeTraceOperation = chip::Tracing::Silabs::TimeTraceOperation;
using SilabsTracer = chip::Tracing::Silabs::SilabsTracer;
#endif // MATTER_TRACING_ENABLED

int main(void)
{
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kBootup);
#endif // MATTER_TRACING_ENABLED
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kSilabsInit);
#endif // MATTER_TRACING_ENABLED
sl_system_init();

#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kSilabsInit);
#endif // MATTER_TRACING_ENABLED
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kMatterInit);
#endif // MATTER_TRACING_ENABLED
// Initialize the application. For example, create periodic timer(s) or
// task(s) if the kernel is present.
SilabsMatterConfig::AppInit();
Expand Down
11 changes: 10 additions & 1 deletion src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni")
import("${chip_root}/build/chip/buildconfig_header.gni")
import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/platform/device.gni")
import("${chip_root}/src/tracing/tracing_args.gni")
import("${chip_root}/third_party/silabs/efr32_sdk.gni")
import("${chip_root}/third_party/silabs/silabs_board.gni")

Expand Down Expand Up @@ -114,9 +115,17 @@ static_library("efr32") {
"${chip_root}/src/platform:platform_base",
"${chip_root}/src/platform/logging:headers",
]
deps = [ "${silabs_platform_dir}/provision:provision-headers" ]
deps = [
"${chip_root}/src/tracing",
"${silabs_platform_dir}/provision:provision-headers",
]

public_configs = []

if (matter_enable_tracing_support) {
public_deps += [ "${chip_root}/src/platform/silabs/tracing:SilabsTracing" ]
}

# Add platform crypto implementation
if (chip_crypto == "platform") {
sources += [
Expand Down
Loading

0 comments on commit b64e7b7

Please sign in to comment.