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