Skip to content

Conversation

@malbert-silabs
Copy link
Contributor

@malbert-silabs malbert-silabs commented Oct 30, 2025

Summary

This PR add two new features.

  1. An optional addition to the existing tracing infrastructure to see quick statistics about the energy states
Screenshot 2025-11-18 at 9 55 32 AM
  1. An optional addition to record and output all energy state transition traces for analysis with other tools.
Screenshot 2025-11-18 at 9 54 22 AM

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:

  • PR title is
    descriptive
  • Apply the
    “When in Rome…”
    rule (coding style)
  • PR size is short
  • Try to avoid "squashing" and "force-update" in commit history
  • CI time didn't increase

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.

  • Tracing (Silabs):
    • Energy Statistics: Track time, longest duration, and transition counts per energy mode; output via SilabsTracer::OutputPowerManagerStatistics() and shell tracing energy.
    • Energy Transition Traces: New SilabsPowerTracing singleton to record EM transitions over time and print a trace table; uses sleeptimer; one-shot timer for deferred output.
    • Config/Args: New platform/silabs/tracing/args.gni flags: silabs_tracing_energy_stats, silabs_tracing_energy_traces, silabs_tracing_energy_traces_seconds, silabs_tracing_energy_traces_max; corresponding defines emitted in SilabsTracingConfig.h.
    • Build Integration: Added SilabsPowerTracing target and deps; wired into efr32/BUILD.gn and tests group; enabled when silabs_tracing_energy_traces is set.
    • Runtime Init: Initialize SilabsPowerTracing in MatterConfig.cpp when energy traces are enabled.
  • Shell:
    • Added tracing energy command to display energy mode stats.
  • FreeRTOS Task Stats:
    • Removed totalTaskCount from SystemTaskStats and related log output; retained active/terminated counts.
  • Tests:
    • Added unit tests for power tracing with CMSIS/Power Manager stubs; included in silabs_platform_tests.

Written by Cursor Bugbot for commit 227026f. This will update automatically on new commits. Configure here.

@malbert-silabs malbert-silabs changed the title Tracing: Energy state stats [SL-ONLY] Tracing: Energy state stats Oct 30, 2025
@silabs-matter-ci-bot silabs-matter-ci-bot bot added the sl-only This TAG indicates that this commit is a silabs-specific commit that cannot be upstreamed to CSA. label Oct 30, 2025
@malbert-silabs malbert-silabs marked this pull request as ready for review November 18, 2025 15:02
@malbert-silabs malbert-silabs requested a review from a team as a code owner November 18, 2025 15:02
Copilot AI review requested due to automatic review settings November 18, 2025 15:02
Copy link
Contributor

Copilot AI left a 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

malbert-silabs and others added 3 commits November 18, 2025 10:13
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

@cursor cursor bot left a 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

{
if (xTask == NULL)
return;
TaskHandle_t handle = (TaskHandle_t) xTask;
TaskStats * stats = findTaskStats(handle);
if (stats == NULL)
{
createTaskStats(handle);
}

Fix in Cursor Fix in Web


Copy link
Contributor

@lpbeliveau-silabs lpbeliveau-silabs left a 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).

@jmartinez-silabs jmartinez-silabs merged commit 1dad243 into main Nov 20, 2025
91 of 93 checks passed
@jmartinez-silabs jmartinez-silabs deleted the feature/em-tracing branch November 20, 2025 20:05
malbert-silabs added a commit that referenced this pull request Nov 20, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sl-only This TAG indicates that this commit is a silabs-specific commit that cannot be upstreamed to CSA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants