2 * blktrace output analysis: generate a timeline & gather statistics
4 * (C) Copyright 2009 Hewlett-Packard Development Company, L.P.
5 * Alan D. Brunelle (alan.brunelle@hp.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 struct list_head head;
31 struct files files[2];
32 unsigned long long ios, nblks;
36 static struct rstat *sys_info;
37 static LIST_HEAD(rstats);
39 static int do_open(struct files *fip, char *bn, char *pn)
41 fip->nm = malloc(sizeof(bn) + 16);
42 sprintf(fip->nm, "%s_%s.dat", bn, pn);
44 fip->fp = my_fopen(fip->nm, "w");
46 add_file(fip->fp, fip->nm);
54 static int init_rsip(struct rstat *rsip, char *bn)
56 rsip->ios = rsip->nblks = 0;
57 if (do_open(&rsip->files[0], bn, "iops_fp") ||
58 do_open(&rsip->files[1], bn, "mbps_fp"))
61 list_add_tail(&rsip->head, &rstats);
65 static void rstat_emit(struct rstat *rsip, double cur)
70 * I/Os per second is easy: just the ios
72 fprintf(rsip->files[0].fp, "%lld %llu\n", rsip->base_sec, rsip->ios);
75 * MB/s we convert blocks to mb...
77 mbps = ((double)rsip->nblks * 512.0) / (1024.0 * 1024.0);
78 fprintf(rsip->files[1].fp, "%lld %lf\n", rsip->base_sec, mbps);
80 rsip->base_sec = (unsigned long long)cur;
81 rsip->ios = rsip->nblks = 0;
84 static void __add(struct rstat *rsip, double cur, unsigned long long nblks)
86 if (rsip->base_sec < 0)
87 rsip->base_sec = (long long)cur;
88 else if (((long long)cur - rsip->base_sec) >= 1)
89 rstat_emit(rsip, cur);
95 void *rstat_alloc(char *bn)
97 struct rstat *rsip = malloc(sizeof(*rsip));
99 if (!init_rsip(rsip, bn))
106 void rstat_free(void *ptr)
108 struct rstat *rsip = ptr;
110 rstat_emit(rsip, last_t_seen);
111 list_del(&rsip->head);
115 void rstat_add(void *ptr, double cur, unsigned long long nblks)
118 __add((struct rstat *)ptr, cur, nblks);
119 __add(sys_info, cur, nblks);
124 sys_info = rstat_alloc("sys");
125 return sys_info != NULL;
128 void rstat_exit(void)
130 struct list_head *p, *q;
132 list_for_each_safe(p, q, &rstats) {
133 struct rstat *rsip = list_entry(p, struct rstat, head);