aboutsummaryrefslogtreecommitdiff
path: root/btt/trace_complete.c
blob: 44732c54fcbb643f1ddf896c797be6e252b05a82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * blktrace output analysis: generate a timeline & gather statistics
 *
 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include "globals.h"

static inline void __out(FILE *ofp, __u64 tm, enum iop_type type,
					__u64 sec, __u32 nsec, int indent)
{
	if (tm != (__u64)-1) {
		if (indent)
			fprintf(ofp, "         ");
		fprintf(ofp, "%5d.%09lu %c %10llu+%-4u\n",
			(int)SECONDS(tm), (unsigned long)NANO_SECONDS(tm),
			type2c(type), (unsigned long long)sec, nsec);
	}
}

static void display_io_track(FILE *ofp, struct io *iop)
{
	fprintf(ofp, "%3d,%-3d: ", MAJOR(iop->t.device), MINOR(iop->t.device));
	__out(ofp, iop->t.time, IOP_Q, iop->t.sector, t_sec(&iop->t), 0);

	if (iop->g_time != (__u64)-1)
		__out(ofp, iop->g_time, IOP_G, iop->t.sector, t_sec(&iop->t),1);
	if (iop->i_time != (__u64)-1)
		__out(ofp, iop->i_time, IOP_I, iop->t.sector, t_sec(&iop->t),1);
	if (iop->m_time != (__u64)-1)
		__out(ofp, iop->m_time, IOP_M, iop->t.sector, t_sec(&iop->t),1);

	__out(ofp, iop->d_time, IOP_D, iop->d_sec, iop->d_nsec, 1);
	__out(ofp, iop->c_time, IOP_C, iop->c_sec, iop->c_nsec, 1);
	fprintf(ofp, "\n");
}

static void handle_complete(struct io *c_iop)
{
	LIST_HEAD(head);
	struct list_head *p, *q;
	__u64 d_time = (__u64)-1;
	FILE *pit_fp = c_iop->dip->pit_fp;
	double cur = BIT_TIME(c_iop->t.time);

	update_blks(c_iop);
	update_cregion(&all_regions, c_iop->t.time);
	update_cregion(&c_iop->dip->regions, c_iop->t.time);
	if (c_iop->pip)
		update_cregion(&c_iop->pip->regions, c_iop->t.time);
	aqd_complete(c_iop->dip->aqd_handle, cur);
	rstat_add(c_iop->dip->rstat_handle, cur, c_iop->t.bytes >> 9);

	dip_foreach_list(c_iop, IOP_Q, &head);
	list_for_each_safe(p, q, &head) {
		struct io *q_iop = list_entry(p, struct io, f_head);
		__u64 q2c = tdelta(q_iop->t.time, c_iop->t.time);

		c_iop->bytes_left -= q_iop->t.bytes;

		update_q2c(q_iop, q2c);
		latency_q2c(q_iop->dip, q_iop->t.time, q2c);

		if (q_iop->d_time != (__u64)-1) {
			__u64 d2c = tdelta(q_iop->d_time, c_iop->t.time);

			p_live_add(q_iop->dip, q_iop->d_time, c_iop->t.time);
			update_d2c(q_iop, d2c);
			latency_d2c(q_iop->dip, c_iop->t.time, d2c);
			iostat_complete(q_iop, c_iop);

			d_time = q_iop->d_time;
		}

		if (per_io_ofp) {
			q_iop->c_time = c_iop->t.time;
			q_iop->c_sec = c_iop->t.sector;
			q_iop->c_nsec = t_sec(&c_iop->t);
			display_io_track(per_io_ofp, q_iop);
		}

		if (q_iop->dip->pit_fp) {
			fprintf(pit_fp, "%d.%09lu ",
				(int)SECONDS(q_iop->t.time),
				(unsigned long)NANO_SECONDS(q_iop->t.time));
		}

		list_del(&q_iop->f_head);
		io_release(q_iop);
	}

	if (per_io_ofp)
		fprintf(per_io_ofp,
			"-----------------------------------------\n");

	if (c_iop->dip->pit_fp) {
		fprintf(pit_fp, "| %d.%09lu | %d.%09lu\n",
			(int)SECONDS(d_time),
			(unsigned long)NANO_SECONDS(d_time),
			(int)SECONDS(c_iop->t.time),
			(unsigned long)NANO_SECONDS(c_iop->t.time));
	}
}

void trace_complete(struct io *c_iop)
{
	if (c_iop->t.bytes == 0)
		return;

	if (io_setup(c_iop, IOP_C))
		handle_complete(c_iop);

	io_release(c_iop);
}