netinet{,6}: Assert in{,6}_inithead() are only used for system routing tables.
[dragonfly.git] / sbin / hammer / cmd_stats.c
1 /*
2  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
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
16  *    distribution.
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.
20  *
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
32  * SUCH DAMAGE.
33  *
34  * $DragonFly: src/sbin/hammer/cmd_stats.c,v 1.3 2008/07/14 20:28:07 dillon Exp $
35  */
36
37 #include <math.h>
38
39 #include "hammer.h"
40
41 static void loaddelay(struct timespec *ts, const char *arg);
42
43 void
44 hammer_cmd_bstats(char **av, int ac)
45 {
46         struct libhammer_btree_stats bs, bsc;
47         struct timespec delay = { 1, 0 };
48         int count;
49
50         if (ac > 0)
51                 loaddelay(&delay, av[0]);
52
53         bzero(&bsc, sizeof(bsc));
54         for (count = 0; ; ++count) {
55                 if (libhammer_btree_stats(&bs) < 0)
56                         err(1, "Failed to get information from HAMMER sysctls");
57                 if (count) {
58                         if ((count & 15) == 1)
59                                 printf("  elements iterations    lookups    "
60                                     "inserts    deletes     splits\n");
61                         printf("%10jd %10jd %10jd %10jd %10jd %10jd\n",
62                             (intmax_t)(bs.elements - bsc.elements),
63                             (intmax_t)(bs.iterations - bsc.iterations),
64                             (intmax_t)(bs.lookups - bsc.lookups),
65                             (intmax_t)(bs.inserts - bsc.inserts),
66                             (intmax_t)(bs.deletes - bsc.deletes),
67                             (intmax_t)(bs.splits - bsc.splits));
68                 }
69                 bcopy(&bs, &bsc, sizeof(bs));
70                 nanosleep(&delay, NULL);
71         }
72 }
73
74 void
75 hammer_cmd_iostats(char **av, int ac)
76 {
77         struct libhammer_io_stats ios, iosc;
78         struct timespec delay = { 1, 0 };
79         int64_t tiops = 0;
80         int count;
81
82         if (ac > 0)
83                 loaddelay(&delay, av[0]);
84
85         bzero(&iosc, sizeof(iosc));
86         for (count = 0; ; ++count) {
87                 if (libhammer_io_stats(&ios) < 0)
88                         err(1, "Failed to get information from HAMMER sysctls");
89                 tiops = (ios.file_iop_writes + ios.file_iop_reads) -
90                     (iosc.file_iop_writes + iosc.file_iop_reads);
91                 if (count) {
92                         if ((count & 15) == 1)
93                                 printf("  file-rd   file-wr  dev-read dev-write"
94                                     " inode_ops ino_flush    commit      undo\n");
95                         printf("%9jd %9jd %9jd %9jd %9jd %9jd %9jd %9jd\n",
96                             (intmax_t)(ios.file_reads - iosc.file_reads),
97                             (intmax_t)(ios.file_writes - iosc.file_writes),
98                             (intmax_t)(ios.dev_reads - iosc.dev_reads),
99                             (intmax_t)(ios.dev_writes - iosc.dev_writes),
100                             (intmax_t)tiops,
101                             (intmax_t)(ios.inode_flushes - iosc.inode_flushes),
102                             (intmax_t)(ios.commits - iosc.commits),
103                             (intmax_t)(ios.undo - iosc.undo));
104                 }
105                 nanosleep(&delay, NULL);
106                 bcopy(&ios, &iosc, sizeof(ios));
107         }
108 }
109
110 /*
111  * Convert a delay string (e.g. "0.1") into a timespec.
112  */
113 static
114 void
115 loaddelay(struct timespec *ts, const char *arg)
116 {
117         double d;
118
119         d = strtod(arg, NULL);
120         if (d < 0.001)
121                 d = 0.001;
122         ts->tv_sec = (int)d;
123         ts->tv_nsec = (int)(modf(d, &d) * 1000000000.0);
124 }