/* * Copyright (c) 2008 The DragonFly Project. All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $DragonFly: src/sbin/hammer/cmd_stats.c,v 1.3 2008/07/14 20:28:07 dillon Exp $ */ #include #include "hammer.h" static void loaddelay(struct timespec *ts, const char *arg); #define bstats_title \ " elements iterations lookups inserts deletes splits" #define iostats_title \ " file-rd file-wr dev-read dev-write ino_rops ino_wops ino_flush commit undo" static __inline void print_bstats(const struct libhammer_btree_stats *p1, const struct libhammer_btree_stats *p2) { printf("%10jd %10jd %10jd %10jd %10jd %10jd", (intmax_t)(p1->elements - p2->elements), (intmax_t)(p1->iterations - p2->iterations), (intmax_t)(p1->lookups - p2->lookups), (intmax_t)(p1->inserts - p2->inserts), (intmax_t)(p1->deletes - p2->deletes), (intmax_t)(p1->splits - p2->splits)); /* no trailing \n */ } static __inline void print_iostats(const struct libhammer_io_stats *p1, const struct libhammer_io_stats *p2) { printf("%9jd %9jd %9jd %9jd %9jd %9jd %9jd %9jd %9jd", (intmax_t)(p1->file_reads - p2->file_reads), (intmax_t)(p1->file_writes - p2->file_writes), (intmax_t)(p1->dev_reads - p2->dev_reads), (intmax_t)(p1->dev_writes - p2->dev_writes), (intmax_t)(p1->file_iop_reads - p2->file_iop_reads), (intmax_t)(p1->file_iop_writes - p2->file_iop_writes), (intmax_t)(p1->inode_flushes - p2->inode_flushes), (intmax_t)(p1->commits - p2->commits), (intmax_t)(p1->undo - p2->undo)); /* no trailing \n */ } void hammer_cmd_bstats(char **av, int ac) { struct libhammer_btree_stats bs, bsc; struct timespec delay = { 1, 0 }; int count; if (ac > 0) loaddelay(&delay, av[0]); bzero(&bsc, sizeof(bsc)); for (count = 0; ; ++count) { if (libhammer_btree_stats(&bs) < 0) err(1, "Failed to get information from HAMMER sysctls"); if (count) { if ((count & 15) == 1) printf(bstats_title"\n"); print_bstats(&bs, &bsc); printf("\n"); } bcopy(&bs, &bsc, sizeof(bs)); nanosleep(&delay, NULL); } } void hammer_cmd_iostats(char **av, int ac) { struct libhammer_io_stats ios, iosc; struct timespec delay = { 1, 0 }; int count; if (ac > 0) loaddelay(&delay, av[0]); bzero(&iosc, sizeof(iosc)); for (count = 0; ; ++count) { if (libhammer_io_stats(&ios) < 0) err(1, "Failed to get information from HAMMER sysctls"); if (count) { if ((count & 15) == 1) printf(iostats_title"\n"); print_iostats(&ios, &iosc); printf("\n"); } nanosleep(&delay, NULL); bcopy(&ios, &iosc, sizeof(ios)); } } void hammer_cmd_stats(char **av, int ac) { struct libhammer_btree_stats bs, bsc; struct libhammer_io_stats ios, iosc; struct timespec delay = { 1, 0 }; int count; if (ac > 0) loaddelay(&delay, av[0]); bzero(&bsc, sizeof(bsc)); bzero(&iosc, sizeof(iosc)); for (count = 0; ; ++count) { if (libhammer_btree_stats(&bs) || libhammer_io_stats(&ios)) err(1, "Failed to get information from HAMMER sysctls"); if (count) { if ((count & 15) == 1) { printf(bstats_title"\t"iostats_title"\n"); } print_bstats(&bs, &bsc); printf("\t"); print_iostats(&ios, &iosc); printf("\n"); } bcopy(&bs, &bsc, sizeof(bs)); bcopy(&ios, &iosc, sizeof(ios)); nanosleep(&delay, NULL); } } /* * Convert a delay string (e.g. "0.1") into a timespec. */ static void loaddelay(struct timespec *ts, const char *arg) { double d; d = strtod(arg, NULL); if (d < 0.001) d = 0.001; ts->tv_sec = (int)d; ts->tv_nsec = (int)(modf(d, &d) * 1000000000.0); }