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

[SL-ONLY] Silabs tracing integration #122

Merged
merged 12 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
2 changes: 1 addition & 1 deletion examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class BaseApplication
/** @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
* @param err CHIP_NO_ERROR on success, corresponding error code on Init failure, note that Init failure leeds to app error so
* @param err CHIP_NO_ERROR on success, corresponding error code on Init failure, note that Init failure leads to an app error so
* this is purely to have a trace logged with the error code
*/
void InitCompleteCallback(CHIP_ERROR err);
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
1 change: 0 additions & 1 deletion examples/platform/silabs/MatterShell.cpp
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#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"
Expand Down
4 changes: 0 additions & 4 deletions examples/platform/silabs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ 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
Expand Down
20 changes: 15 additions & 5 deletions examples/platform/silabs/shell/tracing/TracingShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ CHIP_ERROR TracingHelpHandler(int argc, char ** argv)
return CHIP_NO_ERROR;
}

CHIP_ERROR TracingListTimeOperations(int argc, char ** argv)
{
for (size_t i = 0; i < static_cast<size_t>(TimeTraceOperation::kNumTraces); ++i)
{
streamer_printf(streamer_get(), "Operation: %s\r\n", TimeTraceOperationToString(static_cast<TimeTraceOperation>(i)));
}
return CHIP_NO_ERROR;
}

CHIP_ERROR TracingCommandHandler(int argc, char ** argv)
{
if (argc == 0)
Expand All @@ -161,7 +170,7 @@ CHIP_ERROR WatermarksCommandHandler(int argc, char ** argv)
}
else
{
TimeTraceOperation operation = StringToTimeTraceOperation(argv[1]);
TimeTraceOperation operation = StringToTimeTraceOperation(argv[0]);
error = Tracing::Silabs::SilabsTracer::Instance().OutputWaterMark(operation);
}
return error;
Expand All @@ -176,7 +185,7 @@ CHIP_ERROR FlushCommandHandler(int argc, char ** argv)
}
else
{
TimeTraceOperation operation = StringToTimeTraceOperation(argv[1]);
TimeTraceOperation operation = StringToTimeTraceOperation(argv[0]);
error = Tracing::Silabs::SilabsTracer::Instance().TraceBufferFlushByOperation(operation);
}
return error;
Expand All @@ -189,9 +198,10 @@ namespace TracingCommands {
void RegisterCommands()
{
static const Shell::Command sTracingSubCommands[] = {
{ &TracingHelpHandler, "help", "Usage: Output this message" },
{ &WatermarksCommandHandler, "watermarks", " Usage: watermarks <TimeTraceOperation>" },
{ &FlushCommandHandler, "flush", "Usage: flush <TimeTraceOperation>" },
{ &TracingHelpHandler, "help", "Output the help menu" },
{ &TracingListTimeOperations, "list", "List all available TimeTraceOperations" },
{ &WatermarksCommandHandler, "watermarks", "Display runtime watermarks. Usage: watermarks <TimeTraceOperation>" },
{ &FlushCommandHandler, "flush", "Display buffered traces. Usage: flush <TimeTraceOperation>" },
};
static const Shell::Command cmds_silabs_tracing = { &TracingCommandHandler, "tracing",
"Dispatch Silicon Labs Tracing command" };
Expand Down
10 changes: 0 additions & 10 deletions src/platform/silabs/tracing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

config("tracing") {
include_dirs = [ "include" ]
}

static_library("SilabsTracing") {
sources = [
"BackendImpl.cpp",
Expand All @@ -38,9 +34,3 @@ static_library("SilabsTracing") {

public_deps = [ "${chip_root}/src/tracing:tracing" ]
}

source_set("silabs_tracing") {
public = [ "include/matter/tracing/macros_impl.h" ]
public_configs = [ ":tracing" ]
deps = [ ":SilabsTracing" ]
}
2 changes: 1 addition & 1 deletion src/platform/silabs/tracing/BackendImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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 them at current to avoid duplication of the same information in the trace. We might implement it
// 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;
Expand Down
65 changes: 65 additions & 0 deletions src/platform/silabs/tracing/Diagram.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
````mermaid
classDiagram
class SilabsTracer {
+static SilabsTracer& Instance()
+CHIP_ERROR Init()
+CHIP_ERROR StartWatermarksStorage(PersistentStorageDelegate* storage)
+void TimeTraceBegin(TimeTraceOperation aOperation)
+void TimeTraceEnd(TimeTraceOperation aOperation, CHIP_ERROR error = CHIP_NO_ERROR)
+void TimeTraceInstant(TimeTraceOperation aOperation, CHIP_ERROR error = CHIP_NO_ERROR)
+CHIP_ERROR OutputTimeTracker(const TimeTracker& tracker)
+CHIP_ERROR OutputWaterMark(TimeTraceOperation aOperation)
+CHIP_ERROR OutputAllWaterMarks()
+CHIP_ERROR TraceBufferFlushAll()
+CHIP_ERROR TraceBufferFlushByOperation(TimeTraceOperation aOperation)
+TimeTracker GetTimeTracker(TimeTraceOperation aOperation)
+Watermark GetWatermark(TimeTraceOperation aOperation)
+CHIP_ERROR SaveWatermarks()
+CHIP_ERROR LoadWatermarks()
+CHIP_ERROR GetTraceCount(size_t& count) const
+CHIP_ERROR GetTraceByIndex(size_t index, const char*& trace) const
-void TraceBufferClear()
-CHIP_ERROR OutputTrace(const TimeTracker& tracker)
-static SilabsTracer sInstance
-TimeTrackerList mTimeTrackerList
-TimeTracker mLatestTimeTrackers[kNumTraces]
-Watermark mWatermarks[kNumTraces]
-PersistentStorageDelegate* mStorage
-size_t mBufferedTrackerCount
}

class TimeTracker {
+System::Clock::Milliseconds32 mStartTime
+System::Clock::Milliseconds32 mEndTime
+TimeTraceOperation mOperation
+OperationType mType
+CHIP_ERROR mError
}

class Watermark {
+System::Clock::Milliseconds32 mMovingAverage
+System::Clock::Milliseconds32 mMaxTimeMs
+System::Clock::Milliseconds32 mMinTimeMs
+uint32_t mTotalCount
+uint32_t mSuccessfullCount
+uint32_t mCountAboveAvg
}

class TimeTrackerList {
+chip::SingleLinkedListNode* head
+void Insert(const TimeTracker& tracker)
+void Remove(size_t index)
}

class SingleLinkedListNode {
+TimeTracker mValue
+SingleLinkedListNode* mpNext
}

SilabsTracer --> TimeTracker
SilabsTracer --> Watermark
SilabsTracer --> TimeTrackerList
TimeTrackerList --> SingleLinkedListNode
SingleLinkedListNode --> TimeTracker
```mermaid
````
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions src/platform/silabs/tracing/SequenceDiagram.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
````mermaid
sequenceDiagram
participant Client
participant SilabsTracer
participant TimeTracker
participant Watermark

Client->>SilabsTracer: TimeTraceInstant(aOperation, error)
SilabsTracer->>TimeTracker: Create tracker
SilabsTracer->>SilabsTracer: OutputTrace(tracker)
SilabsTracer->>SilabsTracer: OutputTimeTracker(tracker)
SilabsTracer->>Watermark: Update Watermark
SilabsTracer->>Client: Return result

```mermaid
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved
````
5 changes: 3 additions & 2 deletions src/platform/silabs/tracing/SilabsTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ CHIP_ERROR SilabsTracer::OutputTrace(const TimeTracker & tracker)
CHIP_ERROR SilabsTracer::OutputWaterMark(TimeTraceOperation aOperation)
{
VerifyOrReturnError(to_underlying(aOperation) < kNumTraces, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(DeviceLayer, "Invalid watermark"));
ChipLogError(DeviceLayer, "Invalid TimeTraceOperation"));
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved
size_t index = to_underlying(aOperation);
auto & watermark = mWatermarks[index];

Expand Down Expand Up @@ -329,7 +329,8 @@ CHIP_ERROR SilabsTracer::TraceBufferFlushAll()

CHIP_ERROR SilabsTracer::TraceBufferFlushByOperation(TimeTraceOperation aOperation)
{

VerifyOrReturnError(to_underlying(aOperation) < kNumTraces, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(DeviceLayer, "Invalid TimeTraceOperation"));
auto * current = mTimeTrackerList.head;
auto * prev = static_cast<chip::SingleLinkedListNode<TimeTracker> *>(nullptr);
while (current != nullptr)
Expand Down
2 changes: 2 additions & 0 deletions src/platform/silabs/tracing/SilabsTracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ class SilabsTracer
CHIP_ERROR OutputTrace(const TimeTracker & tracker);
};

const char * TimeTraceOperationToString(TimeTraceOperation operation);

} // namespace Silabs
} // namespace Tracing
} // namespace chip
23 changes: 0 additions & 23 deletions src/platform/silabs/tracing/include/matter/tracing/macros_impl.h

This file was deleted.

Loading