Commit | Line | Data |
---|---|---|
b2ecdd0f ADB |
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 | ||
b2ecdd0f ADB |
23 | static inline void latency_out(FILE *ofp, __u64 tstamp, __u64 latency) |
24 | { | |
25 | if (ofp) | |
26 | fprintf(ofp, "%lf %lf\n", TO_SEC(tstamp), TO_SEC(latency)); | |
27 | } | |
28 | ||
29 | FILE *latency_open(__u32 device, char *name, char *post) | |
30 | { | |
c053af42 | 31 | FILE *fp = NULL; |
b2ecdd0f | 32 | |
c053af42 AB |
33 | if (name) { |
34 | int mjr, mnr; | |
35 | char oname[strlen(name) + 32]; | |
b2ecdd0f | 36 | |
c053af42 AB |
37 | mjr = device >> MINORBITS; |
38 | mnr = device & ((1 << MINORBITS) - 1); | |
b2ecdd0f | 39 | |
c053af42 AB |
40 | sprintf(oname, "%s_%03d,%03d_%s.dat", name, mjr, mnr, post); |
41 | if ((fp = my_fopen(oname, "w")) == NULL) | |
42 | perror(oname); | |
43 | else | |
44 | add_file(fp, strdup(oname)); | |
45 | } | |
b2ecdd0f ADB |
46 | |
47 | return fp; | |
48 | } | |
49 | ||
c053af42 | 50 | void latency_alloc(struct d_info *dip) |
b2ecdd0f | 51 | { |
e47ada10 | 52 | dip->q2d_ofp = latency_open(dip->device, q2d_name, "q2d"); |
b2ecdd0f ADB |
53 | dip->d2c_ofp = latency_open(dip->device, d2c_name, "d2c"); |
54 | dip->q2c_ofp = latency_open(dip->device, q2c_name, "q2c"); | |
55 | } | |
56 | ||
e47ada10 AB |
57 | void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency) |
58 | { | |
59 | plat_x2c(dip->q2d_plat_handle, tstamp, latency); | |
60 | latency_out(dip->q2d_ofp, tstamp, latency); | |
61 | } | |
62 | ||
b2ecdd0f ADB |
63 | void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency) |
64 | { | |
2baef508 | 65 | plat_x2c(dip->d2c_plat_handle, tstamp, latency); |
b2ecdd0f ADB |
66 | latency_out(dip->d2c_ofp, tstamp, latency); |
67 | } | |
68 | ||
69 | void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency) | |
70 | { | |
2baef508 | 71 | plat_x2c(dip->q2c_plat_handle, tstamp, latency); |
b2ecdd0f ADB |
72 | latency_out(dip->q2c_ofp, tstamp, latency); |
73 | } |