San Mehat | e20e134 | 2009-06-03 15:36:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * I/O monitor based on block queue trace data |
| 3 | * |
| 4 | * Copyright IBM Corp. 2008 |
| 5 | * |
| 6 | * Author(s): Martin Peschke <mp3@de.ibm.com> |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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 |
| 21 | */ |
| 22 | |
| 23 | #ifndef BLKIOMON_H |
| 24 | #define BLKIOMON_H |
| 25 | |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include "stats.h" |
| 29 | #include "blktrace.h" |
| 30 | |
| 31 | #define BLKIOMON_SIZE_BUCKETS 16 |
| 32 | #define BLKIOMON_D2C_BUCKETS 25 |
| 33 | struct blkiomon_stat { |
| 34 | __u64 time; |
| 35 | __u32 size_hist[BLKIOMON_SIZE_BUCKETS]; |
| 36 | __u32 d2c_hist[BLKIOMON_D2C_BUCKETS]; |
| 37 | __u32 device; |
| 38 | struct minmax size_r; |
| 39 | struct minmax size_w; |
| 40 | struct minmax d2c_r; |
| 41 | struct minmax d2c_w; |
| 42 | struct minmax thrput_r; |
| 43 | struct minmax thrput_w; |
| 44 | __u64 bidir; |
| 45 | }; |
| 46 | |
| 47 | static struct histlog2 size_hist = { |
| 48 | .first = 0, |
| 49 | .delta = 1024, |
| 50 | .num = BLKIOMON_SIZE_BUCKETS |
| 51 | }; |
| 52 | |
| 53 | static struct histlog2 d2c_hist = { |
| 54 | .first = 0, |
| 55 | .delta = 8, |
| 56 | .num = BLKIOMON_D2C_BUCKETS |
| 57 | }; |
| 58 | |
| 59 | static inline void blkiomon_stat_init(struct blkiomon_stat *bstat) |
| 60 | { |
| 61 | memset(bstat, 0, sizeof(*bstat)); |
| 62 | minmax_init(&bstat->size_r); |
| 63 | minmax_init(&bstat->size_w); |
| 64 | minmax_init(&bstat->d2c_r); |
| 65 | minmax_init(&bstat->d2c_w); |
| 66 | minmax_init(&bstat->thrput_r); |
| 67 | minmax_init(&bstat->thrput_w); |
| 68 | } |
| 69 | |
| 70 | static inline void blkiomon_stat_to_be(struct blkiomon_stat *bstat) |
| 71 | { |
| 72 | histlog2_to_be(bstat->size_hist, &size_hist); |
| 73 | histlog2_to_be(bstat->d2c_hist, &d2c_hist); |
| 74 | minmax_to_be(&bstat->size_r); |
| 75 | minmax_to_be(&bstat->size_w); |
| 76 | minmax_to_be(&bstat->d2c_r); |
| 77 | minmax_to_be(&bstat->d2c_w); |
| 78 | minmax_to_be(&bstat->thrput_r); |
| 79 | minmax_to_be(&bstat->thrput_w); |
| 80 | bstat->bidir = cpu_to_be64(bstat->bidir); |
| 81 | bstat->time = cpu_to_be64(bstat->time); |
| 82 | bstat->device = cpu_to_be32(bstat->device); |
| 83 | } |
| 84 | |
| 85 | static inline void blkiomon_stat_merge(struct blkiomon_stat *dst, |
| 86 | struct blkiomon_stat *src) |
| 87 | { |
| 88 | histlog2_merge(&size_hist, dst->size_hist, src->size_hist); |
| 89 | histlog2_merge(&d2c_hist, dst->d2c_hist, src->d2c_hist); |
| 90 | minmax_merge(&dst->size_r, &src->size_r); |
| 91 | minmax_merge(&dst->size_w, &src->size_w); |
| 92 | minmax_merge(&dst->d2c_r, &src->d2c_r); |
| 93 | minmax_merge(&dst->d2c_w, &src->d2c_w); |
| 94 | minmax_merge(&dst->thrput_r, &src->thrput_r); |
| 95 | minmax_merge(&dst->thrput_w, &src->thrput_w); |
| 96 | dst->bidir += src->bidir; |
| 97 | } |
| 98 | |
| 99 | static inline void blkiomon_stat_print(FILE *fp, struct blkiomon_stat *p) |
| 100 | { |
| 101 | if (!fp) |
| 102 | return; |
| 103 | |
| 104 | fprintf(fp, "\ntime: %s", ctime((void *)&p->time)); |
| 105 | fprintf(fp, "device: %d,%d\n", MAJOR(p->device), MINOR(p->device)); |
| 106 | minmax_print(fp, "sizes read (bytes)", &p->size_r); |
| 107 | minmax_print(fp, "sizes write (bytes)", &p->size_w); |
| 108 | minmax_print(fp, "d2c read (usec)", &p->d2c_r); |
| 109 | minmax_print(fp, "d2c write (usec)", &p->d2c_w); |
| 110 | minmax_print(fp, "throughput read (bytes/msec)", &p->thrput_r); |
| 111 | minmax_print(fp, "throughput write (bytes/msec)", &p->thrput_w); |
| 112 | histlog2_print(fp, "sizes histogram (bytes)", p->size_hist, &size_hist); |
| 113 | histlog2_print(fp, "d2c histogram (usec)", p->d2c_hist, &d2c_hist); |
| 114 | fprintf(fp, "bidirectional requests: %ld\n", (unsigned long)p->bidir); |
| 115 | } |
| 116 | |
| 117 | #endif |