Skip to content

Commit e552682

Browse files
kuroa-meqmonnet
authored andcommitted
bpftool: Dump map id instead of value for map_of_maps types
When using `bpftool map dump` with map_of_maps, it is usually more convenient to show the inner map id instead of raw value. We are changing the plain print behavior to show inner_map_id instead of hex value, this would help with quick look up of inner map with `bpftool map dump id <inner_map_id>`. To avoid disrupting scripted behavior, we will add a new `inner_map_id` field to json output instead of replacing value. plain print: ``` $ bpftool map dump id 138 Without Patch: key: fc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 27 16 06 00 value: 8b 00 00 00 Found 1 element With Patch: key: fc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 27 16 06 00 inner_map_id: 139 Found 1 element ``` json print: ``` $ bpftool -p map dump id 567 Without Patch: [{ "key": ["0xc0","0x00","0x02","0x05","0x27","0x16","0x06","0x00" ], "value": ["0x38","0x02","0x00","0x00" ] } ] With Patch: [{ "key": ["0xc0","0x00","0x02","0x05","0x27","0x16","0x06","0x00" ], "value": ["0x38","0x02","0x00","0x00" ], "inner_map_id": 568 } ] ``` Signed-off-by: Xueming Feng <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent d89768b commit e552682

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/map.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key,
139139
print_hex_data_json(key, info->key_size);
140140
jsonw_name(json_wtr, "value");
141141
print_hex_data_json(value, info->value_size);
142+
if (map_is_map_of_maps(info->type))
143+
jsonw_uint_field(json_wtr, "inner_map_id",
144+
*(unsigned int *)value);
142145
if (btf) {
143146
struct btf_dumper d = {
144147
.btf = btf,
@@ -259,8 +262,13 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key,
259262
}
260263

261264
if (info->value_size) {
262-
printf("value:%c", break_names ? '\n' : ' ');
263-
fprint_hex(stdout, value, info->value_size, " ");
265+
if (map_is_map_of_maps(info->type)) {
266+
printf("inner_map_id:%c", break_names ? '\n' : ' ');
267+
printf("%u ", *(unsigned int *)value);
268+
} else {
269+
printf("value:%c", break_names ? '\n' : ' ');
270+
fprint_hex(stdout, value, info->value_size, " ");
271+
}
264272
}
265273

266274
printf("\n");

0 commit comments

Comments
 (0)