btreplay/btrecord man pages
[blktrace.git] / blkparse_fmt.c
index f74832d8c7832f2409dd062f6d979f272e68febd..0ca5c60912c164432a6b8d375765ca30c8ee1217 100644 (file)
@@ -7,10 +7,11 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <time.h>
 
 #include "blktrace.h"
 
-#define VALID_SPECS    "ABCDFGMPQRSTUWX"
+#define VALID_SPECS    "ABCDFGIMPQRSTUWX"
 
 #define HEADER         "%D %2c %8s %5T.%9t %5p %2a %3d "
 
@@ -48,14 +49,7 @@ int add_format_spec(char *option)
                return 1;
        }
 
-       /*
-        * Set both merges (front and back)
-        */
-       if (spec == 'M') {
-               override_format['B'] = strdup(option);
-               override_format['M'] = strdup(option);
-       } else
-               override_format[spec] = strdup(option);
+       override_format[spec] = strdup(option);
 
        return 0;
 }
@@ -71,8 +65,10 @@ static inline void fill_rwbs(char *rwbs, struct blk_io_trace *t)
 
        if (w)
                rwbs[i++] = 'W';
-       else
+       else if (t->bytes)
                rwbs[i++] = 'R';
+       else
+               rwbs[i++] = 'N';
        if (a)
                rwbs[i++] = 'A';
        if (b)
@@ -85,6 +81,31 @@ static inline void fill_rwbs(char *rwbs, struct blk_io_trace *t)
        rwbs[i] = '\0';
 }
 
+static const char *
+print_time(unsigned long long timestamp)
+{
+       static char     timebuf[128];
+       struct tm       *tm;
+       time_t          sec;
+       unsigned long   nsec;
+
+       sec  = abs_start_time.tv_sec + SECONDS(timestamp);
+       nsec = abs_start_time.tv_nsec + NANO_SECONDS(timestamp);
+       if (nsec >= 1000000000) {
+               nsec -= 1000000000;
+               sec += 1;
+       }
+
+       tm = localtime(&sec);
+       snprintf(timebuf, sizeof(timebuf),
+                       "%02u:%02u:%02u.%06lu",
+                       tm->tm_hour,
+                       tm->tm_min,
+                       tm->tm_sec,
+                       nsec / 1000);
+       return timebuf;
+}
+
 static inline int pdu_rest_is_zero(unsigned char *pdu, int len)
 {
        static char zero[4096];
@@ -221,10 +242,12 @@ static void print_field(char *act, struct per_cpu_info *pci,
                }
                fprintf(ofp, strcat(format, "llu"), elapsed / 1000);
                break;
-       case 'U': {
+       case 'U':
                fprintf(ofp, strcat(format, "u"), get_pdu_int(t));
                break;
-       }
+       case 'z':
+               fprintf(ofp, strcat(format, "s"), print_time(t->time));
+               break;
        default:
                fprintf(ofp,strcat(format, "c"), field);
                break;
@@ -293,13 +316,23 @@ static void process_default(char *act, struct per_cpu_info *pci,
                        fprintf(ofp, "[%d]\n", t->error);
                } else {
                        if (elapsed != -1ULL) {
-                               fprintf(ofp, "%llu + %u (%8llu) [%d]\n",
-                                       (unsigned long long) t->sector,
-                                       t_sec(t), elapsed, t->error);
+                               if (t_sec(t))
+                                       fprintf(ofp, "%llu + %u (%8llu) [%d]\n",
+                                               (unsigned long long) t->sector,
+                                               t_sec(t), elapsed, t->error);
+                               else
+                                       fprintf(ofp, "%llu (%8llu) [%d]\n",
+                                               (unsigned long long) t->sector,
+                                               elapsed, t->error);
                        } else {
-                               fprintf(ofp, "%llu + %u [%d]\n",
-                                       (unsigned long long) t->sector,
-                                       t_sec(t), t->error);
+                               if (t_sec(t))
+                                       fprintf(ofp, "%llu + %u [%d]\n",
+                                               (unsigned long long) t->sector,
+                                               t_sec(t), t->error);
+                               else
+                                       fprintf(ofp, "%llu [%d]\n",
+                                               (unsigned long long) t->sector,
+                                               t->error);
                        }
                }
                break;
@@ -307,7 +340,7 @@ static void process_default(char *act, struct per_cpu_info *pci,
        case 'D':       /* Issue */
        case 'I':       /* Insert */
        case 'Q':       /* Queue */
-       case 'W':       /* Bounce */
+       case 'B':       /* Bounce */
                if (t->action & BLK_TC_ACT(BLK_TC_PC)) {
                        char *p;
                        fprintf(ofp, "%u ", t->bytes);
@@ -317,24 +350,33 @@ static void process_default(char *act, struct per_cpu_info *pci,
                        fprintf(ofp, "[%s]\n", name);
                } else {
                        if (elapsed != -1ULL) {
-                               fprintf(ofp, "%llu + %u (%8llu) [%s]\n",
-                                       (unsigned long long) t->sector,
-                                       t_sec(t), elapsed, name);
+                               if (t_sec(t))
+                                       fprintf(ofp, "%llu + %u (%8llu) [%s]\n",
+                                               (unsigned long long) t->sector,
+                                               t_sec(t), elapsed, name);
+                               else
+                                       fprintf(ofp, "(%8llu) [%s]\n", elapsed,
+                                               name);
                        } else {
-                               fprintf(ofp, "%llu + %u [%s]\n",
-                                       (unsigned long long) t->sector,
-                                       t_sec(t), name);
+                               if (t_sec(t))
+                                       fprintf(ofp, "%llu + %u [%s]\n",
+                                               (unsigned long long) t->sector,
+                                               t_sec(t), name);
+                               else
+                                       fprintf(ofp, "[%s]\n", name);
                        }
                }
                break;
 
-       case 'B':       /* Back merge */
+       case 'M':       /* Back merge */
        case 'F':       /* Front merge */
-       case 'M':       /* Front or back merge */
        case 'G':       /* Get request */
        case 'S':       /* Sleep request */
-               fprintf(ofp, "%llu + %u [%s]\n", (unsigned long long) t->sector,
-                       t_sec(t), name);
+               if (t_sec(t))
+                       fprintf(ofp, "%llu + %u [%s]\n",
+                               (unsigned long long) t->sector, t_sec(t), name);
+               else
+                       fprintf(ofp, "[%s]\n", name);
                break;
 
        case 'P':       /* Plug */