Major revamping (ver 2.0)
[blktrace.git] / btt / latency.c
CommitLineData
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
23static struct file_info *all_files = NULL;
24
25static inline void latency_out(FILE *ofp, __u64 tstamp, __u64 latency)
26{
27 if (ofp)
28 fprintf(ofp, "%lf %lf\n", TO_SEC(tstamp), TO_SEC(latency));
29}
30
31FILE *latency_open(__u32 device, char *name, char *post)
32{
33 FILE *fp;
34 char *oname;
35 int mjr, mnr;
36
37 if (name == NULL) return NULL;
38
39 mjr = device >> MINORBITS;
40 mnr = device & ((1 << MINORBITS) - 1);
41
42 oname = malloc(strlen(name)+32);
43 sprintf(oname, "%s_%03d,%03d_%s.dat", name, mjr, mnr, post);
44 if ((fp = fopen(oname, "w")) == NULL)
45 perror(oname);
46 else
47 add_file(&all_files, fp, oname);
48
49 return fp;
50}
51
52void latency_init(struct d_info *dip)
53{
54 dip->d2c_ofp = latency_open(dip->device, d2c_name, "d2c");
55 dip->q2c_ofp = latency_open(dip->device, q2c_name, "q2c");
56}
57
58void latency_clean(void)
59{
60 clean_files(&all_files);
61}
62
63void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency)
64{
65 latency_out(dip->d2c_ofp, tstamp, latency);
66}
67
68void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency)
69{
70 latency_out(dip->q2c_ofp, tstamp, latency);
71}