Skip to content

Commit 0ae558e

Browse files
committed
net: lib: shell: Print vendor value as hex blob
Along with key-value pairs, print only the value as hex blob for easier parsing to a C struct. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent a1e9c23 commit 0ae558e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

subsys/net/lib/shell/stats.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,33 @@ static void print_eth_stats(struct net_if *iface, struct net_stats_eth *data,
110110

111111
#if defined(CONFIG_NET_STATISTICS_ETHERNET_VENDOR)
112112
if (data->vendor) {
113-
PR("Vendor specific statistics for Ethernet "
114-
"interface %p [%d]:\n",
115-
iface, net_if_get_by_iface(iface));
116113
size_t i = 0;
117114

115+
PR("Vendor specific statistics for Ethernet interface %p [%d]:\n",
116+
iface, net_if_get_by_iface(iface));
117+
118+
PR("Key-Value Pairs:\n");
118119
do {
119-
PR("%s : %u\n", data->vendor[i].key,
120-
data->vendor[i].value);
120+
PR("%s : %u\n", data->vendor[i].key, data->vendor[i].value);
121121
i++;
122122
} while (data->vendor[i].key);
123+
124+
/*
125+
* Print vendor stats as a contiguous hex blob, little-endian, no delimiters.
126+
* This format is suitable for direct typecasting to a C struct for offline parsing.
127+
* Each value is output as 4 bytes, least significant byte first.
128+
*/
129+
PR("Vendor stats hex blob: ");
130+
for (i = 0; data->vendor[i].key; i++) {
131+
uint32_t v = data->vendor[i].value;
132+
133+
PR("%02x%02x%02x%02x",
134+
(uint8_t)(v & 0xFF),
135+
(uint8_t)((v >> 8) & 0xFF),
136+
(uint8_t)((v >> 16) & 0xFF),
137+
(uint8_t)((v >> 24) & 0xFF));
138+
}
139+
PR("\n");
123140
}
124141
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
125142
}

0 commit comments

Comments
 (0)