zephyr/subsys/bluetooth/mesh/statistic.c
Aleksandr Khromykh 7199425792 Bluetooth: Mesh: add statistic module
PR adds the statistic module to estimate frame handling.
The module helps to understand the ratio of
the received\relayed\dropped\transmited frames.
That shows the efficiency of the current configuration\implementation.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-07-07 09:20:33 +02:00

65 lines
1.3 KiB
C

/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/bluetooth/mesh.h>
#include "adv.h"
#include "net.h"
#include "statistic.h"
static struct bt_mesh_statistic stat;
void bt_mesh_stat_get(struct bt_mesh_statistic *st)
{
memcpy(st, &stat, sizeof(struct bt_mesh_statistic));
}
void bt_mesh_stat_reset(void)
{
memset(&stat, 0, sizeof(struct bt_mesh_statistic));
}
void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv)
{
if (adv->tag & BT_MESH_LOCAL_ADV) {
stat.tx_local_planned++;
} else if (adv->tag & BT_MESH_RELAY_ADV) {
stat.tx_adv_relay_planned++;
} else if (adv->tag & BT_MESH_FRIEND_ADV) {
stat.tx_friend_planned++;
}
}
void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv)
{
if (adv->tag & BT_MESH_LOCAL_ADV) {
stat.tx_local_succeeded++;
} else if (adv->tag & BT_MESH_RELAY_ADV) {
stat.tx_adv_relay_succeeded++;
} else if (adv->tag & BT_MESH_FRIEND_ADV) {
stat.tx_friend_succeeded++;
}
}
void bt_mesh_stat_rx(enum bt_mesh_net_if net_if)
{
switch (net_if) {
case BT_MESH_NET_IF_ADV:
stat.rx_adv++;
break;
case BT_MESH_NET_IF_LOCAL:
stat.rx_loopback++;
break;
case BT_MESH_NET_IF_PROXY:
case BT_MESH_NET_IF_PROXY_CFG:
stat.rx_proxy++;
break;
default:
stat.rx_uknown++;
break;
}
}