Added in running stats for btt
[blktrace.git] / btt / trace.c
index 39faf76701416c2001d22ec6c3a73749a08598c9..48f4f99f754524cda107a1c63d72dd5c587edd86 100644 (file)
@@ -24,11 +24,13 @@ static void __add_trace(struct io *iop)
 {
        time_t now = time(NULL);
 
+       last_t_seen = BIT_TIME(iop->t.time);
+
        n_traces++;
        iostat_check_time(iop->t.time);
 
        if (verbose && ((now - last_vtrace) > 0)) {
-               printf("%10lu t\r", n_traces);
+               printf("%10lu t (%6.2lf%%)\r", n_traces, pct_done());
                if ((n_traces % 1000000) == 0) printf("\n");
                fflush(stdout);
                last_vtrace = now;
@@ -47,37 +49,54 @@ static void __add_trace(struct io *iop)
        case __BLK_TA_PLUG:             trace_plug(iop); break;
        case __BLK_TA_UNPLUG_IO:        trace_unplug_io(iop); break;
        case __BLK_TA_UNPLUG_TIMER:     trace_unplug_timer(iop); break;
+       case __BLK_TA_SLEEPRQ:          trace_sleeprq(iop); break;
        default:
                io_release(iop);
                return;
        }
 }
 
+static void trace_message(struct io *iop)
+{
+       char scratch[15];
+       char msg[iop->t.pdu_len + 1];
+
+       if (!io_setup(iop, IOP_M))
+               return;
+
+       memcpy(msg, iop->pdu, iop->t.pdu_len);
+       msg[iop->t.pdu_len] = '\0';
+
+       fprintf(msgs_ofp, "%s %5d.%09lu %s\n",
+               make_dev_hdr(scratch, 15, iop->dip, 1),
+               (int)SECONDS(iop->t.time),
+               (unsigned long)NANO_SECONDS(iop->t.time), msg);
+}
+
 void add_trace(struct io *iop)
 {
        if (iop->t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) {
                if (iop->t.action == BLK_TN_PROCESS) {
                        if (iop->t.pid == 0)
-                               add_process(0, "kernel");
+                               process_alloc(0, "kernel");
                        else {
                                char *slash = strchr(iop->pdu, '/');
                                if (slash)
                                        *slash = '\0';
 
-                               add_process(iop->t.pid, iop->pdu);
+                               process_alloc(iop->t.pid, iop->pdu);
                        }
-               }
+               } else if (iop->t.action == BLK_TN_MESSAGE)
+                       trace_message(iop);
                io_release(iop);
-       }
-       else if (iop->t.action & BLK_TC_ACT(BLK_TC_PC))
+       } else if (iop->t.action & BLK_TC_ACT(BLK_TC_PC)) {
                io_release(iop);
-       else {
+       else {
                if (time_bounded) {
                        if (BIT_TIME(iop->t.time) < t_astart) {
                                io_release(iop);
                                return;
-                       }
-                       else if (BIT_TIME(iop->t.time) > t_aend) {
+                       } else if (BIT_TIME(iop->t.time) > t_aend) {
                                io_release(iop);
                                done = 1;
                                return;