-
Notifications
You must be signed in to change notification settings - Fork 30
[SL-ONLY] Tracing: Energy state stats #699
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
Conversation
69401cf to
8c8063a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds optional energy state monitoring features to the tracing infrastructure for Silicon Labs platforms. The implementation provides both statistical summaries of time spent in different energy modes (EM0, EM1, EM2) and detailed transition traces for external analysis.
Key Changes
- Added statistics tracking for energy state transitions with accumulated time, longest duration, and transition counts per state
- Added optional trace recording system that captures timestamps and energy modes for later analysis
- Implemented CLI command "tracing energy" to display energy mode statistics
- Added comprehensive unit tests with mock implementations for PowerManager and CMSIS-OS2 APIs
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/platform/silabs/tracing/SilabsPowerTracing.h | New header defining power tracing class with trace storage and callbacks |
| src/platform/silabs/tracing/SilabsPowerTracing.cpp | Implementation of power tracing with buffer management and timer-based output |
| src/platform/silabs/tracing/SilabsTracing.h | Added energy statistics tracking fields and callbacks to existing tracer |
| src/platform/silabs/tracing/SilabsTracing.cpp | Integrated power manager callbacks for real-time energy state monitoring |
| src/platform/silabs/tracing/args.gni | Build configuration for enabling energy stats and traces with configurable limits |
| src/platform/silabs/tracing/BUILD.gn | Added new static libraries for power tracing and test stubs |
| src/platform/tests/TestSilabsPowerTracing.cpp | Unit tests covering basic functionality and buffer overflow scenarios |
| src/platform/tests/BUILD.gn | Added power tracing test to build configuration |
| src/platform/silabs/tracing/mocks/* | Mock implementations of sl_power_manager and cmsis_os2 for unit testing |
| examples/platform/silabs/shell/tracing/TracingShellCommands.cpp | Added "energy" command to display statistics |
| examples/platform/silabs/MatterConfig.cpp | Initialization of power tracing system when enabled |
| examples/platform/silabs/FreeRTOSRuntimeStats.{h,c} | Removed unused totalTaskCount field from SystemTaskStats |
| src/platform/silabs/efr32/BUILD.gn | Added dependency on power tracing library when enabled |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: New Task Stats Remain Uninitialized
In vTaskCreated(), the return value from createTaskStats(handle) is discarded. The line should assign the result back to stats variable: stats = createTaskStats(handle); instead of just createTaskStats(handle);. This causes stats to remain NULL, preventing the newly created task statistics from being initialized with the current time value. Compare with vTaskMovedToReadyState() and vTaskSwitchedOut() which correctly assign the return value.
examples/platform/silabs/FreeRTOSRuntimeStats.c#L109-L118
matter_sdk/examples/platform/silabs/FreeRTOSRuntimeStats.c
Lines 109 to 118 in c756118
| { | |
| if (xTask == NULL) | |
| return; | |
| TaskHandle_t handle = (TaskHandle_t) xTask; | |
| TaskStats * stats = findTaskStats(handle); | |
| if (stats == NULL) | |
| { | |
| createTaskStats(handle); | |
| } |
lpbeliveau-silabs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved on resolution of comments, if an app surviving the power tracing failure is a real scenario, I would like to have a least a test that verifies every call to an un-initialized object is handled safely (note that it seems to be the case currently with the cleanup and checks on the array allocation).
* Initial implementation * Polish * Remove total tasks * add debug for transitions and em reqs * power stats "lite" * power tracing with GN * Optimize imports * update unit tests * Add stubs * Restyled by whitespace * Restyled by clang-format * Restyled by gn * remove debug include * update printing * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update headers * avoid size_t for printing * rework init functino * Restyled by whitespace * Restyled by clang-format * add casting for unit tests * Restyled by clang-format * Rename defines * Review comments * Review comments again * Review comments * Use macro * Remove unchanged things * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
This PR add two new features.
WIP Confluence page: https://confluence.silabs.com/spaces/MATTER/pages/745094873/Energy+Mode+Tracing+and+Statistics
Related issues
Closes: https://jira.silabs.com/browse/MATTER-5331
-->
Testing
Added unit tests for the energy tracing feature. Uses stubs for PowerManager and CMSIS.
Tested feature on LIT-ICD app and Lighting app on series 2 and 3.
Tested on UART and RTT for the transition traces.
Readability checklist
The checklist below will help the reviewer finish PR review in time and keep the
code readable:
descriptive
“When in Rome…”
rule (coding style)
See: Pull Request Guidelines
Note
Adds optional energy mode statistics and transition tracing (with CLI and build flags), integrates power tracing init, and removes totalTaskCount from FreeRTOS task stats.
SilabsTracer::OutputPowerManagerStatistics()and shelltracing energy.SilabsPowerTracingsingleton to record EM transitions over time and print a trace table; uses sleeptimer; one-shot timer for deferred output.platform/silabs/tracing/args.gniflags:silabs_tracing_energy_stats,silabs_tracing_energy_traces,silabs_tracing_energy_traces_seconds,silabs_tracing_energy_traces_max; corresponding defines emitted inSilabsTracingConfig.h.SilabsPowerTracingtarget and deps; wired intoefr32/BUILD.gnand tests group; enabled whensilabs_tracing_energy_tracesis set.SilabsPowerTracinginMatterConfig.cppwhen energy traces are enabled.tracing energycommand to display energy mode stats.totalTaskCountfromSystemTaskStatsand related log output; retained active/terminated counts.silabs_platform_tests.Written by Cursor Bugbot for commit 227026f. This will update automatically on new commits. Configure here.