Commit | Line | Data |
---|---|---|
69040794 AB |
1 | /* |
2 | * blktrace output analysis: generate a timeline & gather statistics | |
3 | * | |
4 | * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | #include "globals.h" | |
22 | ||
23 | struct bno_dump { | |
24 | FILE *rfp, *wfp, *cfp; | |
25 | }; | |
26 | ||
a155ab98 | 27 | static FILE *bno_dump_open(struct d_info *dip, char rwc) |
69040794 AB |
28 | { |
29 | FILE *fp; | |
30 | char *oname; | |
69040794 | 31 | |
a155ab98 AB |
32 | oname = malloc(strlen(bno_dump_name) + strlen(dip->dip_name) + 32); |
33 | sprintf(oname, "%s_%s_%c.dat", bno_dump_name, dip->dip_name, rwc); | |
99bb5ebc | 34 | if ((fp = my_fopen(oname, "w")) == NULL) |
69040794 AB |
35 | perror(oname); |
36 | else | |
c053af42 | 37 | add_file(fp, oname); |
69040794 AB |
38 | return fp; |
39 | } | |
40 | ||
c053af42 AB |
41 | static inline void bno_dump_write(FILE *fp, struct io *iop) |
42 | { | |
43 | fprintf(fp, "%15.9lf %lld %lld\n", BIT_TIME(iop->t.time), | |
44 | (long long)BIT_START(iop), (long long)BIT_END(iop)); | |
45 | } | |
46 | ||
a155ab98 | 47 | void *bno_dump_alloc(struct d_info *dip) |
69040794 AB |
48 | { |
49 | struct bno_dump *bdp; | |
50 | ||
51 | if (bno_dump_name == NULL) return NULL; | |
52 | ||
53 | bdp = malloc(sizeof(*bdp)); | |
a155ab98 AB |
54 | bdp->rfp = bno_dump_open(dip, 'r'); |
55 | bdp->wfp = bno_dump_open(dip, 'w'); | |
56 | bdp->cfp = bno_dump_open(dip, 'c'); | |
69040794 AB |
57 | |
58 | return bdp; | |
59 | } | |
60 | ||
c053af42 | 61 | void bno_dump_free(void *param) |
69040794 | 62 | { |
69040794 AB |
63 | free(param); |
64 | } | |
65 | ||
69040794 AB |
66 | void bno_dump_add(void *handle, struct io *iop) |
67 | { | |
69040794 AB |
68 | struct bno_dump *bdp = handle; |
69 | ||
70 | if (bdp) { | |
c053af42 AB |
71 | FILE *fp = IOP_READ(iop) ? bdp->rfp : bdp->wfp; |
72 | ||
73 | if (fp) | |
74 | bno_dump_write(fp, iop); | |
69040794 AB |
75 | if (bdp->cfp) |
76 | bno_dump_write(bdp->cfp, iop); | |
77 | } | |
78 | } |