2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/hammer/cmd_stats.c,v 1.3 2008/07/14 20:28:07 dillon Exp $
41 static void loaddelay(struct timespec *ts, const char *arg);
43 #define bstats_title \
44 " elements iterations lookups inserts deletes splits"
45 #define iostats_title \
46 " file-rd file-wr dev-read dev-write ino_rops ino_wops ino_flush commit undo"
50 print_bstats(const struct libhammer_btree_stats *p1,
51 const struct libhammer_btree_stats *p2)
53 printf("%10jd %10jd %10jd %10jd %10jd %10jd",
54 (intmax_t)(p1->elements - p2->elements),
55 (intmax_t)(p1->iterations - p2->iterations),
56 (intmax_t)(p1->lookups - p2->lookups),
57 (intmax_t)(p1->inserts - p2->inserts),
58 (intmax_t)(p1->deletes - p2->deletes),
59 (intmax_t)(p1->splits - p2->splits));
65 print_iostats(const struct libhammer_io_stats *p1,
66 const struct libhammer_io_stats *p2)
68 printf("%9jd %9jd %9jd %9jd %9jd %9jd %9jd %9jd %9jd",
69 (intmax_t)(p1->file_reads - p2->file_reads),
70 (intmax_t)(p1->file_writes - p2->file_writes),
71 (intmax_t)(p1->dev_reads - p2->dev_reads),
72 (intmax_t)(p1->dev_writes - p2->dev_writes),
73 (intmax_t)(p1->file_iop_reads - p2->file_iop_reads),
74 (intmax_t)(p1->file_iop_writes - p2->file_iop_writes),
75 (intmax_t)(p1->inode_flushes - p2->inode_flushes),
76 (intmax_t)(p1->commits - p2->commits),
77 (intmax_t)(p1->undo - p2->undo));
82 hammer_cmd_bstats(char **av, int ac)
84 struct libhammer_btree_stats bs, bsc;
85 struct timespec delay = { 1, 0 };
89 loaddelay(&delay, av[0]);
91 bzero(&bsc, sizeof(bsc));
92 for (count = 0; ; ++count) {
93 if (libhammer_btree_stats(&bs) < 0)
94 err(1, "Failed to get information from HAMMER sysctls");
96 if ((count & 15) == 1)
97 printf(bstats_title"\n");
98 print_bstats(&bs, &bsc);
101 bcopy(&bs, &bsc, sizeof(bs));
102 nanosleep(&delay, NULL);
107 hammer_cmd_iostats(char **av, int ac)
109 struct libhammer_io_stats ios, iosc;
110 struct timespec delay = { 1, 0 };
114 loaddelay(&delay, av[0]);
116 bzero(&iosc, sizeof(iosc));
117 for (count = 0; ; ++count) {
118 if (libhammer_io_stats(&ios) < 0)
119 err(1, "Failed to get information from HAMMER sysctls");
121 if ((count & 15) == 1)
122 printf(iostats_title"\n");
123 print_iostats(&ios, &iosc);
126 nanosleep(&delay, NULL);
127 bcopy(&ios, &iosc, sizeof(ios));
132 hammer_cmd_stats(char **av, int ac)
134 struct libhammer_btree_stats bs, bsc;
135 struct libhammer_io_stats ios, iosc;
136 struct timespec delay = { 1, 0 };
140 loaddelay(&delay, av[0]);
142 bzero(&bsc, sizeof(bsc));
143 bzero(&iosc, sizeof(iosc));
145 for (count = 0; ; ++count) {
146 if (libhammer_btree_stats(&bs) || libhammer_io_stats(&ios))
147 err(1, "Failed to get information from HAMMER sysctls");
149 if ((count & 15) == 1) {
150 printf(bstats_title"\t"iostats_title"\n");
152 print_bstats(&bs, &bsc);
154 print_iostats(&ios, &iosc);
157 bcopy(&bs, &bsc, sizeof(bs));
158 bcopy(&ios, &iosc, sizeof(ios));
159 nanosleep(&delay, NULL);
164 * Convert a delay string (e.g. "0.1") into a timespec.
168 loaddelay(struct timespec *ts, const char *arg)
172 d = strtod(arg, NULL);
176 ts->tv_nsec = (int)(modf(d, &d) * 1000000000.0);