Datasheet

Adding Statistics
Mynewt includes an internal statistics system where numeric values can be declared and incremented over time, then
accessed as a debug and analysis tool.
For example, every time a specific sensor is accessed, you can increment the sensor_reads statistic value by one
(assigning whatever variable name you want), and when a specific bug or condition occurs you can check the value to
see whether or how many times the sensor was accessed before the specific condition occurs.
You can also use statistics to verify the number of bytes sent and received over a specific peripheral to make sure
sensitive interrupt driven code is working well without having to stop the entire system.
Configuring Your App for Statistics
To enable statistics in your application, the following dependency needs to be present in pkg.yml :
To save flash space internally, statistics are referenced by number by default. If you wish to preserve the full name of
the individual statistics for easier debugging, then the following flag also needs to be added to the syscfg.yml file:
Optionally, if you wish to access statistics from the shell interface, you can also enable the ' stat ' command with the
following flag in syscfg.yml :
Adding Stats to your main.c File:
Stats requires the following header be present:
This will enable the use of the STATS* macros to define the stats layout, following the example below:
Full documentation on statistics is available here:
https://mynewt.apache.org/latest/os/modules/stats/stats.html
pkg.deps:
- "@apache-mynewt-core/sys/stats"
syscfg.vals:
# Include names for statistics.
STATS_NAMES: 1
syscfg.vals:
STATS_CLI: 1
#include <stats/stats.h>
© Adafruit Industries https://learn.adafruit.com/adafruit-nrf52-pro-feather Page 62 of 87