From dbb8d92dc5d3d61fca94c8eef3636bc4044deda2 Mon Sep 17 00:00:00 2001 From: "Alan D. Brunelle" Date: Fri, 14 Aug 2009 13:00:27 -0400 Subject: [PATCH] Added in running stats for btt 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 | 2 +- btt/bt_timeline.c | 6 +- btt/devs.c | 2 + btt/globals.h | 11 +++- btt/rstats.c | 136 +++++++++++++++++++++++++++++++++++++++++++ btt/trace.c | 2 + btt/trace_complete.c | 4 +- 7 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 btt/rstats.c diff --git a/btt/Makefile b/btt/Makefile index 1f6dacc..1dc4b5c 100644 --- a/btt/Makefile +++ b/btt/Makefile @@ -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) diff --git a/btt/bt_timeline.c b/btt/bt_timeline.c index 24dafc8..9b0850b 100644 --- a/btt/bt_timeline.c +++ b/btt/bt_timeline.c @@ -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); diff --git a/btt/devs.c b/btt/devs.c index 3578633..2f1c6c0 100644 --- a/btt/devs.c +++ b/btt/devs.c @@ -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++; diff --git a/btt/globals.h b/btt/globals.h index d05d996..5235ec6 100644 --- a/btt/globals.h +++ b/btt/globals.h @@ -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 index 0000000..c0d2904 --- /dev/null +++ b/btt/rstats.c @@ -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); + } +} diff --git a/btt/trace.c b/btt/trace.c index e18a887..48f4f99 100644 --- a/btt/trace.c +++ b/btt/trace.c @@ -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); diff --git a/btt/trace_complete.c b/btt/trace_complete.c index 6f616bc..d34fbd0 100644 --- a/btt/trace_complete.c +++ b/btt/trace_complete.c @@ -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) { -- 2.25.1