[PATCH] blktrace: need to free ts->buf for networked transfer
[blktrace.git] / blkparse_fmt.c
index b8f90de18a667784355d646dd50858574ef647c5..ceeaaba85fdde8f775528917790f76999297b16b 100644 (file)
@@ -79,6 +79,13 @@ static inline void fill_rwbs(char *rwbs, struct blk_io_trace *t)
        rwbs[i] = '\0';
 }
 
+static inline int pdu_rest_is_zero(unsigned char *pdu, int len)
+{
+       static char zero[4096];
+
+       return !memcmp(pdu, zero, len);
+}
+
 static char *dump_pdu(unsigned char *pdu_buf, int pdu_len)
 {
        static char p[4096];
@@ -92,6 +99,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;
@@ -109,9 +126,10 @@ static unsigned int get_pdu_int(struct blk_io_trace *t)
 static void get_pdu_remap(struct blk_io_trace *t, struct blk_io_trace_remap *r)
 {
        struct blk_io_trace_remap *__r = pdu_start(t);
+       __u64 sector = __r->sector;
 
        r->device = be32_to_cpu(__r->device);
-       r->sector = be64_to_cpu(__r->sector);
+       r->sector = be64_to_cpu(sector);
 }
 
 static void print_field(char *act, struct per_cpu_info *pci,
@@ -136,9 +154,12 @@ static void print_field(char *act, struct per_cpu_info *pci,
        case 'c':
                fprintf(ofp, strcat(format, "d"), pci->cpu);
                break;
-       case 'C':
-               fprintf(ofp, strcat(format, "s"), t->comm);
+       case 'C': {
+               char *name = find_process_name(t->pid);
+
+               fprintf(ofp, strcat(format, "s"), name);
                break;
+       }
        case 'd': {
                char rwbs[4];
 
@@ -159,7 +180,7 @@ static void print_field(char *act, struct per_cpu_info *pci,
                fprintf(ofp, strcat(format, "d"), MINOR(t->device));
                break;
        case 'n':
-               fprintf(ofp, strcat(format, "u"), t->bytes >> 9);
+               fprintf(ofp, strcat(format, "u"), t_sec(t));
                break;
        case 'N':
                fprintf(ofp, strcat(format, "u"), t->bytes);
@@ -235,6 +256,7 @@ static void process_default(char *act, struct per_cpu_info *pci,
                            int pdu_len, unsigned char *pdu_buf)
 {
        char rwbs[4];
+       char *name;
 
        fill_rwbs(rwbs, t);
 
@@ -246,7 +268,10 @@ static void process_default(char *act, struct per_cpu_info *pci,
                (int) SECONDS(t->time), (unsigned long) NANO_SECONDS(t->time),
                t->pid, act, rwbs);
 
+       name = find_process_name(t->pid);
+
        switch (act[0]) {
+       case 'R':       /* Requeue */
        case 'C':       /* Complete */
                if (t->action & BLK_TC_ACT(BLK_TC_PC)) {
                        char *p = dump_pdu(pdu_buf, pdu_len);
@@ -257,11 +282,11 @@ static void process_default(char *act, struct per_cpu_info *pci,
                        if (elapsed != -1ULL) {
                                fprintf(ofp, "%llu + %u (%8llu) [%d]\n",
                                        (unsigned long long) t->sector,
-                                       t->bytes >> 9, elapsed, t->error);
+                                       t_sec(t), elapsed, t->error);
                        } else {
                                fprintf(ofp, "%llu + %u [%d]\n",
                                        (unsigned long long) t->sector,
-                                       t->bytes >> 9, t->error);
+                                       t_sec(t), t->error);
                        }
                }
                break;
@@ -276,16 +301,16 @@ static void process_default(char *act, struct per_cpu_info *pci,
                        p = dump_pdu(pdu_buf, pdu_len);
                        if (p)
                                fprintf(ofp, "(%s) ", p);
-                       fprintf(ofp, "[%s]\n", t->comm);
+                       fprintf(ofp, "[%s]\n", name);
                } else {
                        if (elapsed != -1ULL) {
                                fprintf(ofp, "%llu + %u (%8llu) [%s]\n",
                                        (unsigned long long) t->sector,
-                                       t->bytes >> 9, elapsed, t->comm);
+                                       t_sec(t), elapsed, name);
                        } else {
                                fprintf(ofp, "%llu + %u [%s]\n",
                                        (unsigned long long) t->sector,
-                                       t->bytes >> 9, t->comm);
+                                       t_sec(t), name);
                        }
                }
                break;
@@ -296,16 +321,16 @@ static void process_default(char *act, struct per_cpu_info *pci,
        case 'G':       /* Get request */
        case 'S':       /* Sleep request */
                fprintf(ofp, "%llu + %u [%s]\n", (unsigned long long) t->sector,
-                       t->bytes >> 9, t->comm);
+                       t_sec(t), name);
                break;
 
        case 'P':       /* Plug */
-               fprintf(ofp, "[%s]\n", t->comm);
+               fprintf(ofp, "[%s]\n", name);
                break;
 
        case 'U':       /* Unplug IO */
        case 'T':       /* Unplug timer */
-               fprintf(ofp, "[%s] %u\n", t->comm, get_pdu_int(t));
+               fprintf(ofp, "[%s] %u\n", name, get_pdu_int(t));
                break;
 
        case 'A': {     /* remap */
@@ -313,7 +338,7 @@ static void process_default(char *act, struct per_cpu_info *pci,
 
                get_pdu_remap(t, &r);
                fprintf(ofp, "%llu + %u <- (%d,%d) %llu\n",
-                       (unsigned long long) r.sector, t->bytes >> 10,
+                       (unsigned long long) r.sector, t_sec(t),
                        MAJOR(r.device), MINOR(r.device),
                        (unsigned long long) t->sector);
                break;
@@ -321,7 +346,7 @@ static void process_default(char *act, struct per_cpu_info *pci,
                
        case 'X':       /* Split */
                fprintf(ofp, "%llu / %u [%s]\n", (unsigned long long) t->sector,
-                       get_pdu_int(t), t->comm);
+                       get_pdu_int(t), name);
                break;
 
        default: