iowatcher: Skip events beyond max_seconds
authorJan Kara <jack@suse.cz>
Thu, 4 Apr 2013 10:18:25 +0000 (06:18 -0400)
committerChris Mason <clm@fb.com>
Wed, 24 Sep 2014 19:02:08 +0000 (12:02 -0700)
Skip events beyond max_seconds.  This not only saves CPU time but also
prevents memory corruption because not all functions were checking that
given time is in the expected range. Also remove now unnecessary checks
in the called functions.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
iowatcher/blkparse.c
iowatcher/blkparse.h
iowatcher/main.c

index d27b54779a017e6d66c2003fe8d5a80c7458db15..c70b1bddfc8e2bc30105ce61a7fa5eac106554c6 100644 (file)
@@ -188,6 +188,11 @@ struct pid_map {
 #define DOUBLE_TO_NANO_ULL(d)   ((unsigned long long)((d) * 1000000000))
 #define CHECK_MAGIC(t)          (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
 
+u64 get_record_time(struct trace *trace)
+{
+       return trace->io->time;
+}
+
 void init_io_hash_table(void)
 {
        int i;
@@ -960,9 +965,6 @@ void add_tput(struct trace *trace, struct graph_line_data *writes_gld,
                gld = writes_gld;
 
        seconds = SECONDS(io->time);
-       if (seconds > gld->max_seconds)
-               return;
-
        gld->data[seconds].sum += io->bytes;
 
        gld->data[seconds].count = 1;
@@ -1060,10 +1062,6 @@ void add_pending_io(struct trace *trace, struct graph_line_data *gld)
        if (action != __BLK_TA_ISSUE)
                return;
 
-       seconds = SECONDS(io->time);
-       if (seconds > gld->max_seconds)
-               return;
-
        pio = hash_dispatched_io(trace->io);
        if (!pio)
                return;
@@ -1075,6 +1073,7 @@ void add_pending_io(struct trace *trace, struct graph_line_data *gld)
 
        ios_in_flight++;
 
+       seconds = SECONDS(io->time);
        gld->data[seconds].sum += ios_in_flight;
        gld->data[seconds].count++;
 
@@ -1138,9 +1137,6 @@ void add_iop(struct trace *trace, struct graph_line_data *gld)
                return;
 
        seconds = SECONDS(io->time);
-       if (seconds > gld->max_seconds)
-               return;
-
        gld->data[seconds].sum += 1;
        gld->data[seconds].count = 1;
        if (gld->data[seconds].sum > gld->max)
index 84bda4a7cadb029d6860f8a9a96c170d716d492c..1c93a2565e54edc64b109ac92db707199c61c63f 100644 (file)
@@ -133,5 +133,6 @@ void add_tput(struct trace *trace, struct graph_line_data *writes_gld,
              struct graph_line_data *reads_gld);
 void add_pending_io(struct trace *trace, struct graph_line_data *gld);
 int next_record(struct trace *trace);
+u64 get_record_time(struct trace *trace);
 void first_record(struct trace *trace);
 #endif
index a4193241281ca07ca01244712917b50b2f1efd3a..694304cd028d44433ec6c4704e7abc5bd1c70d97 100644 (file)
@@ -426,17 +426,16 @@ static void read_trace_events(void)
                trace = tf->trace;
 
                first_record(trace);
-               while (1) {
+               do {
+                       if (SECONDS(get_record_time(trace)) > tf->max_seconds)
+                               continue;
                        check_record(trace);
                        add_tput(trace, tf->tput_writes_gld, tf->tput_reads_gld);
                        add_iop(trace, tf->iop_gld);
                        add_io(trace, tf);
                        add_pending_io(trace, tf->queue_depth_gld);
                        add_completed_io(trace, tf->latency_gld);
-                       ret = next_record(trace);
-                       if (ret)
-                               break;
-               }
+               } while (!(ret = next_record(trace)));
        }
        list_for_each_entry(tf, &all_traces, list) {
                trace = tf->trace;