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 42 static void loaddelay(struct timespec *ts, const char *arg); 43 44 void 45 hammer_cmd_bstats(char **av, int ac) 46 { 47 struct libhammer_btree_stats bs, bsc; 48 struct timespec delay = { 1, 0 }; 49 int count; 50 51 if (ac > 0) 52 loaddelay(&delay, av[0]); 53 54 bzero(&bsc, sizeof(bsc)); 55 for (count = 0; ; ++count) { 56 if (libhammer_btree_stats(&bs) < 0) 57 err(1, "Failed to get information from HAMMER sysctls"); 58 if (count) { 59 if ((count & 15) == 1) 60 printf(" elements iterations lookups " 61 "inserts deletes splits\n"); 62 printf("%10jd %10jd %10jd %10jd %10jd %10jd\n", 63 (intmax_t)(bs.elements - bsc.elements), 64 (intmax_t)(bs.iterations - bsc.iterations), 65 (intmax_t)(bs.lookups - bsc.lookups), 66 (intmax_t)(bs.inserts - bsc.inserts), 67 (intmax_t)(bs.deletes - bsc.deletes), 68 (intmax_t)(bs.splits - bsc.splits)); 69 } 70 bcopy(&bs, &bsc, sizeof(bs)); 71 nanosleep(&delay, NULL); 72 } 73 } 74 75 void 76 hammer_cmd_iostats(char **av, int ac) 77 { 78 struct libhammer_io_stats ios, iosc; 79 struct timespec delay = { 1, 0 }; 80 int64_t tiops = 0; 81 int count; 82 83 if (ac > 0) 84 loaddelay(&delay, av[0]); 85 86 bzero(&iosc, sizeof(iosc)); 87 for (count = 0; ; ++count) { 88 if (libhammer_io_stats(&ios) < 0) 89 err(1, "Failed to get information from HAMMER sysctls"); 90 tiops = (ios.file_iop_writes + ios.file_iop_reads) - 91 (iosc.file_iop_writes + iosc.file_iop_reads); 92 if (count) { 93 if ((count & 15) == 1) 94 printf(" file-rd file-wr dev-read dev-write" 95 " inode_ops ino_flush commit undo\n"); 96 printf("%9jd %9jd %9jd %9jd %9jd %9jd %9jd %9jd\n", 97 (intmax_t)(ios.file_reads - iosc.file_reads), 98 (intmax_t)(ios.file_writes - iosc.file_writes), 99 (intmax_t)(ios.dev_reads - iosc.dev_reads), 100 (intmax_t)(ios.dev_writes - iosc.dev_writes), 101 (intmax_t)tiops, 102 (intmax_t)(ios.inode_flushes - iosc.inode_flushes), 103 (intmax_t)(ios.commits - iosc.commits), 104 (intmax_t)(ios.undo - iosc.undo)); 105 } 106 nanosleep(&delay, NULL); 107 bcopy(&ios, &iosc, sizeof(ios)); 108 } 109 } 110 111 /* 112 * Convert a delay string (e.g. "0.1") into a timespec. 113 */ 114 static 115 void 116 loaddelay(struct timespec *ts, const char *arg) 117 { 118 double d; 119 120 d = strtod(arg, NULL); 121 if (d < 0.001) 122 d = 0.001; 123 ts->tv_sec = (int)d; 124 ts->tv_nsec = (int)(modf(d, &d) * 1000000000.0); 125 } 126