net: shell: Add allocs command
Move "allocs" command to a separate file. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
3f36f78654
commit
e850517a15
|
@ -6,6 +6,8 @@ zephyr_library_include_directories(. ${ZEPHYR_BASE}/subsys/net/lib)
|
|||
zephyr_library_include_directories(. ${ZEPHYR_BASE}/subsys/net/ip)
|
||||
zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)
|
||||
|
||||
zephyr_library_sources(allocs.c)
|
||||
|
||||
zephyr_library_include_directories(
|
||||
${ZEPHYR_BASE}/kernel/include
|
||||
${ARCH_DIR}/${ARCH}/include
|
||||
|
|
100
subsys/net/lib/shell/allocs.c
Normal file
100
subsys/net/lib/shell/allocs.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_shell);
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
|
||||
static void allocs_cb(struct net_pkt *pkt,
|
||||
struct net_buf *buf,
|
||||
const char *func_alloc,
|
||||
int line_alloc,
|
||||
const char *func_free,
|
||||
int line_free,
|
||||
bool in_use,
|
||||
void *user_data)
|
||||
{
|
||||
struct net_shell_user_data *data = user_data;
|
||||
const struct shell *sh = data->sh;
|
||||
const char *str;
|
||||
|
||||
if (in_use) {
|
||||
str = "used";
|
||||
} else {
|
||||
if (func_alloc) {
|
||||
str = "free";
|
||||
} else {
|
||||
str = "avail";
|
||||
}
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
goto buf;
|
||||
}
|
||||
|
||||
if (func_alloc) {
|
||||
if (in_use) {
|
||||
PR("%p/%ld\t%5s\t%5s\t%s():%d\n",
|
||||
pkt, atomic_get(&pkt->atomic_ref), str,
|
||||
net_pkt_slab2str(pkt->slab),
|
||||
func_alloc, line_alloc);
|
||||
} else {
|
||||
PR("%p\t%5s\t%5s\t%s():%d -> %s():%d\n",
|
||||
pkt, str, net_pkt_slab2str(pkt->slab),
|
||||
func_alloc, line_alloc, func_free,
|
||||
line_free);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
buf:
|
||||
if (func_alloc) {
|
||||
struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
|
||||
|
||||
if (in_use) {
|
||||
PR("%p/%d\t%5s\t%5s\t%s():%d\n",
|
||||
buf, buf->ref,
|
||||
str, net_pkt_pool2str(pool), func_alloc,
|
||||
line_alloc);
|
||||
} else {
|
||||
PR("%p\t%5s\t%5s\t%s():%d -> %s():%d\n",
|
||||
buf, str, net_pkt_pool2str(pool),
|
||||
func_alloc, line_alloc, func_free,
|
||||
line_free);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
|
||||
|
||||
static int cmd_net_allocs(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
|
||||
struct net_shell_user_data user_data;
|
||||
#endif
|
||||
|
||||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
|
||||
user_data.sh = sh;
|
||||
|
||||
PR("Network memory allocations\n\n");
|
||||
PR("memory\t\tStatus\tPool\tFunction alloc -> freed\n");
|
||||
net_pkt_allocs_foreach(allocs_cb, &user_data);
|
||||
#else
|
||||
PR_INFO("Set %s to enable %s support.\n",
|
||||
"CONFIG_NET_DEBUG_NET_PKT_ALLOC", "net_pkt allocation");
|
||||
#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_SUBCMD_ADD((net), allocs, NULL,
|
||||
"Print network memory allocations.",
|
||||
cmd_net_allocs, 1, 0);
|
|
@ -1627,93 +1627,6 @@ static void ipv6_frag_cb(struct net_ipv6_reassembly *reass,
|
|||
}
|
||||
#endif /* CONFIG_NET_IPV6_FRAGMENT */
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
|
||||
static void allocs_cb(struct net_pkt *pkt,
|
||||
struct net_buf *buf,
|
||||
const char *func_alloc,
|
||||
int line_alloc,
|
||||
const char *func_free,
|
||||
int line_free,
|
||||
bool in_use,
|
||||
void *user_data)
|
||||
{
|
||||
struct net_shell_user_data *data = user_data;
|
||||
const struct shell *sh = data->sh;
|
||||
const char *str;
|
||||
|
||||
if (in_use) {
|
||||
str = "used";
|
||||
} else {
|
||||
if (func_alloc) {
|
||||
str = "free";
|
||||
} else {
|
||||
str = "avail";
|
||||
}
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
goto buf;
|
||||
}
|
||||
|
||||
if (func_alloc) {
|
||||
if (in_use) {
|
||||
PR("%p/%ld\t%5s\t%5s\t%s():%d\n",
|
||||
pkt, atomic_get(&pkt->atomic_ref), str,
|
||||
net_pkt_slab2str(pkt->slab),
|
||||
func_alloc, line_alloc);
|
||||
} else {
|
||||
PR("%p\t%5s\t%5s\t%s():%d -> %s():%d\n",
|
||||
pkt, str, net_pkt_slab2str(pkt->slab),
|
||||
func_alloc, line_alloc, func_free,
|
||||
line_free);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
buf:
|
||||
if (func_alloc) {
|
||||
struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
|
||||
|
||||
if (in_use) {
|
||||
PR("%p/%d\t%5s\t%5s\t%s():%d\n",
|
||||
buf, buf->ref,
|
||||
str, net_pkt_pool2str(pool), func_alloc,
|
||||
line_alloc);
|
||||
} else {
|
||||
PR("%p\t%5s\t%5s\t%s():%d -> %s():%d\n",
|
||||
buf, str, net_pkt_pool2str(pool),
|
||||
func_alloc, line_alloc, func_free,
|
||||
line_free);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
|
||||
|
||||
/* Put the actual shell commands after this */
|
||||
|
||||
static int cmd_net_allocs(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
|
||||
struct net_shell_user_data user_data;
|
||||
#endif
|
||||
|
||||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
|
||||
user_data.sh = sh;
|
||||
|
||||
PR("Network memory allocations\n\n");
|
||||
PR("memory\t\tStatus\tPool\tFunction alloc -> freed\n");
|
||||
net_pkt_allocs_foreach(allocs_cb, &user_data);
|
||||
#else
|
||||
PR_INFO("Set %s to enable %s support.\n",
|
||||
"CONFIG_NET_DEBUG_NET_PKT_ALLOC", "net_pkt allocation");
|
||||
#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_ARP) && defined(CONFIG_NET_NATIVE)
|
||||
static void arp_cb(struct arp_entry *entry, void *user_data)
|
||||
{
|
||||
|
@ -6647,8 +6560,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_udp,
|
|||
);
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(net_commands,
|
||||
SHELL_CMD(allocs, NULL, "Print network memory allocations.",
|
||||
cmd_net_allocs),
|
||||
SHELL_CMD(arp, &net_cmd_arp, "Print information about IPv4 ARP cache.",
|
||||
cmd_net_arp),
|
||||
SHELL_CMD(capture, &net_cmd_capture,
|
||||
|
|
Loading…
Reference in a new issue