Skip to content

Commit

Permalink
Wrapped tracing begin and end with maccros to reduce the amount if #i…
Browse files Browse the repository at this point in the history
…f in the code
  • Loading branch information
lpbeliveau-silabs committed Dec 3, 2024
1 parent 7d7c700 commit 436ed87
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 148 deletions.
17 changes: 4 additions & 13 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@
#endif

// Tracing
#include <matter/tracing/build_config.h>
#if MATTER_TRACING_ENABLED
#ifdef ENABLE_CHIP_SHELL
#include <platform/silabs/tracing/SilabsTracingMacros.h>
#if MATTER_TRACING_ENABLED && defined(ENABLE_CHIP_SHELL)
#include <TracingShellCommands.h>
#endif // ENABLE_CHIP_SHELL
#include <platform/silabs/tracing/SilabsTracing.h>
#endif // MATTER_TRACING_ENABLED

// sl-only
Expand Down Expand Up @@ -127,11 +124,7 @@ 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 {

/**********************************************************
Expand Down Expand Up @@ -375,10 +368,8 @@ CHIP_ERROR BaseApplication::Init()

void BaseApplication::InitCompleteCallback(CHIP_ERROR err)
{
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kAppInit);
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kBootup);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END(TimeTraceOperation::kAppInit);
SILABS_TRACE_END(TimeTraceOperation::kBootup);
}

void BaseApplication::FunctionTimerEventHandler(void * timerCbArg)
Expand Down
19 changes: 6 additions & 13 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
#include "MemMonitoring.h"
#endif

#if ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) || defined(EXP_BOARD) )
#if ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
#include <platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h>
#if !defined(EXP_BOARD)
#include <platform/silabs/SiWx917/SiWxPlatformInterface.h>
#endif //!defined(EXP_BOARD)
#endif //! defined(EXP_BOARD)
#endif // ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) || defined(EXP_BOARD) )

#include <crypto/CHIPCryptoPAL.h>
Expand Down Expand Up @@ -97,10 +97,9 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
#include "sl_power_manager.h"
#endif

#include <matter/tracing/build_config.h>
#include <platform/silabs/tracing/SilabsTracingMacros.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

Expand All @@ -113,11 +112,7 @@ using namespace ::chip::Inet;
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>
Expand Down Expand Up @@ -193,10 +188,8 @@ 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
SILABS_TRACE_END(TimeTraceOperation::kMatterInit);
SILABS_TRACE_BEGIN(TimeTraceOperation::kAppInit);

gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
Expand Down Expand Up @@ -381,7 +374,7 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
#endif // SL_WFX_USE_SECURE_LINK
#endif // WF200_WIFI

#if ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) || defined(EXP_BOARD) )
#if ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
VerifyOrReturnError(sl_matter_wifi_platform_init() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
#endif // ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) || defined(EXP_BOARD) )

Expand Down
21 changes: 5 additions & 16 deletions examples/platform/silabs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,17 @@
#include "sl_system_init.h"
#include "sl_system_kernel.h"
#include <MatterConfig.h>
#include <platform/silabs/tracing/SilabsTracingMacros.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);
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kSilabsInit);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_BEGIN(chip::Tracing::Silabs::TimeTraceOperation::kBootup);
SILABS_TRACE_BEGIN(chip::Tracing::Silabs::TimeTraceOperation::kSilabsInit);
sl_system_init();
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kSilabsInit);
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kMatterInit);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END(chip::Tracing::Silabs::TimeTraceOperation::kSilabsInit);
SILABS_TRACE_BEGIN(chip::Tracing::Silabs::TimeTraceOperation::kMatterInit);
// Initialize the application. For example, create periodic timer(s) or
// task(s) if the kernel is present.
SilabsMatterConfig::AppInit();
Expand Down
7 changes: 5 additions & 2 deletions src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ static_library("efr32") {
"${chip_root}/src/platform/logging:headers",
]
deps = [
"${chip_root}/src/tracing",
"${chip_root}/src/tracing/silabs:silabs_tracing",
"${silabs_platform_dir}/provision:provision-headers",
]

public_configs = []

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

# Add platform crypto implementation
Expand Down
67 changes: 17 additions & 50 deletions src/platform/silabs/efr32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
#include <platform/silabs/wifi/wf200/platform/spi_multiplex.h>
#endif // SL_WIFI

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

extern "C" {
#include "btl_interface.h"
#include "sl_core.h"
}

using TimeTraceOperation = chip::Tracing::Silabs::TimeTraceOperation;

#ifdef _SILICON_LABS_32B_SERIES_2
// Series 2 bootloader_ api calls must be called from a critical section context for thread safeness
#define WRAP_BL_DFU_CALL(code) \
Expand All @@ -56,11 +55,6 @@ static chip::OTAImageProcessorImpl gImageProcessor;

namespace chip {

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

// Define static memebers
uint8_t OTAImageProcessorImpl::mSlotId = 0;
uint32_t OTAImageProcessorImpl::mWriteOffset = 0;
Expand Down Expand Up @@ -168,19 +162,15 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)

ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started");

#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kImageUpload);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_BEGIN(TimeTraceOperation::kImageUpload);

#ifdef _SILICON_LABS_32B_SERIES_2
// TODO sl-temp: bootloader_init is called previously sl_platform_init(). Recalling it for series3 causes a crash.
WRAP_BL_DFU_CALL(err = bootloader_init())
if (err != SL_BOOTLOADER_OK)
{
ChipLogProgress(SoftwareUpdate, "bootloader_init Failed error: %ld", err);
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageUpload, CHIP_ERROR_INTERNAL);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageUpload, CHIP_ERROR_INTERNAL);
}
#endif

Expand Down Expand Up @@ -222,9 +212,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
if (err != SL_STATUS_OK)
{
ChipLogError(SoftwareUpdate, "sl_wfx_host_pre_bootloader_spi_transfer() error: %ld", err);
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageUpload, CHIP_ERROR_INTERNAL);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageUpload, CHIP_ERROR_INTERNAL);
return;
}
#endif // SL_BTLCTRL_MUX
Expand All @@ -235,29 +223,23 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
if (err != SL_STATUS_OK)
{
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageUpload, CHIP_ERROR_INTERNAL);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageUpload, CHIP_ERROR_INTERNAL);
return;
}
#endif // SL_BTLCTRL_MUX
if (err)
{
ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage() error: %ld", err);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageUpload, CHIP_ERROR_WRITE_FAILED);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageUpload, CHIP_ERROR_WRITE_FAILED);
return;
}
}

imageProcessor->ReleaseBlock();

ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageUpload);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END(TimeTraceOperation::kImageUpload);
}

// TODO: SE access is not thread safe. It assert if other tasks accesses it during bootloader_verifyImage or
Expand All @@ -281,9 +263,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
uint32_t err = SL_BOOTLOADER_OK;

ChipLogProgress(SoftwareUpdate, "HandleApply: verifying image");
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceBegin(TimeTraceOperation::kImageVerification);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_BEGIN(TimeTraceOperation::kImageVerification);

// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
Expand All @@ -292,9 +272,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
if (err != SL_STATUS_OK)
{
ChipLogError(SoftwareUpdate, "sl_wfx_host_pre_bootloader_spi_transfer() error: %ld", err);
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageVerification, CHIP_ERROR_INTERNAL);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageVerification, CHIP_ERROR_INTERNAL);
return;
}
#endif // SL_BTLCTRL_MUX
Expand All @@ -317,9 +295,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
}
#endif // SL_BTLCTRL_MUX
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageVerification, err);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageVerification, err);
return;
}
ChipLogProgress(SoftwareUpdate, "Image verified, Set image to bootload");
Expand All @@ -338,9 +314,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
}
#endif // SL_BTLCTRL_MUX
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageVerification, err);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageVerification, err);
return;
}

Expand All @@ -349,23 +323,16 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
if (err != SL_STATUS_OK)
{
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageVerification, err);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END_ERROR(TimeTraceOperation::kImageVerification, err);
return;
}
#endif // SL_BTLCTRL_MUX

#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kImageVerification);
SilabsTracer::Instance().TimeTraceInstant(TimeTraceOperation::kAppApplyTime);
#endif // MATTER_TRACING_ENABLED
SILABS_TRACE_END(TimeTraceOperation::kImageVerification);
SILABS_TRACE_INSTANT(TimeTraceOperation::kAppApplyTime);
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
SILABS_TRACE_FLUSH_ALL();
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
osDelay(100); // sl-temp: delay for uart print before reboot
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
Expand Down
18 changes: 2 additions & 16 deletions src/platform/silabs/tracing/BackendImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@
#include <tracing/metric_event.h>
#include <tracing/registry.h>

#define _MATTER_TRACE_DISABLE(...) \
do \
{ \
} while (false)

// This gets forwarded to the multiplexed instance
#define MATTER_TRACE_BEGIN(label, group) ::chip::Tracing::Internal::Begin(label, group)
#define MATTER_TRACE_END(label, group) ::chip::Tracing::Internal::End(label, group)
#define MATTER_TRACE_INSTANT(label, group) ::chip::Tracing::Internal::Instant(label, group)
#define MATTER_TRACE_COUNTER(label) ::chip::Tracing::Internal::Counter(label)

// We are not using this in our current implementation, so we are disabling it.
#define MATTER_TRACE_SCOPE(...) _MATTER_TRACE_DISABLE(__VA_ARGS__)

namespace chip {
namespace Tracing {
namespace Silabs {
Expand All @@ -46,8 +32,8 @@ class BackendImpl : public ::chip::Tracing::Backend
public:
BackendImpl() = default;
// TraceBegin, TraceEnd and TraceInstant are redundant with LogMetricEvent in the usecases that we are trying to track,
// so we are not implementing these at the moment to avoid duplication of the same information in the trace. We might implement them
// in the future if we want to add new traces that are not related to our metrics measurements
// so we are not implementing these at the moment to avoid duplication of the same information in the trace. We might implement
// them in the future if we want to add new traces that are not related to our metrics measurements
void TraceBegin(const char * label, const char * group) override;
void TraceEnd(const char * label, const char * group) override;
void TraceInstant(const char * label, const char * group) override;
Expand Down
Loading

0 comments on commit 436ed87

Please sign in to comment.