1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include "bpf_iter.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 
7 char _license[] SEC("license") = "GPL";
8 
9 SEC("iter/bpf_map")
10 int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
11 {
12 	struct seq_file *seq = ctx->meta->seq;
13 	__u64 seq_num = ctx->meta->seq_num;
14 	struct bpf_map *map = ctx->map;
15 
16 	if (map == (void *)0) {
17 		BPF_SEQ_PRINTF(seq, "      %%%%%% END %%%%%%\n");
18 		return 0;
19 	}
20 
21 	if (seq_num == 0)
22 		BPF_SEQ_PRINTF(seq, "      id   refcnt  usercnt  locked_vm\n");
23 
24 	BPF_SEQ_PRINTF(seq, "%8u %8ld %8ld %10lu\n", map->id, map->refcnt.counter,
25 		       map->usercnt.counter,
26 		       0LLU);
27 	return 0;
28 }
29