[PATCH] blkparse_fmt: Check for repeated zeroes in pdu
authorJens Axboe <axboe@suse.de>
Fri, 7 Oct 2005 08:50:56 +0000 (10:50 +0200)
committerJens Axboe <axboe@suse.de>
Fri, 7 Oct 2005 08:50:56 +0000 (10:50 +0200)
We can stop dumping the pdu (typically the cdb) if the rest is just
zeroes, append a .. to show that is the case. Saves screen space.

blkparse_fmt.c

index c445d0d4fa7d973a37e2d03ccf9a006e8b04b2d4..8031a8e661bba91bdabec497a4ba24dace9fe594 100644 (file)
@@ -79,6 +79,16 @@ static inline void fill_rwbs(char *rwbs, struct blk_io_trace *t)
        rwbs[i] = '\0';
 }
 
+static int pdu_rest_is_zero(unsigned char *pdu, int len)
+{
+       int i = 0;
+
+       while (!pdu[i] && i < len)
+               i++;
+
+       return i == len;
+}
+
 static char *dump_pdu(unsigned char *pdu_buf, int pdu_len)
 {
        static char p[4096];
@@ -92,6 +102,16 @@ static char *dump_pdu(unsigned char *pdu_buf, int pdu_len)
                        len += sprintf(p + len, " ");
 
                len += sprintf(p + len, "%02x", pdu_buf[i]);
+
+               /*
+                * usually dump for cdb dumps where we can see lots of
+                * zeroes, stop when the rest is just zeroes and indicate
+                * so with a .. appended
+                */
+               if (!pdu_buf[i] && pdu_rest_is_zero(pdu_buf + i, pdu_len - i)) {
+                       sprintf(p + len, " ..");
+                       break;
+               }
        }
 
        return p;