2 * I/O monitor based on block queue trace data
4 * Copyright IBM Corp. 2008
6 * Author(s): Martin Peschke <mp3@de.ibm.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #define BLKIOMON_SIZE_BUCKETS 16
32 #define BLKIOMON_D2C_BUCKETS 25
33 struct blkiomon_stat {
35 __u32 size_hist[BLKIOMON_SIZE_BUCKETS];
36 __u32 d2c_hist[BLKIOMON_D2C_BUCKETS];
43 } __attribute__ ((packed));
45 static struct histlog2 size_hist = {
48 .num = BLKIOMON_SIZE_BUCKETS
51 static struct histlog2 d2c_hist = {
54 .num = BLKIOMON_D2C_BUCKETS
57 static inline void blkiomon_stat_init(struct blkiomon_stat *bstat)
59 memset(bstat, 0, sizeof(*bstat));
60 minmax_init(&bstat->size_r);
61 minmax_init(&bstat->size_w);
62 minmax_init(&bstat->d2c_r);
63 minmax_init(&bstat->d2c_w);
66 static inline void blkiomon_stat_to_be(struct blkiomon_stat *bstat)
68 histlog2_to_be(bstat->size_hist, &size_hist);
69 histlog2_to_be(bstat->d2c_hist, &d2c_hist);
70 minmax_to_be(&bstat->size_r);
71 minmax_to_be(&bstat->size_w);
72 minmax_to_be(&bstat->d2c_r);
73 minmax_to_be(&bstat->d2c_w);
74 bstat->bidir = cpu_to_be64(bstat->bidir);
75 bstat->time = cpu_to_be64(bstat->time);
76 bstat->device = cpu_to_be32(bstat->device);
79 static inline void blkiomon_stat_merge(struct blkiomon_stat *dst,
80 struct blkiomon_stat *src)
82 histlog2_merge(&size_hist, dst->size_hist, src->size_hist);
83 histlog2_merge(&d2c_hist, dst->d2c_hist, src->d2c_hist);
84 minmax_merge(&dst->size_r, &src->size_r);
85 minmax_merge(&dst->size_w, &src->size_w);
86 minmax_merge(&dst->d2c_r, &src->d2c_r);
87 minmax_merge(&dst->d2c_w, &src->d2c_w);
88 dst->bidir += src->bidir;
91 static inline void blkiomon_stat_print(FILE *fp, struct blkiomon_stat *p)
96 fprintf(fp, "\ntime: %s", ctime((void *)&p->time));
97 fprintf(fp, "device: %d,%d\n", MAJOR(p->device), MINOR(p->device));
98 minmax_print(fp, "sizes read (bytes)", &p->size_r);
99 minmax_print(fp, "sizes write (bytes)", &p->size_w);
100 minmax_print(fp, "d2c read (usec)", &p->d2c_r);
101 minmax_print(fp, "d2c write (usec)", &p->d2c_w);
102 histlog2_print(fp, "sizes histogram (bytes)", p->size_hist, &size_hist);
103 histlog2_print(fp, "d2c histogram (usec)", p->d2c_hist, &d2c_hist);
104 fprintf(fp, "bidirectional requests: %ld\n", (unsigned long)p->bidir);