xref: /aosp_15_r20/external/blktrace/blkiomon.h (revision 1a3d31e37cc95e9919fd86900a2b6a555f55952c)
1*1a3d31e3SAndroid Build Coastguard Worker /*
2*1a3d31e3SAndroid Build Coastguard Worker  * I/O monitor based on block queue trace data
3*1a3d31e3SAndroid Build Coastguard Worker  *
4*1a3d31e3SAndroid Build Coastguard Worker  * Copyright IBM Corp. 2008
5*1a3d31e3SAndroid Build Coastguard Worker  *
6*1a3d31e3SAndroid Build Coastguard Worker  * Author(s): Martin Peschke <[email protected]>
7*1a3d31e3SAndroid Build Coastguard Worker  *
8*1a3d31e3SAndroid Build Coastguard Worker  *  This program is free software; you can redistribute it and/or modify
9*1a3d31e3SAndroid Build Coastguard Worker  *  it under the terms of the GNU General Public License as published by
10*1a3d31e3SAndroid Build Coastguard Worker  *  the Free Software Foundation; either version 2 of the License, or
11*1a3d31e3SAndroid Build Coastguard Worker  *  (at your option) any later version.
12*1a3d31e3SAndroid Build Coastguard Worker  *
13*1a3d31e3SAndroid Build Coastguard Worker  *  This program is distributed in the hope that it will be useful,
14*1a3d31e3SAndroid Build Coastguard Worker  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15*1a3d31e3SAndroid Build Coastguard Worker  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*1a3d31e3SAndroid Build Coastguard Worker  *  GNU General Public License for more details.
17*1a3d31e3SAndroid Build Coastguard Worker  *
18*1a3d31e3SAndroid Build Coastguard Worker  *  You should have received a copy of the GNU General Public License
19*1a3d31e3SAndroid Build Coastguard Worker  *  along with this program; if not, write to the Free Software
20*1a3d31e3SAndroid Build Coastguard Worker  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21*1a3d31e3SAndroid Build Coastguard Worker  */
22*1a3d31e3SAndroid Build Coastguard Worker 
23*1a3d31e3SAndroid Build Coastguard Worker #ifndef BLKIOMON_H
24*1a3d31e3SAndroid Build Coastguard Worker #define BLKIOMON_H
25*1a3d31e3SAndroid Build Coastguard Worker 
26*1a3d31e3SAndroid Build Coastguard Worker #include <string.h>
27*1a3d31e3SAndroid Build Coastguard Worker 
28*1a3d31e3SAndroid Build Coastguard Worker #include "stats.h"
29*1a3d31e3SAndroid Build Coastguard Worker #include "blktrace.h"
30*1a3d31e3SAndroid Build Coastguard Worker 
31*1a3d31e3SAndroid Build Coastguard Worker #define BLKIOMON_SIZE_BUCKETS 16
32*1a3d31e3SAndroid Build Coastguard Worker #define BLKIOMON_D2C_BUCKETS 25
33*1a3d31e3SAndroid Build Coastguard Worker struct blkiomon_stat {
34*1a3d31e3SAndroid Build Coastguard Worker 	__u64 time;
35*1a3d31e3SAndroid Build Coastguard Worker 	__u32 size_hist[BLKIOMON_SIZE_BUCKETS];
36*1a3d31e3SAndroid Build Coastguard Worker 	__u32 d2c_hist[BLKIOMON_D2C_BUCKETS];
37*1a3d31e3SAndroid Build Coastguard Worker 	__u32 device;
38*1a3d31e3SAndroid Build Coastguard Worker 	struct minmax size_r;
39*1a3d31e3SAndroid Build Coastguard Worker 	struct minmax size_w;
40*1a3d31e3SAndroid Build Coastguard Worker 	struct minmax d2c_r;
41*1a3d31e3SAndroid Build Coastguard Worker 	struct minmax d2c_w;
42*1a3d31e3SAndroid Build Coastguard Worker 	struct minmax thrput_r;
43*1a3d31e3SAndroid Build Coastguard Worker 	struct minmax thrput_w;
44*1a3d31e3SAndroid Build Coastguard Worker 	__u64 bidir;
45*1a3d31e3SAndroid Build Coastguard Worker };
46*1a3d31e3SAndroid Build Coastguard Worker 
47*1a3d31e3SAndroid Build Coastguard Worker static struct histlog2 size_hist = {
48*1a3d31e3SAndroid Build Coastguard Worker 	.first = 0,
49*1a3d31e3SAndroid Build Coastguard Worker 	.delta = 1024,
50*1a3d31e3SAndroid Build Coastguard Worker 	.num = BLKIOMON_SIZE_BUCKETS
51*1a3d31e3SAndroid Build Coastguard Worker };
52*1a3d31e3SAndroid Build Coastguard Worker 
53*1a3d31e3SAndroid Build Coastguard Worker static struct histlog2 d2c_hist = {
54*1a3d31e3SAndroid Build Coastguard Worker 	.first = 0,
55*1a3d31e3SAndroid Build Coastguard Worker 	.delta = 8,
56*1a3d31e3SAndroid Build Coastguard Worker 	.num = BLKIOMON_D2C_BUCKETS
57*1a3d31e3SAndroid Build Coastguard Worker };
58*1a3d31e3SAndroid Build Coastguard Worker 
blkiomon_stat_init(struct blkiomon_stat * bstat)59*1a3d31e3SAndroid Build Coastguard Worker static inline void blkiomon_stat_init(struct blkiomon_stat *bstat)
60*1a3d31e3SAndroid Build Coastguard Worker {
61*1a3d31e3SAndroid Build Coastguard Worker 	memset(bstat, 0, sizeof(*bstat));
62*1a3d31e3SAndroid Build Coastguard Worker 	minmax_init(&bstat->size_r);
63*1a3d31e3SAndroid Build Coastguard Worker 	minmax_init(&bstat->size_w);
64*1a3d31e3SAndroid Build Coastguard Worker 	minmax_init(&bstat->d2c_r);
65*1a3d31e3SAndroid Build Coastguard Worker 	minmax_init(&bstat->d2c_w);
66*1a3d31e3SAndroid Build Coastguard Worker 	minmax_init(&bstat->thrput_r);
67*1a3d31e3SAndroid Build Coastguard Worker 	minmax_init(&bstat->thrput_w);
68*1a3d31e3SAndroid Build Coastguard Worker }
69*1a3d31e3SAndroid Build Coastguard Worker 
blkiomon_stat_to_be(struct blkiomon_stat * bstat)70*1a3d31e3SAndroid Build Coastguard Worker static inline void blkiomon_stat_to_be(struct blkiomon_stat *bstat)
71*1a3d31e3SAndroid Build Coastguard Worker {
72*1a3d31e3SAndroid Build Coastguard Worker 	histlog2_to_be(bstat->size_hist, &size_hist);
73*1a3d31e3SAndroid Build Coastguard Worker 	histlog2_to_be(bstat->d2c_hist, &d2c_hist);
74*1a3d31e3SAndroid Build Coastguard Worker 	minmax_to_be(&bstat->size_r);
75*1a3d31e3SAndroid Build Coastguard Worker 	minmax_to_be(&bstat->size_w);
76*1a3d31e3SAndroid Build Coastguard Worker 	minmax_to_be(&bstat->d2c_r);
77*1a3d31e3SAndroid Build Coastguard Worker 	minmax_to_be(&bstat->d2c_w);
78*1a3d31e3SAndroid Build Coastguard Worker 	minmax_to_be(&bstat->thrput_r);
79*1a3d31e3SAndroid Build Coastguard Worker 	minmax_to_be(&bstat->thrput_w);
80*1a3d31e3SAndroid Build Coastguard Worker 	bstat->bidir = cpu_to_be64(bstat->bidir);
81*1a3d31e3SAndroid Build Coastguard Worker 	bstat->time = cpu_to_be64(bstat->time);
82*1a3d31e3SAndroid Build Coastguard Worker 	bstat->device = cpu_to_be32(bstat->device);
83*1a3d31e3SAndroid Build Coastguard Worker }
84*1a3d31e3SAndroid Build Coastguard Worker 
blkiomon_stat_merge(struct blkiomon_stat * dst,struct blkiomon_stat * src)85*1a3d31e3SAndroid Build Coastguard Worker static inline void blkiomon_stat_merge(struct blkiomon_stat *dst,
86*1a3d31e3SAndroid Build Coastguard Worker 				       struct blkiomon_stat *src)
87*1a3d31e3SAndroid Build Coastguard Worker {
88*1a3d31e3SAndroid Build Coastguard Worker 	histlog2_merge(&size_hist, dst->size_hist, src->size_hist);
89*1a3d31e3SAndroid Build Coastguard Worker 	histlog2_merge(&d2c_hist, dst->d2c_hist, src->d2c_hist);
90*1a3d31e3SAndroid Build Coastguard Worker 	minmax_merge(&dst->size_r, &src->size_r);
91*1a3d31e3SAndroid Build Coastguard Worker 	minmax_merge(&dst->size_w, &src->size_w);
92*1a3d31e3SAndroid Build Coastguard Worker 	minmax_merge(&dst->d2c_r, &src->d2c_r);
93*1a3d31e3SAndroid Build Coastguard Worker 	minmax_merge(&dst->d2c_w, &src->d2c_w);
94*1a3d31e3SAndroid Build Coastguard Worker 	minmax_merge(&dst->thrput_r, &src->thrput_r);
95*1a3d31e3SAndroid Build Coastguard Worker 	minmax_merge(&dst->thrput_w, &src->thrput_w);
96*1a3d31e3SAndroid Build Coastguard Worker 	dst->bidir += src->bidir;
97*1a3d31e3SAndroid Build Coastguard Worker }
98*1a3d31e3SAndroid Build Coastguard Worker 
blkiomon_stat_print(FILE * fp,struct blkiomon_stat * p)99*1a3d31e3SAndroid Build Coastguard Worker static inline void blkiomon_stat_print(FILE *fp, struct blkiomon_stat *p)
100*1a3d31e3SAndroid Build Coastguard Worker {
101*1a3d31e3SAndroid Build Coastguard Worker 	if (!fp)
102*1a3d31e3SAndroid Build Coastguard Worker 		return;
103*1a3d31e3SAndroid Build Coastguard Worker 
104*1a3d31e3SAndroid Build Coastguard Worker 	fprintf(fp, "\ntime: %s", ctime((void *)&p->time));
105*1a3d31e3SAndroid Build Coastguard Worker 	fprintf(fp, "device: %d,%d\n", MAJOR(p->device), MINOR(p->device));
106*1a3d31e3SAndroid Build Coastguard Worker 	minmax_print(fp, "sizes read (bytes)", &p->size_r);
107*1a3d31e3SAndroid Build Coastguard Worker 	minmax_print(fp, "sizes write (bytes)", &p->size_w);
108*1a3d31e3SAndroid Build Coastguard Worker 	minmax_print(fp, "d2c read (usec)", &p->d2c_r);
109*1a3d31e3SAndroid Build Coastguard Worker 	minmax_print(fp, "d2c write (usec)", &p->d2c_w);
110*1a3d31e3SAndroid Build Coastguard Worker 	minmax_print(fp, "throughput read (bytes/msec)", &p->thrput_r);
111*1a3d31e3SAndroid Build Coastguard Worker 	minmax_print(fp, "throughput write (bytes/msec)", &p->thrput_w);
112*1a3d31e3SAndroid Build Coastguard Worker 	histlog2_print(fp, "sizes histogram (bytes)", p->size_hist, &size_hist);
113*1a3d31e3SAndroid Build Coastguard Worker 	histlog2_print(fp, "d2c histogram (usec)", p->d2c_hist, &d2c_hist);
114*1a3d31e3SAndroid Build Coastguard Worker 	fprintf(fp, "bidirectional requests: %ld\n", (unsigned long)p->bidir);
115*1a3d31e3SAndroid Build Coastguard Worker }
116*1a3d31e3SAndroid Build Coastguard Worker 
117*1a3d31e3SAndroid Build Coastguard Worker #endif
118