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(strlen(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, struct d_info *dip)
56 char *nm = dip ? dip->dip_name : "sys";
59 rsip->ios = rsip->nblks = 0;
60 if (do_open(&rsip->files[0], nm, "iops_fp") ||
61 do_open(&rsip->files[1], nm, "mbps_fp"))
64 list_add_tail(&rsip->head, &rstats);
68 static void rstat_emit(struct rstat *rsip, double cur)
73 * I/Os per second is easy: just the ios
75 fprintf(rsip->files[0].fp, "%lld %llu\n", rsip->base_sec, rsip->ios);
78 * MB/s we convert blocks to mb...
80 mbps = ((double)rsip->nblks * 512.0) / (1024.0 * 1024.0);
81 fprintf(rsip->files[1].fp, "%lld %lf\n", rsip->base_sec, mbps);
83 rsip->base_sec = (unsigned long long)cur;
84 rsip->ios = rsip->nblks = 0;
87 static void __add(struct rstat *rsip, double cur, unsigned long long nblks)
89 if (rsip->base_sec < 0)
90 rsip->base_sec = (long long)cur;
91 else if (((long long)cur - rsip->base_sec) >= 1)
92 rstat_emit(rsip, cur);
98 void *rstat_alloc(struct d_info *dip)
100 struct rstat *rsip = malloc(sizeof(*rsip));
102 if (!init_rsip(rsip, dip))
109 void rstat_free(void *ptr)
111 struct rstat *rsip = ptr;
113 rstat_emit(rsip, last_t_seen);
114 list_del(&rsip->head);
118 void rstat_add(void *ptr, double cur, unsigned long long nblks)
121 __add((struct rstat *)ptr, cur, nblks);
122 __add(sys_info, cur, nblks);
127 sys_info = rstat_alloc(NULL);
128 return sys_info != NULL;
131 void rstat_exit(void)
133 struct list_head *p, *q;
135 list_for_each_safe(p, q, &rstats) {
136 struct rstat *rsip = list_entry(p, struct rstat, head);