You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/02/13 02:22:10 UTC
[mynewt-mcumgr] 26/42: smp_svr - Add statistics.
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git
commit e86e83f27293ec7eaef751c8d5acc62f411248d3
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Jan 30 12:17:43 2018 -0800
smp_svr - Add statistics.
---
samples/smp_svr/zephyr/prj.conf | 5 +++++
samples/smp_svr/zephyr/src/main.c | 31 +++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/samples/smp_svr/zephyr/prj.conf b/samples/smp_svr/zephyr/prj.conf
index 88ad795..5179c2c 100644
--- a/samples/smp_svr/zephyr/prj.conf
+++ b/samples/smp_svr/zephyr/prj.conf
@@ -39,11 +39,16 @@ CONFIG_REBOOT_LOG=y
# Enable assertions. Required for crash logging.
CONFIG_ASSERT=y
+# Enable statistics and statistic names.
+CONFIG_STATS=y
+CONFIG_STATS_NAMES=y
+
# Enable all core commands.
CONFIG_MCUMGR_CMD_FS_MGMT=y
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_LOG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
+CONFIG_MCUMGR_CMD_STAT_MGMT=y
### nRF5 specific settings
diff --git a/samples/smp_svr/zephyr/src/main.c b/samples/smp_svr/zephyr/src/main.c
index 2906711..47e5de2 100644
--- a/samples/smp_svr/zephyr/src/main.c
+++ b/samples/smp_svr/zephyr/src/main.c
@@ -14,6 +14,7 @@
#include "logging/mdlog.h"
#include "logging/reboot_log.h"
#include "fcb.h"
+#include "stats.h"
#include "mgmt/smp_bt.h"
#include "mgmt/buf.h"
@@ -29,13 +30,13 @@
#ifdef CONFIG_MCUMGR_CMD_LOG_MGMT
#include "log_mgmt/log_mgmt.h"
#endif
+#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT
+#include "stat_mgmt/stat_mgmt.h"
+#endif
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
-struct fcb smp_svr_fcb;
-struct mdlog smp_svr_log;
-
/* smp_svr uses the first "peruser" log module. */
#define SMP_SVR_MDLOG_MODULE (MDLOG_MODULE_PERUSER + 0)
@@ -43,6 +44,21 @@ struct mdlog smp_svr_log;
#define SMP_SVR_MDLOG(lvl, ...) \
MDLOG_ ## lvl(&smp_svr_log, SMP_SVR_MDLOG_MODULE, __VA_ARGS__)
+/* Define an example stats group; tracks seconds of uptime. */
+STATS_SECT_START(smp_svr_stats)
+ STATS_SECT_ENTRY(ticks)
+STATS_SECT_END
+
+/* Assign a name to the `ticks` stat. */
+STATS_NAME_START(smp_svr_stats)
+ STATS_NAME(smp_svr_stats, ticks)
+STATS_NAME_END(smp_svr_stats)
+
+/* Define an instance of the stats group. */
+STATS_SECT_DECL(smp_svr_stats) smp_svr_stats;
+
+struct fcb smp_svr_fcb;
+struct mdlog smp_svr_log;
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
@@ -158,6 +174,9 @@ void main(void)
reboot_log_configure(&smp_svr_log);
#endif
+ rc = STATS_INIT_AND_REG(smp_svr_stats, STATS_SIZE_32, "smp_svr_stats");
+ assert(rc == 0);
+
/* Register the built-in mcumgr command handlers. */
#ifdef CONFIG_MCUMGR_CMD_FS_MGMT
fs_mgmt_register_group();
@@ -171,6 +190,9 @@ void main(void)
#ifdef CONFIG_MCUMGR_CMD_LOG_MGMT
log_mgmt_register_group();
#endif
+#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT
+ stat_mgmt_register_group();
+#endif
/* Enable Bluetooth. */
rc = bt_enable(bt_ready);
@@ -192,6 +214,7 @@ void main(void)
* main thread idle while the mcumgr server runs.
*/
while (1) {
- k_sleep(INT32_MAX);
+ k_sleep(1000);
+ STATS_INC(smp_svr_stats, ticks);
}
}
--
To stop receiving notification emails like this one, please contact
ccollins@apache.org.