Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zephyr/samples/coredumps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ endif()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(coredumps)

add_compile_options(-fno-omit-frame-pointer -g)

add_subdirectory(../common ${CMAKE_CURRENT_BINARY_DIR}/common)

target_sources(app PRIVATE
Expand Down
2 changes: 2 additions & 0 deletions zephyr/samples/coredumps/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CONFIG_DEBUG_INFO=y

CONFIG_SPOTFLOW=y
CONFIG_SPOTFLOW_COREDUMPS=y

Expand Down
3 changes: 2 additions & 1 deletion zephyr/samples/coredumps/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ int main(void)
int i = 0;
while (true) {
LOG_INF("Hello from Zephyr to Spotflow: %d", i++);
k_sleep(K_SECONDS(2));
k_sleep(K_SECONDS(1));

}
}

Expand Down
17 changes: 17 additions & 0 deletions zephyr/samples/metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/credentials.conf")
list(APPEND EXTRA_CONF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/credentials.conf")
endif()


find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(metrics)

add_subdirectory(../common ${CMAKE_CURRENT_BINARY_DIR}/common)

target_sources(app PRIVATE
src/main.c
)
11 changes: 11 additions & 0 deletions zephyr/samples/metrics/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
config NET_WIFI_SSID
string "SSID device should connect to"
help
SSID of the wifi network that the device should connect to.

config NET_WIFI_PASSWORD
string "Wifi Password device should connect to"
help
Wifi password for the network that the device should connect to.

source "Kconfig.zephyr"
8 changes: 8 additions & 0 deletions zephyr/samples/metrics/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config WIFI_NRF70
default y if \
BOARD_NRF7002DK_NRF5340_CPUAPP || \
BOARD_NRF7002DK_NRF5340_CPUAPP_NS || \
BOARD_NRF7002DK_NRF5340_CPUAPP_NRF7001 || \
BOARD_NRF7002DK_NRF5340_CPUAPP_NRF7001_NS

source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
5 changes: 5 additions & 0 deletions zephyr/samples/metrics/boards/esp32c3_devkitc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WiFi Config
CONFIG_WIFI_ESP32=y
CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4=y
CONFIG_ESP32_WIFI_STA_RECONNECT=y
CONFIG_NET_L2_ETHERNET=y
3 changes: 3 additions & 0 deletions zephyr/samples/metrics/boards/esp32c3_devkitc.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&wifi {
status = "okay";
};
8 changes: 8 additions & 0 deletions zephyr/samples/metrics/boards/esp32c6_devkitc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# WiFi Config
CONFIG_WIFI_ESP32=y
CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4=y
CONFIG_ESP32_WIFI_STA_RECONNECT=y
CONFIG_NET_L2_ETHERNET=y

# not supported on esp32c6 devkitc
CONFIG_DEBUG_COREDUMP_THREADS_METADATA=n
4 changes: 4 additions & 0 deletions zephyr/samples/metrics/boards/esp32c6_devkitc.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&wifi {
status = "okay";
};

7 changes: 7 additions & 0 deletions zephyr/samples/metrics/boards/frdm_rw612.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_WIFI_NXP=y
CONFIG_NXP_RW610=y
CONFIG_ETH_DRIVER=n
#fix buffer size for RW612 on Zephyr 4.1.0
CONFIG_NET_BUF_DATA_SIZE=1744

CONFIG_NXP_WIFI_SOFTAP_SUPPORT=n
49 changes: 49 additions & 0 deletions zephyr/samples/metrics/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Networking stats
CONFIG_NET_STATISTICS=y



CONFIG_SYS_HEAP_RUNTIME_STATS=y

CONFIG_THREAD_STACK_INFO=y
CONFIG_INIT_STACKS=y
# Optional: per-thread runtime stats
CONFIG_THREAD_RUNTIME_STATS=y

CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y
#---------------------------------

CONFIG_SPOTFLOW=y
CONFIG_SPOTFLOW_MODULE_DEFAULT_LOG_LEVEL=4

# configure if the function names should be included in the logs
CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y

#logging
CONFIG_PRINTK=y
CONFIG_LOG=y

# net
CONFIG_NETWORKING=y
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_INFO=y
CONFIG_NET_CONFIG_AUTO_INIT=n
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y

# WIFI
CONFIG_WIFI=y
CONFIG_WIFI_NM=y
CONFIG_NET_L2_WIFI_MGMT=y




105 changes: 105 additions & 0 deletions zephyr/samples/metrics/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <zephyr/bindesc.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_stats.h>
#include <zephyr/sys/mem_stats.h>
#include <zephyr/sys/sys_heap.h>
#include <zephyr/kernel/thread_stack.h>

#include "../../common/wifi.h"


LOG_MODULE_REGISTER(SPOTF_MAIN, LOG_LEVEL_DBG);

/* Uncomment this function to provide your own device ID in runtime */
/*const char* spotflow_override_device_id()
{
return "my_nrf7002dk_test";
}*/

static void capture_network_stats()
{
uint32_t ipv4_recv;
uint32_t ipv4_sent;
uint32_t ipv4_drop;
struct net_if* iface = net_if_get_default();
if (iface) {
const struct net_stats_ip *ip = &iface->stats.ipv4;
ipv4_recv = ip->recv;
ipv4_sent = ip->sent;
ipv4_drop = ip->drop;
LOG_DBG("Network: ipv4_recv=%u ipv4_sent=%u ipv4_drop=%u", ipv4_recv, ipv4_sent,
ipv4_drop);
}
}

// extern struct sys_heap z_heap_runtime_stats;
extern struct sys_heap _system_heap; // declared by Zephyr if k_malloc() is used

static void capture_heap_stats()
{
struct sys_memory_stats stats;

if (sys_heap_runtime_stats_get(&_system_heap, &stats) == 0) {
LOG_DBG("Heap free: %zu bytes", stats.free_bytes);
LOG_DBG("Heap allocated: %zu bytes", stats.allocated_bytes);
}

}

static void thread_info_cb(const struct k_thread *thread, void *user_data)
{
ARG_UNUSED(user_data);

// struct k_thread_stack_info info;

size_t unused, size = thread->stack_info.size;
if (k_thread_stack_space_get(thread, &unused) == 0) {
size_t used = size - unused;
const char *tname;

tname = k_thread_name_get((k_tid_t)thread);

if (tname == NULL) {
static char buf[32];
snprintk(buf, sizeof(buf), "%p", (void *)thread);
tname = buf;
}
// LOG_INF("%p (%s):\tunused %zu\tusage %zu / %zu (%u %%)",
// thread, tname, unused, size - unused, size,
// pcnt);

// unsigned int pcnt = ((size - unused) * 100U) / size;
LOG_DBG("Thread: %s, Stack size: %zu, Used: %zu", tname, size, used);
// LOG_DBG(" ", used);
// LOG_DBG(" Unused: %zu\n", unused);
}
}

static void capture_threads_stacks()
{
k_thread_foreach(thread_info_cb, NULL);

}

int main(void)
{
LOG_INF("Starting Spotflow logging example");

// Wait for the initialization of Wi-Fi device
k_sleep(K_SECONDS(1));

init_wifi();
connect_to_wifi();

while (1) {
capture_network_stats();
capture_threads_stacks();
capture_heap_stats();
// metrics_capture(&s);
// metrics_log(&s);
k_sleep(K_SECONDS(5));
}
return 0;
}
1 change: 1 addition & 0 deletions zephyr/src/logging/spotflow_log_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int poll_and_process_enqueued_logs()
k_free(msg_ptr);
if (messages_sent_counter % 100 == 0) {
LOG_INF("Sent %" PRIu32 " messages", messages_sent_counter);
msg_ptr->len = 10;
}
if (messages_sent_counter == UINT32_MAX) {
LOG_INF("Sent %" PRIu32 " messages. Reset.", messages_sent_counter);
Expand Down