summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-12-22 21:58:54 +0100
committerDamjan Marion <damarion@cisco.com>2021-12-22 22:03:27 +0100
commite6387b2b9fdaca33d50c1074dda5d41e1092e8ad (patch)
tree4e733499edfa09986f658d4c3667d24b7d5a91c5 /src
parentc824977ed38738985864c4524510f37a41453f7d (diff)
vppinfra: add format_u64_bitmap function
Sample output: 60 56 52 48 44 40 36 32 28 24 20 16 12 8 4 0 0x0020 .... .... .... .... .... .... .... .... .... .... .... .... ..11 .... ...1 1... 0x0000000000003018 0x0018 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 111. .1.1 0xffffffffffffffe5 0x0010 .... .... .... .... .... .... ..1. ...1 .1.1 1... 11.. 1... .... .1.. 1111 ..11 0x0000002158c804f3 0x0008 .... .... .... .... .... .... .... .... .... .... .... .... .... .... ..1. 11.. 0x000000000000002c 0x0000 .... .... .... .... .... .... .... .... .... .... .... .... .... .... .... ...1 0x0000000000000001 Type: improvement Change-Id: Ib99129866ad5a1d2d52be6855406e2829aa9ec3e Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/format.h3
-rw-r--r--src/vppinfra/std-formats.c31
2 files changed, 34 insertions, 0 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h
index b70384c0e41..d143ecdb6e9 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -305,6 +305,9 @@ u8 *format_c_identifier (u8 * s, va_list * va);
/* Format hexdump with both hex and printable chars - compatible with text2pcap */
u8 *format_hexdump (u8 * s, va_list * va);
+/* Format bitmap of array of u64 numbers */
+u8 *format_u64_bitmap (u8 *s, va_list *va);
+
/* Unix specific formats. */
#ifdef CLIB_UNIX
/* Setup input from Unix file. */
diff --git a/src/vppinfra/std-formats.c b/src/vppinfra/std-formats.c
index 1a150ead7bd..421cb3dda99 100644
--- a/src/vppinfra/std-formats.c
+++ b/src/vppinfra/std-formats.c
@@ -411,6 +411,37 @@ format_hexdump (u8 * s, va_list * args)
return s;
}
+__clib_export u8 *
+format_u64_bitmap (u8 *s, va_list *args)
+{
+ u64 *bitmap = va_arg (*args, u64 *);
+ int n_uword = va_arg (*args, int);
+ u32 indent = format_get_indent (s);
+
+ s = format (s, "%6s", "");
+
+ for (int i = 60; i >= 0; i -= 4)
+ s = format (s, "%5d", i);
+
+ vec_add1 (s, '\n');
+
+ for (int j = n_uword - 1; j >= 0; j--)
+ {
+ s = format (s, "%U0x%04x ", format_white_space, indent, j * 8);
+ for (int i = 63; i >= 0; i--)
+ {
+ vec_add1 (s, (1ULL << i) & bitmap[j] ? '1' : '.');
+ if (i % 4 == 0)
+ vec_add1 (s, ' ');
+ }
+ s = format (s, "0x%016lx", bitmap[j]);
+ if (j)
+ vec_add1 (s, '\n');
+ }
+
+ return s;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*