4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
39 #include <sys/types.h>
43 #include <libcfs/util/param.h>
50 gettimeofday (&tv, NULL);
51 return (tv.tv_sec + tv.tv_usec / 1000000.0);
55 unsigned long msgs_alloc;
56 unsigned long msgs_max;
58 unsigned long send_count;
59 unsigned long recv_count;
60 unsigned long route_count;
61 unsigned long drop_count;
62 unsigned long long send_length;
63 unsigned long long recv_length;
64 unsigned long long route_length;
65 unsigned long long drop_length;
68 unsigned long long subull(unsigned long long a, unsigned long long b)
71 return -1ULL - b + a + 1;
76 unsigned long long subul(unsigned long a, unsigned long b)
79 return -1UL - b + a + 1;
84 double rul(unsigned long a, double secs)
86 return (double)a/secs;
89 double rull(unsigned long long a, double secs)
91 return (double)a/secs;
97 static char buffer[1024];
98 static double last = 0.0;
99 static counters_t old_counter;
102 counters_t new_counter;
106 lseek (fd, 0, SEEK_SET);
108 n = read(fd, buffer, sizeof(buffer) - 1);
111 fprintf (stderr, "Can't read statfile\n");
116 n = sscanf(buffer, "%lu %lu %lu %lu %lu %lu %lu %llu %llu %llu %llu",
117 &new_counter.msgs_alloc, &new_counter.msgs_max,
119 &new_counter.send_count, &new_counter.recv_count,
120 &new_counter.route_count, &new_counter.drop_count,
121 &new_counter.send_length, &new_counter.recv_length,
122 &new_counter.route_length, &new_counter.drop_length);
125 fprintf (stderr, "Can't parse statfile\n");
130 printf("M %lu(%lu) E %lu S %llu/%lu R %llu/%lu F %llu/%lu "
132 new_counter.msgs_alloc, new_counter.msgs_max,
134 new_counter.send_length, new_counter.send_count,
135 new_counter.recv_length, new_counter.recv_count,
136 new_counter.route_length, new_counter.route_count,
137 new_counter.drop_length, new_counter.drop_count);
141 counter.msgs_alloc = new_counter.msgs_alloc;
142 counter.msgs_max = new_counter.msgs_max;
144 counter.errors = subul(new_counter.errors, old_counter.errors);
145 counter.send_count = subul(new_counter.send_count, old_counter.send_count);
146 counter.recv_count = subul(new_counter.recv_count, old_counter.recv_count);
147 counter.route_count = subul(new_counter.route_count, old_counter.route_count);
148 counter.drop_count = subul(new_counter.drop_count, old_counter.drop_count);
149 counter.send_length = subull(new_counter.send_length, old_counter.send_length);
150 counter.recv_length = subull(new_counter.recv_length, old_counter.recv_length);
151 counter.route_length = subull(new_counter.route_length, old_counter.route_length);
152 counter.drop_length = subull(new_counter.drop_length, old_counter.drop_length);
154 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",
155 counter.msgs_alloc, counter.msgs_max,
156 rul(counter.errors,t),
157 rull(counter.send_length,t*1024.0*1024.0), rul(counter.send_count, t),
158 rull(counter.recv_length,t*1024.0*1024.0), rul(counter.recv_count, t),
159 rull(counter.route_length,t*1024.0*1024.0), rul(counter.route_count, t),
160 rull(counter.drop_length,t*1024.0*1024.0), rul(counter.drop_count, t));
163 old_counter = new_counter;
166 lseek (fd, 0, SEEK_SET);
170 int main(int argc, char **argv)
177 interval = atoi(argv[1]);
179 if (cfs_get_param_paths(&path, "stats") != 0) {
180 fprintf(stderr, "LNet stats not available\n");
184 fd = open(path.gl_pathv[0], O_RDONLY);
186 fprintf(stderr, "failed to open '%s': %s\n", path.gl_pathv[0],
188 cfs_free_param_data(&path);
191 cfs_free_param_data(&path);