From: Alan D. Brunelle <[EMAIL PROTECTED]>

Add Q and D histograms (based upon IO size)

Signed-off-by: Alan D. Brunelle <[EMAIL PROTECTED]>
---

 btt/bt_timeline.c    |    1 +
 btt/globals.h        |   11 +++++++++++
 btt/inlines.h        |   16 ++++++++++++++++
 btt/output.c         |   39 +++++++++++++++++++++++++++++++++++++++
 btt/trace_complete.c |    2 +-
 btt/trace_issue.c    |    2 ++
 btt/trace_queue.c    |    2 ++
 7 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/btt/bt_timeline.c b/btt/bt_timeline.c
index 36d9c74..0438e3f 100644
--- a/btt/bt_timeline.c
+++ b/btt/bt_timeline.c
@@ -39,6 +39,7 @@ time_t genesis, last_vtrace;
 LIST_HEAD(all_devs);
 LIST_HEAD(all_procs);
 LIST_HEAD(free_ios);
+__u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];
 
 double range_delta = 0.1;
 __u64 last_q = (__u64)-1;
diff --git a/btt/globals.h b/btt/globals.h
index b47e9f5..aebd0d8 100644
--- a/btt/globals.h
+++ b/btt/globals.h
@@ -27,6 +27,16 @@
 #include "rbtree.h"
 #include "list.h"
 
+/*
+ * 0 == 1 blk
+ * 1 == 2 blks
+ * ...
+ * 1022 == 1023 blks
+ * 1023 == 1024 blks
+ * 1024 == > 1024 blks
+ */
+#define N_HIST_BKTS    1025
+
 #define BIT_TIME(t)    ((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9))
 
 #define BIT_START(iop) ((iop)->t.sector)
@@ -195,6 +205,7 @@ extern struct list_head free_ios;
 extern __u64 iostat_interval, iostat_last_stamp;
 extern time_t genesis, last_vtrace;
 extern double t_astart, t_aend;
+extern __u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];
 #if defined(DEBUG)
 extern int rb_tree_size;
 #endif
diff --git a/btt/inlines.h b/btt/inlines.h
index 5eb183c..8756bea 100644
--- a/btt/inlines.h
+++ b/btt/inlines.h
@@ -432,3 +432,19 @@ static inline void bilink_for_each_down(bilink_func func, 
struct io *uiop,
                        biunlink(blp);
        }
 }
+
+static inline int histo_idx(__u64 nbytes)
+{
+       int idx = (nbytes >> 9) - 1;
+       return min(idx, N_HIST_BKTS-1);
+}
+
+static inline void update_q_histo(__u64 nbytes)
+{
+       q_histo[histo_idx(nbytes)]++;
+}
+
+static inline void update_d_histo(__u64 nbytes)
+{
+       d_histo[histo_idx(nbytes)]++;
+}
diff --git a/btt/output.c b/btt/output.c
index 8baf14d..44e7bac 100644
--- a/btt/output.c
+++ b/btt/output.c
@@ -484,6 +484,43 @@ void output_plug_info(FILE *ofp)
        fprintf(ofp, "\n");
 }
 
+void output_histos(void)
+{
+       int i;
+       FILE *ofp;
+       char fname[256];
+
+       if (output_name == NULL) return;
+
+       sprintf(fname, "%s_qhist.dat", output_name);
+       ofp = fopen(fname, "w");
+       if (!ofp) {
+               perror(fname);
+               return;
+       }
+
+       fprintf(ofp, "# BTT histogram data\n");
+       fprintf(ofp, "# Q buckets\n");
+       for (i = 0; i < (N_HIST_BKTS-1); i++) 
+               fprintf(ofp, "%4d %lld\n", (i+1), (long long)q_histo[i]);
+       fprintf(ofp, "\n# Q bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
+               N_HIST_BKTS-1, q_histo[N_HIST_BKTS-1]);
+       fclose(ofp);
+
+       sprintf(fname, "%s_dhist.dat", output_name);
+       ofp = fopen(fname, "w");
+       if (!ofp) {
+               perror(fname);
+               return;
+       }
+       fprintf(ofp, "# D buckets\n");
+       for (i = 0; i < (N_HIST_BKTS-1); i++)
+               fprintf(ofp, "%4d %lld\n", (i+1), (long long)d_histo[i]);
+       fprintf(ofp, "\n# D bucket for > %d\n%4d %lld\n", (int)N_HIST_BKTS-1,
+               N_HIST_BKTS-1, d_histo[N_HIST_BKTS-1]);
+       fclose(ofp);
+}
+
 int output_avgs(FILE *ofp)
 {
        if (exes == NULL || *exes != '\0') {
@@ -534,6 +571,8 @@ int output_avgs(FILE *ofp)
        output_section_hdr(ofp, "Plug Information");
        output_plug_info(ofp);
 
+       output_histos();
+
        return 0;
 }
 
diff --git a/btt/trace_complete.c b/btt/trace_complete.c
index c82ccb3..ac85c32 100644
--- a/btt/trace_complete.c
+++ b/btt/trace_complete.c
@@ -27,7 +27,7 @@ static inline void __run_complete(struct io *c_iop)
        LIST_HEAD(rmhd);
 
        if (remapper_dev(c_iop->t.device)) {
-               struct bilink *blp;
+               struct bilink *blp = blp;
                struct io *iop = bilink_first_down(c_iop, &blp);
 
                if (iop->type == IOP_Q) {
diff --git a/btt/trace_issue.c b/btt/trace_issue.c
index 5266e87..780a133 100644
--- a/btt/trace_issue.c
+++ b/btt/trace_issue.c
@@ -93,6 +93,8 @@ void trace_issue(struct io *d_iop)
                seeki_add(d_iop->dip->seek_handle, d_iop);
                iostat_issue(d_iop);
                d_iop->dip->n_ds++;
+               if (!remapper_dev(d_iop->t.device))
+                       update_d_histo(d_iop->t.bytes);
        }
        else
                io_release(d_iop);
diff --git a/btt/trace_queue.c b/btt/trace_queue.c
index 676684d..ea285e3 100644
--- a/btt/trace_queue.c
+++ b/btt/trace_queue.c
@@ -71,6 +71,8 @@ void trace_queue(struct io *q_iop)
                update_qregion(&all_regions, q_iop->t.time);
                dip_update_q(q_iop->dip, q_iop);
                pip_update_q(q_iop);
+               if (!remapper_dev(q_iop->t.device))
+                       update_q_histo(q_iop->t.bytes);
        }
        else
                io_release(q_iop);

Reply via email to