Skip to content

Commit

Permalink
Bluetooth: Make H(ost)Top
Browse files Browse the repository at this point in the history
Sorry we don't have color support yet..

On the non-joke side, this option will print the number of dropped
extended advertising reports every second.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
  • Loading branch information
jori-nordic and alwa-nordic committed Sep 27, 2024
1 parent df0031d commit 529cfd3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions subsys/bluetooth/host/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,12 @@ config BT_TESTING
This option enables custom Bluetooth testing interface.
Shall only be used for testing purposes.

config BT_HTOP
bool "Bluetooth Statistics"
help
Enable printing of Bluetooth performance statistics.
Sort of like THREAD_ANALYZER.

config BT_CONN_DISABLE_SECURITY
bool "Disable security"
depends on BT_TESTING
Expand Down
35 changes: 35 additions & 0 deletions subsys/bluetooth/host/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,35 @@ static void create_ext_adv_info(struct bt_hci_evt_le_ext_advertising_info const
scan_info->adv_props = get_adv_props_extended(sys_le16_to_cpu(evt->evt_type));
}

#if defined(CONFIG_BT_HTOP)
static atomic_t dropped_adv_reports;
static struct k_thread htop_thread;
static K_THREAD_PINNED_STACK_DEFINE(htop_thread_stack, CONFIG_MAIN_STACK_SIZE);

static void htop_thread_entry(void *p1, void *p2, void *p3)
{
for (;;) {
int reports = atomic_clear(&dropped_adv_reports);

if (reports) {
LOG_INF("Dropped advertising reports: %d", reports);
}

k_sleep(K_SECONDS(2));
}
}

static int sys_init_spawn_htop(void)
{
k_thread_create(&htop_thread, htop_thread_stack, K_THREAD_STACK_SIZEOF(htop_thread_stack),
htop_thread_entry, NULL, NULL, NULL, K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);
k_thread_name_set(&htop_thread, "htop");
return 0;
}

SYS_INIT(sys_init_spawn_htop, POST_KERNEL, 64);
#endif

static void start_discarding(struct fragmented_advertiser *a)
{
if (a->report) {
Expand All @@ -874,6 +903,9 @@ static void start_discarding(struct fragmented_advertiser *a)
}

a->state = FRAG_ADV_DISCARDING;
#if defined(CONFIG_BT_HTOP)
atomic_inc(&dropped_adv_reports);
#endif
}

static void crash_if_corrupted(size_t report_length, size_t buffer_length)
Expand Down Expand Up @@ -1015,6 +1047,9 @@ static void process_unfragmented_report(struct bt_hci_evt_le_ext_advertising_inf
struct net_buf *report)
{
if (report == NULL) {
#if defined(CONFIG_BT_HTOP)
atomic_inc(&dropped_adv_reports);
#endif
return;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/bsim/bluetooth/host/scan/slow/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ CONFIG_ASSERT=y
CONFIG_THREAD_NAME=y
CONFIG_LOG_THREAD_ID_PREFIX=y
CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y

CONFIG_BT_HTOP=y

0 comments on commit 529cfd3

Please sign in to comment.