From 39f22449d0464acab03a444dd8ba36b8145c021f Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs Date: Fri, 22 Nov 2024 14:01:57 -0500 Subject: [PATCH] Integrated in lighting app to have complete time to LIGHT-ON, will apply tracing to other apps as well after review of potential app refactor --- examples/lighting-app/silabs/src/AppTask.cpp | 1 + examples/platform/silabs/BaseApplication.cpp | 19 +++++++++++++++++++ examples/platform/silabs/BaseApplication.h | 9 ++++++++- examples/platform/silabs/MatterConfig.cpp | 8 +++++--- .../silabs/efr32/OTAImageProcessorImpl.cpp | 8 +++++++- src/platform/silabs/tracing/SilabsTracing.cpp | 2 ++ src/platform/silabs/tracing/SilabsTracing.h | 1 + 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/examples/lighting-app/silabs/src/AppTask.cpp b/examples/lighting-app/silabs/src/AppTask.cpp index 4f74ca7f34..852163087d 100644 --- a/examples/lighting-app/silabs/src/AppTask.cpp +++ b/examples/lighting-app/silabs/src/AppTask.cpp @@ -105,6 +105,7 @@ CHIP_ERROR AppTask::Init() #endif // QR_CODE_ENABLED #endif + BaseApplication::InitCompleteCallback(err); return err; } diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index b3e3df1744..86c3e83270 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -89,6 +89,12 @@ #include "sl_cmp_config.h" #endif +// Tracing +#include +#if MATTER_TRACING_ENABLED +#include +#endif // MATTER_TRACING_ENABLED + /********************************************************** * Defines and Constants *********************************************************/ @@ -113,6 +119,11 @@ using namespace chip::app; using namespace ::chip::DeviceLayer; 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 + namespace { /********************************************************** @@ -340,6 +351,14 @@ CHIP_ERROR BaseApplication::Init() return err; } +void BaseApplication::InitCompleteCallback(CHIP_ERROR err) +{ +#if MATTER_TRACING_ENABLED + SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kAppInit); + SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kBootup); +#endif // MATTER_TRACING_ENABLED +} + void BaseApplication::FunctionTimerEventHandler(void * timerCbArg) { AppEvent event; diff --git a/examples/platform/silabs/BaseApplication.h b/examples/platform/silabs/BaseApplication.h index 39c0e2cab3..36530c0595 100644 --- a/examples/platform/silabs/BaseApplication.h +++ b/examples/platform/silabs/BaseApplication.h @@ -89,7 +89,7 @@ class BaseApplication public: BaseApplication() = default; - virtual ~BaseApplication() {}; + virtual ~BaseApplication(){}; static bool sIsProvisioned; static bool sIsFactoryResetTriggered; static LEDWidget * sAppActionLed; @@ -122,6 +122,7 @@ class BaseApplication * * @param event AppEvent to post */ + static void PostEvent(const AppEvent * event); /** @@ -176,6 +177,12 @@ class BaseApplication protected: CHIP_ERROR Init(); + /** @brief + * Function to be called at the end of Init to indicate that the application has completed its initialization. + * Currently only used for tracing, might want to move logging here as well in the future + */ + void InitCompleteCallback(CHIP_ERROR err); + /** * @brief Function called to start the function timer * diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 5b29a0af18..7871316230 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -187,6 +187,11 @@ void ApplicationStart(void * unused) if (err != CHIP_NO_ERROR) appError(err); +#if MATTER_TRACING_ENABLED + SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kMatterInit); + SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kAppInit); +#endif // MATTER_TRACING_ENABLED + gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); @@ -218,9 +223,6 @@ void SilabsMatterConfig::AppInit() 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 diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 0c9addf4de..47716d6383 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -356,9 +356,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) } #endif // SL_BTLCTRL_MUX - ChipLogProgress(SoftwareUpdate, "Reboot and install new image..."); #if MATTER_TRACING_ENABLED SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageVerification); + SilabsTracer::Instance().TimeTraceInstant(TimeTraceOperation::kAppApplyTime); +#endif // MATTER_TRACING_ENABLED + ChipLogProgress(SoftwareUpdate, "Reboot and install new image..."); + +#if MATTER_TRACING_ENABLED + // Flush all traces before reboot since we do not store them in NVM currently + SilabsTracer::Instance().TraceBufferFlushAll(); #endif // MATTER_TRACING_ENABLED #if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING osDelay(100); // sl-temp: delay for uart print before reboot diff --git a/src/platform/silabs/tracing/SilabsTracing.cpp b/src/platform/silabs/tracing/SilabsTracing.cpp index 3d0d1107f6..a93f0ee9c3 100644 --- a/src/platform/silabs/tracing/SilabsTracing.cpp +++ b/src/platform/silabs/tracing/SilabsTracing.cpp @@ -82,6 +82,8 @@ const char * TimeTraceOperationToString(TimeTraceOperation operation) return "SilabsInit"; case TimeTraceOperation::kMatterInit: return "MatterInit"; + case TimeTraceOperation::kAppInit: + return "AppInit"; case TimeTraceOperation::kNumTraces: return "NumTraces"; case TimeTraceOperation::kBufferFull: diff --git a/src/platform/silabs/tracing/SilabsTracing.h b/src/platform/silabs/tracing/SilabsTracing.h index 80f110ce37..ea15c12340 100644 --- a/src/platform/silabs/tracing/SilabsTracing.h +++ b/src/platform/silabs/tracing/SilabsTracing.h @@ -61,6 +61,7 @@ enum class TimeTraceOperation : uint8_t kBootup, kSilabsInit, kMatterInit, + kAppInit, kBufferFull, kNumTraces, };