X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Frouterstat.c;h=b6ea9a8015394a40443c6fbb7fbcc7a9511156f2;hb=8e2f5a3a919073a91dd987e36f15678cf0cbdbc8;hp=99bc59b0e105432c5616ff7fdb5601fa3a9c8113;hpb=5a63afa17b94d652460586dc16ce0dff0165eb05;p=fs%2Flustre-release.git diff --git a/lnet/utils/routerstat.c b/lnet/utils/routerstat.c index 99bc59b..b6ea9a8 100644 --- a/lnet/utils/routerstat.c +++ b/lnet/utils/routerstat.c @@ -1,3 +1,39 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + * + * Copyright (c) 2011, Whamcloud, Inc. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + */ + #include #include #include @@ -11,27 +47,63 @@ double timenow () { struct timeval tv; - + gettimeofday (&tv, NULL); return (tv.tv_sec + tv.tv_usec / 1000000.0); } +typedef struct { + unsigned long msgs_alloc; + unsigned long msgs_max; + unsigned long errors; + unsigned long send_count; + unsigned long recv_count; + unsigned long route_count; + unsigned long drop_count; + unsigned long long send_length; + unsigned long long recv_length; + unsigned long long route_length; + unsigned long long drop_length; +} counters_t; + +unsigned long long subull(unsigned long long a, unsigned long long b) +{ + if (a < b) + return -1ULL - b + a + 1; + + return a - b; +} + +unsigned long long subul(unsigned long a, unsigned long b) +{ + if (a < b) + return -1UL - b + a + 1; + + return a - b; +} + +double rul(unsigned long a, double secs) +{ + return (double)a/secs; +} + +double rull(unsigned long long a, double secs) +{ + return (double)a/secs; +} + void do_stat (int fd) { static char buffer[1024]; static double last = 0.0; - static unsigned long long old_bytes; - static unsigned long old_packets; - static unsigned long old_errors; + static counters_t old_counter; double now; double t; - unsigned long long new_bytes, bytes; - unsigned long new_packets, packets; - unsigned long new_errors, errors; - unsigned long depth; + counters_t new_counter; + counters_t counter; int n; - + lseek (fd, 0, SEEK_SET); now = timenow(); n = read (fd, buffer, sizeof (buffer)); @@ -39,56 +111,59 @@ do_stat (int fd) { fprintf (stderr, "Can't read statfile\n"); exit (1); - } + } buffer[n] = 0; - - n = sscanf (buffer, "%Lu %lu %lu %lu", - &new_bytes, &new_packets, &new_errors, &depth); - - if (n < 3) + + n = sscanf(buffer, "%lu %lu %lu %lu %lu %lu %lu %llu %llu %llu %llu", + &new_counter.msgs_alloc, &new_counter.msgs_max, + &new_counter.errors, + &new_counter.send_count, &new_counter.recv_count, + &new_counter.route_count, &new_counter.drop_count, + &new_counter.send_length, &new_counter.recv_length, + &new_counter.route_length, &new_counter.drop_length); + if (n < 11) { fprintf (stderr, "Can't parse statfile\n"); exit (1); } - - if (last == 0.0) - printf ("%llu bytes, %lu packets (sz %lld), %lu errors", - new_bytes, new_packets, - (long long)((new_packets == 0) ? 0LL : new_bytes/new_packets), - new_errors); - else - { - t = now - last; - - if (new_bytes < old_bytes) - bytes = -1ULL - old_bytes + new_bytes + 1; - else - bytes = new_bytes - old_bytes; - if (new_packets < old_packets) - packets = -1UL - old_packets + new_packets + 1; - else - packets = new_packets - old_packets; - if (new_errors < old_errors) - errors = -1UL - old_errors + new_errors + 1; - else - errors = new_errors - old_errors; - - printf ("%9llu bytes (%7.2fMb/s), %7lu packets (sz %5lld, %5ld/s), %lu errors (%ld/s)", - bytes, ((double)bytes)/((1<<20) * t), - packets, (long long)((packets == 0) ? 0LL : bytes/packets), (long)(packets/t), - errors, (long)(errors/t)); - } - old_bytes = new_bytes; - old_packets = new_packets; - old_errors = new_errors; - if (n == 4) - printf (", depth (%ld)\n", depth); - else - printf ("\n"); + if (last == 0.0) { + printf("M %lu(%lu) E %lu S %llu/%lu R %llu/%lu F %llu/%lu " + "D %llu/%lu\n", + new_counter.msgs_alloc, new_counter.msgs_max, + new_counter.errors, + new_counter.send_length, new_counter.send_count, + new_counter.recv_length, new_counter.recv_count, + new_counter.route_length, new_counter.route_count, + new_counter.drop_length, new_counter.drop_count); + } else { + t = now - last; + + counter.msgs_alloc = new_counter.msgs_alloc; + counter.msgs_max = new_counter.msgs_max; + counter.errors = subul(new_counter.errors, old_counter.errors); + counter.send_count = subul(new_counter.send_count, old_counter.send_count); + counter.recv_count = subul(new_counter.recv_count, old_counter.recv_count); + counter.route_count = subul(new_counter.route_count, old_counter.route_count); + counter.drop_count = subul(new_counter.drop_count, old_counter.drop_count); + counter.send_length = subull(new_counter.send_length, old_counter.send_length); + counter.recv_length = subull(new_counter.recv_length, old_counter.recv_length); + counter.route_length = subull(new_counter.route_length, old_counter.route_length); + counter.drop_length = subull(new_counter.drop_length, old_counter.drop_length); + + printf ("M %3lu(%3lu) E %0.0f S %7.2f/%6.0f R %7.2f/%6.0f F %7.2f/%6.0f D %4.2f/%0.0f\n", + counter.msgs_alloc, counter.msgs_max, + rul(counter.errors,t), + rull(counter.send_length,t*1024.0*1024.0), rul(counter.send_count, t), + rull(counter.recv_length,t*1024.0*1024.0), rul(counter.recv_count, t), + rull(counter.route_length,t*1024.0*1024.0), rul(counter.route_count, t), + rull(counter.drop_length,t*1024.0*1024.0), rul(counter.drop_count, t)); + } + + old_counter = new_counter; fflush (stdout); - + lseek (fd, 0, SEEK_SET); last = timenow(); } @@ -97,21 +172,21 @@ int main (int argc, char **argv) { int interval = 0; int fd; - + if (argc > 1) interval = atoi (argv[1]); - fd = open ("/proc/sys/portals/router", O_RDONLY); + fd = open ("/proc/sys/lnet/stats", O_RDONLY); if (fd < 0) { fprintf (stderr, "Can't open stat: %s\n", strerror (errno)); return (1); } - + do_stat (fd); if (interval == 0) return (0); - + for (;;) { sleep (interval);