Added in running stats for btt
authorAlan D. Brunelle <alan.brunelle@hp.com>
Fri, 14 Aug 2009 17:00:27 +0000 (13:00 -0400)
committerAlan D. Brunelle <alan.brunelle@hp.com>
Fri, 14 Aug 2009 17:00:27 +0000 (13:00 -0400)
Create an overall system and per-device statistics file containing
MB-per-second and I/Os-per-second values. Format for each file is first
column contains an (integer) time stamp (seconds since start of run)
and a (double) value.

File names are:

sys_mbps_fp.dat - system-wide mbps (for all devices watched, of course)
sys_iops_fp.dat - I/Os per sec

Each device watched will have a file with the device preceeding the
_mbps or _iops section of the above file names.

btt/Makefile
btt/bt_timeline.c
btt/devs.c
btt/globals.h
btt/rstats.c [new file with mode: 0644]
btt/trace.c
btt/trace_complete.c

index 1f6dacc25c89261f440a79d044f21afc1e8c9327..1dc4b5c13dbfc44d88425f5d4f50b8ec5055b62a 100644 (file)
@@ -17,7 +17,7 @@ OBJS  = args.o bt_timeline.o devmap.o devs.o dip_rb.o iostat.o latency.o \
          misc.o output.o proc.o seek.o trace.o trace_complete.o trace_im.o \
          trace_issue.o trace_queue.o trace_remap.o trace_requeue.o \
          ../rbtree.o mmap.o trace_plug.o bno_dump.o unplug_hist.o q2d.o \
-         aqd.o plat.o
+         aqd.o plat.o rstats.o
 
 all: depend $(PROGS)
 
index 24dafc89e98c0f1284a4d4dcb23f05279fdba3f0..9b0850b8729c511493e6c3e3563fbefae7dfe6d7 100644 (file)
@@ -33,7 +33,7 @@ char *sps_name, *aqd_name, *q2d_name, *per_io_trees;
 FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *per_io_ofp, *msgs_ofp;
 int verbose, done, time_bounded, output_all_data, seek_absolute;
 int easy_parse_avgs, ignore_remaps;
-double t_astart, t_aend;
+double t_astart, t_aend, last_t_seen;
 unsigned long n_traces;
 struct avgs_info all_avgs;
 unsigned int n_devs;
@@ -62,6 +62,9 @@ int main(int argc, char *argv[])
 
        init_dev_heads();
        iostat_init();
+       if (!rstat_init())
+               return 1;
+
        if (process() || output_avgs(avgs_ofp) || output_ranges(rngs_ofp))
                return 1;
 
@@ -82,6 +85,7 @@ int main(int argc, char *argv[])
        dip_cleanup();
        dev_map_exit();
        dip_exit();
+       rstat_exit();
        pip_exit();
        io_free_all();
        region_exit(&all_regions);
index 3578633149c4a55c180c0e35c5d895a7e067b132..2f1c6c065e840a98a9b39cbebf3d4601b5d96ec6 100644 (file)
@@ -86,6 +86,7 @@ void __dip_exit(struct d_info *dip)
        plat_free(dip->d2c_plat_handle);
        bno_dump_free(dip->bno_dump_handle);
        unplug_hist_free(dip->up_hist_handle);
+       rstat_free(dip->rstat_handle);
        if (output_all_data)
                q2d_free(dip->q2d_priv);
        if (dip->pit_fp)
@@ -152,6 +153,7 @@ struct d_info *dip_alloc(__u32 device, struct io *iop)
                list_add_tail(&dip->all_head, &all_devs);
                dip->start_time = BIT_TIME(iop->t.time);
                dip->pre_culling = 1;
+               dip->rstat_handle = rstat_alloc(mkhandle(str, device, ""));
                if (output_all_data)
                        dip->q2d_priv = q2d_alloc();
                n_devs++;
index d05d9966138141e3b9ca10a9de06e1c91c9778e1..5235ec650b0bc762c1c9b83790ee84bc6267821e 100644 (file)
@@ -133,7 +133,7 @@ struct d_info {
        struct region_info regions;
        char *devmap;
        void *q2q_handle, *seek_handle, *bno_dump_handle, *up_hist_handle;
-       void *q2d_priv, *aqd_handle;
+       void *q2d_priv, *aqd_handle, *rstat_handle;
        void *q2d_plat_handle, *q2c_plat_handle, *d2c_plat_handle;
        FILE *q2d_ofp, *d2c_ofp, *q2c_ofp, *pit_fp;
        struct avgs_info avgs;
@@ -170,7 +170,7 @@ extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name;
 extern char *seek_name, *iostat_name, *d2c_name, *q2c_name, *per_io_name;
 extern char *bno_dump_name, *unplug_hist_name, *sps_name, *aqd_name, *q2d_name;
 extern char *per_io_trees;
-extern double range_delta, plat_freq;
+extern double range_delta, plat_freq, last_t_seen;
 extern FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *iostat_ofp, *per_io_ofp;
 extern FILE *msgs_ofp;
 extern int verbose, done, time_bounded, output_all_data, seek_absolute;
@@ -290,6 +290,13 @@ void q2d_display(FILE *fp, void *priv);
 int q2d_ok(void *priv);
 void q2d_acc(void *a1, void *a2);
 
+/* rstats.c */
+void *rstat_alloc(char *bn);
+void rstat_free(void *ptr);
+void rstat_add(void *ptr, double cur, unsigned long long nblks);
+int rstat_init(void);
+void rstat_exit(void);
+
 /* seek.c */
 void *seeki_alloc(char *str);
 void seeki_free(void *param);
diff --git a/btt/rstats.c b/btt/rstats.c
new file mode 100644 (file)
index 0000000..c0d2904
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * blktrace output analysis: generate a timeline & gather statistics
+ *
+ * (C) Copyright 2009 Hewlett-Packard Development Company, L.P.
+ *     Alan D. Brunelle (alan.brunelle@hp.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+#include "globals.h"
+
+struct files {
+       FILE *fp;
+       char *nm;
+};
+
+struct rstat {
+       struct list_head head;
+       struct files files[2];
+       unsigned long long ios, nblks;
+       long long base_sec;
+};
+
+static struct rstat *sys_info;
+static LIST_HEAD(rstats);
+
+static int do_open(struct files *fip, char *bn, char *pn)
+{
+       fip->nm = malloc(sizeof(bn) + 16);
+       sprintf(fip->nm, "%s_%s.dat", bn, pn);
+
+       fip->fp = my_fopen(fip->nm, "w");
+       if (fip->fp) {
+               add_file(fip->fp, fip->nm);
+               return 0;
+       }
+
+       free(fip->nm);
+       return -1;
+}
+
+static int init_rsip(struct rstat *rsip, char *bn)
+{
+       rsip->ios = rsip->nblks = 0;
+       if (do_open(&rsip->files[0], bn, "iops_fp") ||
+                           do_open(&rsip->files[1], bn, "mbps_fp"))
+               return -1;
+
+       list_add_tail(&rsip->head, &rstats);
+       return 0;
+}
+
+static void rstat_emit(struct rstat *rsip, double cur)
+{
+       double mbps;
+
+       /*
+        * I/Os per second is easy: just the ios
+        */
+       fprintf(rsip->files[0].fp, "%lld %llu\n", rsip->base_sec, rsip->ios);
+
+       /*
+        * MB/s we convert blocks to mb...
+        */
+       mbps = ((double)rsip->nblks * 512.0) / (1024.0 * 1024.0);
+       fprintf(rsip->files[1].fp, "%lld %lf\n", rsip->base_sec, mbps);
+
+       rsip->base_sec = (unsigned long long)cur;
+       rsip->ios = rsip->nblks = 0;
+}
+
+static void __add(struct rstat *rsip, double cur, unsigned long long nblks)
+{
+       if (rsip->base_sec < 0)
+               rsip->base_sec = (long long)cur;
+       else if (((long long)cur - rsip->base_sec) >= 1)
+               rstat_emit(rsip, cur);
+
+       rsip->ios++;
+       rsip->nblks += nblks;
+}
+
+void *rstat_alloc(char *bn)
+{
+       struct rstat *rsip = malloc(sizeof(*rsip));
+
+       if (!init_rsip(rsip, bn))
+               return rsip;
+
+       free(rsip);
+       return NULL;
+}
+
+void rstat_free(void *ptr)
+{
+       struct rstat *rsip = ptr;
+
+       rstat_emit(rsip, last_t_seen);
+       list_del(&rsip->head);
+       free(rsip);
+}
+
+void rstat_add(void *ptr, double cur, unsigned long long nblks)
+{
+       if (ptr != NULL)
+               __add((struct rstat *)ptr, cur, nblks);
+       __add(sys_info, cur, nblks);
+}
+
+int rstat_init(void)
+{
+       sys_info = rstat_alloc("sys");
+       return sys_info != NULL;
+}
+
+void rstat_exit(void)
+{
+       struct list_head *p, *q;
+
+       list_for_each_safe(p, q, &rstats) {
+               struct rstat *rsip = list_entry(p, struct rstat, head);
+               rstat_free(rsip);
+       }
+}
index e18a8875820f03dcbbcefa207a76201b80ce1e41..48f4f99f754524cda107a1c63d72dd5c587edd86 100644 (file)
@@ -24,6 +24,8 @@ 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);
 
index 6f616bcab2499d80ff23af92e1cf18678f02122f..d34fbd0caa8ad04e5984ec0c672a868698ee46f9 100644 (file)
@@ -55,13 +55,15 @@ static void handle_complete(struct io *c_iop)
        struct list_head *p, *q;
        __u64 d_time = (__u64)-1;
        FILE *pit_fp = c_iop->dip->pit_fp;
+       double cur = BIT_TIME(c_iop->t.time);
 
        update_blks(c_iop);
        update_cregion(&all_regions, c_iop->t.time);
        update_cregion(&c_iop->dip->regions, c_iop->t.time);
        if (c_iop->pip)
                update_cregion(&c_iop->pip->regions, c_iop->t.time);
-       aqd_complete(c_iop->dip->aqd_handle, BIT_TIME(c_iop->t.time));
+       aqd_complete(c_iop->dip->aqd_handle, cur);
+       rstat_add(c_iop->dip->rstat_handle, cur, c_iop->t.bytes >> 9);
 
        dip_foreach_list(c_iop, IOP_Q, &head);
        list_for_each_safe(p, q, &head) {