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];
37 struct minmax size_mm;
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_mm);
61 minmax_init(&bstat->d2c_mm);
64 static inline void blkiomon_stat_to_be(struct blkiomon_stat *bstat)
66 histlog2_to_be(bstat->size_hist, &size_hist);
67 histlog2_to_be(bstat->d2c_hist, &d2c_hist);
68 minmax_to_be(&bstat->size_mm);
69 minmax_to_be(&bstat->d2c_mm);
70 bstat->read = cpu_to_be64(bstat->read);
71 bstat->write = cpu_to_be64(bstat->write);
72 bstat->bidir = cpu_to_be64(bstat->bidir);
73 bstat->time = cpu_to_be64(bstat->time);
74 bstat->device = cpu_to_be32(bstat->device);
77 static inline void blkiomon_stat_merge(struct blkiomon_stat *dst,
78 struct blkiomon_stat *src)
80 histlog2_merge(&size_hist, dst->size_hist, src->size_hist);
81 histlog2_merge(&d2c_hist, dst->d2c_hist, src->d2c_hist);
82 minmax_merge(&dst->size_mm, &src->size_mm);
83 minmax_merge(&dst->d2c_mm, &src->d2c_mm);
84 dst->read += src->read;
85 dst->write += src->write;
86 dst->bidir += src->bidir;
89 static inline void blkiomon_stat_print(FILE *fp, struct blkiomon_stat *p)
94 fprintf(fp, "\ntime: %s", ctime((void *)&p->time));
95 fprintf(fp, "device: %d,%d\n", MAJOR(p->device), MINOR(p->device));
96 fprintf(fp, "requests: read %ld, write %ld, bidir: %ld\n",
97 (unsigned long)p->read, (unsigned long)p->write,
98 (unsigned long)p->bidir);
99 minmax_print(fp, "sizes", &p->size_mm);
100 minmax_print(fp, "d2c", &p->d2c_mm);
101 histlog2_print(fp, "sizes histogram (in kB)", p->size_hist, &size_hist);
102 histlog2_print(fp, "d2c histogram (in usec)", p->d2c_hist, &d2c_hist);