Skip to content

Conversation

@malbert-silabs
Copy link
Contributor

@malbert-silabs malbert-silabs commented Nov 20, 2025

Cherry Pick #699

This is a cherry pick of #699 for release 2.8. The rest of the description body is from the original PR

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 on Silabs, wired via GN args, exposed via tracing energy CLI, initialized behind flags, and covered by unit tests; also drops totalTaskCount from FreeRTOS stats.

  • Silabs Tracing:
    • Energy Mode Stats: Track and report time/percentage/longest/transition-count per energy mode in SilabsTracing (OutputPowerManagerStatistics), enabled by SL_TRACING_ENERGY_STATS and accessible via tracing energy.
    • Energy Transition Traces: New SilabsPowerTracing component to record EM transitions over time and log them after a timer; initialized in MatterConfig.cpp when SL_TRACING_ENERGY_TRACES==1.
    • Build/Config: New GN args in src/platform/silabs/tracing/args.gni; config header defines (SL_TRACING_ENERGY_STATS, SL_TRACING_ENERGY_TRACES, periods/max); new SilabsPowerTracing target and deps; EFR32 BUILD.gn wires in tracing libs and tests.
    • Shell: Adds tracing energy command to print energy mode statistics.
    • Timing: Introduces SL_GET_SLEEPTIMER_TIME for EM2-safe timestamps.
  • FreeRTOS Task Stats:
    • Removes totalTaskCount from SystemTaskStats and associated log output.
  • Tests:
    • Adds unit tests for energy tracing with CMSIS/Power Manager stubs and integrates into silabs_platform_tests.

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

* 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>
@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 Nov 20, 2025
@malbert-silabs malbert-silabs marked this pull request as ready for review November 20, 2025 20:20
@malbert-silabs malbert-silabs requested a review from a team as a code owner November 20, 2025 20:20
Copilot AI review requested due to automatic review settings November 20, 2025 20:20
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 energy state tracing capabilities to the Silicon Labs platform, enabling developers to monitor device energy mode transitions and statistics. The implementation includes two optional features: real-time energy state statistics accessible via the "tracing energy" CLI command, and detailed transition traces for external analysis.

  • New SilabsPowerTracing class for recording energy mode transitions with timestamp tracking
  • Statistics collection for time spent in each energy mode (EM0-EM2) with percentage calculations
  • Unit tests with stub implementations for PowerManager and CMSIS OS2 APIs

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/platform/silabs/tracing/tests/mocks/sl_power_manager_stub.h Stub header defining PowerManager types and functions for unit tests
src/platform/silabs/tracing/tests/mocks/sl_power_manager_stub.cpp No-op stub implementations of PowerManager functions
src/platform/silabs/tracing/tests/mocks/cmsis_os2_stub.h Stub header defining CMSIS-OS2 timer types and functions for unit tests
src/platform/silabs/tracing/tests/mocks/cmsis_os2_stub.cpp Minimal stub implementations returning success/dummy values
src/platform/silabs/tracing/tests/TestSilabsPowerTracing.cpp Unit tests covering basic functionality, buffer overflow handling, and initialization failures
src/platform/silabs/tracing/tests/BUILD.gn Build configuration for tracing unit tests
src/platform/silabs/tracing/args.gni Build arguments for enabling energy stats and traces features
src/platform/silabs/tracing/SilabsTracingMacros.h Macro for obtaining sleeptimer-based timestamps
src/platform/silabs/tracing/SilabsTracing.h Extended tracer with PowerManager statistics tracking members and methods
src/platform/silabs/tracing/SilabsTracing.cpp Implemented PowerManager transition callbacks and statistics output logic
src/platform/silabs/tracing/SilabsPowerTracing.h Header defining the power tracing singleton class interface
src/platform/silabs/tracing/SilabsPowerTracing.cpp Implementation of power tracing with trace buffer and timer management
src/platform/silabs/tracing/BUILD.gn Build configuration adding power tracing library
src/platform/silabs/tests/BUILD.gn Added tracing tests to platform test group
src/platform/silabs/efr32/BUILD.gn Conditional dependency on power tracing library
examples/platform/silabs/shell/tracing/TracingShellCommands.cpp Added "energy" CLI command handler
examples/platform/silabs/MatterConfig.cpp Initialize power tracing singleton during Matter setup
examples/platform/silabs/FreeRTOSRuntimeStats.h Removed unused totalTaskCount field from SystemTaskStats
examples/platform/silabs/FreeRTOSRuntimeStats.c Removed calculation of unused totalTaskCount field
Comments suppressed due to low confidence (2)

src/platform/silabs/tracing/SilabsTracing.cpp:836

  • The removal of totalTaskCount from the log output appears unrelated to energy tracing functionality. This change modifies task statistics logging behavior and should either be documented in the PR description or moved to a separate commit, as it's not part of the energy state tracing feature being added.
    ChipLogProgress(DeviceLayer, "Active tasks: %lu | Terminated tasks: %lu", systemStats.activeTaskCount,
                    systemStats.terminatedTaskCount);

examples/platform/silabs/FreeRTOSRuntimeStats.h:1

  • The removal of totalTaskCount from SystemTaskStats is unrelated to energy tracing and could break existing code that depends on this field. This change should be in a separate PR or clearly documented as a related cleanup with justification for why it's being removed.
/***************************************************************************

@malbert-silabs malbert-silabs merged commit bde2093 into release_2.8-1.5 Nov 21, 2025
90 checks passed
@malbert-silabs malbert-silabs deleted the cherry-pick/em-tracing branch November 21, 2025 13:04
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.

4 participants