From d6d8bb86576372ee14e4f17addee724bb121fa19 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 28 Jun 2024 09:08:53 +0200 Subject: [PATCH] util/hexdump: Squeeze repeated patterns instead of zero-ed chunks Our u_hexdump() squeezes 16-byte chunks filled of zeros, where the unix hexdump squeezes repeated 16-byte chunks. Turns out panfrost/panvk dumps can be pretty big when when VM dump is requested (PANVK_DEBUG/PAN_MESA_DEBUG=dump) and memory regions are filled with repeated non-zero patterns (like a Z16_UNORM buffer cleared to 1.0, AKA 0xffff). Avoiding the repetition of such non-zero patterns in dumps significantly reduces the size of the dumps. It also clears any confusion for people used to the original hexdump semantics where a star means the previous line is repeated. Signed-off-by: Boris Brezillon Acked-by: Alyssa Rosenzweig Part-of: --- src/util/u_hexdump.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/util/u_hexdump.h b/src/util/u_hexdump.h index 9c79fc23c0f..0c07b24dea1 100644 --- a/src/util/u_hexdump.h +++ b/src/util/u_hexdump.h @@ -13,29 +13,24 @@ static inline void u_hexdump(FILE *fp, const uint8_t *hex, size_t cnt, bool with_strings) { for (unsigned i = 0; i < cnt; ++i) { - if ((i & 0xF) == 0) - fprintf(fp, "%06X ", i); + if ((i & 0xF) == 0 && i >= 0x10) { + unsigned j; - uint8_t v = hex[i]; - - if (v == 0 && (i & 0xF) == 0) { - /* Check if we're starting an aligned run of zeroes */ - unsigned zero_count = 0; - - for (unsigned j = i; j < cnt; ++j) { - if (hex[j] == 0) - zero_count++; - else + for (j = i; j + 0x10 < cnt; j += 0x10) { + if (memcmp(&hex[j], &hex[j - 0x10], 0x10)) break; } - if (zero_count >= 32) { + if (j > i) { fprintf(fp, "*\n"); - i += (zero_count & ~0xF) - 1; + i = j - 1; continue; } } + if ((i & 0xF) == 0) + fprintf(fp, "%06X ", i); + fprintf(fp, "%02X ", hex[i]); if ((i & 0xF) == 0xF && with_strings) { fprintf(fp, " | ");