throughput.c (36934) | throughput.c (46686) |
---|---|
1/*- 2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $Id: throughput.c,v 1.7 1998/06/12 17:45:41 brian Exp $ | 26 * $Id: throughput.c,v 1.8 1998/06/12 20:12:26 brian Exp $ |
27 */ 28 29#include <sys/types.h> 30 31#include <stdio.h> 32#include <string.h> 33#include <termios.h> 34#include <time.h> --- 25 unchanged lines hidden (view full) --- 60throughput_disp(struct pppThroughput *t, struct prompt *prompt) 61{ 62 int secs_up; 63 64 secs_up = t->uptime ? time(NULL) - t->uptime : 0; 65 prompt_Printf(prompt, "Connect time: %d secs\n", secs_up); 66 if (secs_up == 0) 67 secs_up = 1; | 27 */ 28 29#include <sys/types.h> 30 31#include <stdio.h> 32#include <string.h> 33#include <termios.h> 34#include <time.h> --- 25 unchanged lines hidden (view full) --- 60throughput_disp(struct pppThroughput *t, struct prompt *prompt) 61{ 62 int secs_up; 63 64 secs_up = t->uptime ? time(NULL) - t->uptime : 0; 65 prompt_Printf(prompt, "Connect time: %d secs\n", secs_up); 66 if (secs_up == 0) 67 secs_up = 1; |
68 prompt_Printf(prompt, "%ld octets in, %ld octets out\n", | 68 prompt_Printf(prompt, "%qu octets in, %qu octets out\n", |
69 t->OctetsIn, t->OctetsOut); 70 if (t->rolling) { | 69 t->OctetsIn, t->OctetsOut); 70 if (t->rolling) { |
71 prompt_Printf(prompt, " overall %5ld bytes/sec\n", | 71 prompt_Printf(prompt, " overall %6qu bytes/sec\n", |
72 (t->OctetsIn+t->OctetsOut)/secs_up); | 72 (t->OctetsIn+t->OctetsOut)/secs_up); |
73 prompt_Printf(prompt, " currently %5d bytes/sec\n", t->OctetsPerSecond); 74 prompt_Printf(prompt, " peak %5d bytes/sec on %s", | 73 prompt_Printf(prompt, " currently %6qu bytes/sec\n", t->OctetsPerSecond); 74 prompt_Printf(prompt, " peak %6qu bytes/sec on %s", |
75 t->BestOctetsPerSecond, ctime(&t->BestOctetsPerSecondTime)); 76 } else | 75 t->BestOctetsPerSecond, ctime(&t->BestOctetsPerSecondTime)); 76 } else |
77 prompt_Printf(prompt, "Overall %ld bytes/sec\n", | 77 prompt_Printf(prompt, "Overall %qu bytes/sec\n", |
78 (t->OctetsIn+t->OctetsOut)/secs_up); 79} 80 81 82void 83throughput_log(struct pppThroughput *t, int level, const char *title) 84{ 85 if (t->uptime) { 86 int secs_up; 87 88 secs_up = t->uptime ? time(NULL) - t->uptime : 0; 89 if (title) | 78 (t->OctetsIn+t->OctetsOut)/secs_up); 79} 80 81 82void 83throughput_log(struct pppThroughput *t, int level, const char *title) 84{ 85 if (t->uptime) { 86 int secs_up; 87 88 secs_up = t->uptime ? time(NULL) - t->uptime : 0; 89 if (title) |
90 log_Printf(level, "%s: Connect time: %d secs: %ld octets in, %ld octets" | 90 log_Printf(level, "%s: Connect time: %d secs: %qu octets in, %qu octets" |
91 " out\n", title, secs_up, t->OctetsIn, t->OctetsOut); 92 else | 91 " out\n", title, secs_up, t->OctetsIn, t->OctetsOut); 92 else |
93 log_Printf(level, "Connect time: %d secs: %ld octets in, %ld octets out\n", | 93 log_Printf(level, "Connect time: %d secs: %qu octets in, %qu octets out\n", |
94 secs_up, t->OctetsIn, t->OctetsOut); 95 if (secs_up == 0) 96 secs_up = 1; 97 if (t->rolling) | 94 secs_up, t->OctetsIn, t->OctetsOut); 95 if (secs_up == 0) 96 secs_up = 1; 97 if (t->rolling) |
98 log_Printf(level, " total %ld bytes/sec, peak %d bytes/sec on %s", | 98 log_Printf(level, " total %qu bytes/sec, peak %qu bytes/sec on %s", |
99 (t->OctetsIn+t->OctetsOut)/secs_up, t->BestOctetsPerSecond, 100 ctime(&t->BestOctetsPerSecondTime)); 101 else | 99 (t->OctetsIn+t->OctetsOut)/secs_up, t->BestOctetsPerSecond, 100 ctime(&t->BestOctetsPerSecondTime)); 101 else |
102 log_Printf(level, " total %ld bytes/sec\n", | 102 log_Printf(level, " total %qu bytes/sec\n", |
103 (t->OctetsIn+t->OctetsOut)/secs_up); 104 } 105} 106 107static void 108throughput_sampler(void *v) 109{ 110 struct pppThroughput *t = (struct pppThroughput *)v; | 103 (t->OctetsIn+t->OctetsOut)/secs_up); 104 } 105} 106 107static void 108throughput_sampler(void *v) 109{ 110 struct pppThroughput *t = (struct pppThroughput *)v; |
111 u_long old; | 111 unsigned long long old; |
112 113 timer_Stop(&t->Timer); 114 115 old = t->SampleOctets[t->nSample]; 116 t->SampleOctets[t->nSample] = t->OctetsIn + t->OctetsOut; 117 t->OctetsPerSecond = (t->SampleOctets[t->nSample] - old) / SAMPLE_PERIOD; 118 if (t->BestOctetsPerSecond < t->OctetsPerSecond) { 119 t->BestOctetsPerSecond = t->OctetsPerSecond; --- 23 unchanged lines hidden (view full) --- 143 144void 145throughput_stop(struct pppThroughput *t) 146{ 147 timer_Stop(&t->Timer); 148} 149 150void | 112 113 timer_Stop(&t->Timer); 114 115 old = t->SampleOctets[t->nSample]; 116 t->SampleOctets[t->nSample] = t->OctetsIn + t->OctetsOut; 117 t->OctetsPerSecond = (t->SampleOctets[t->nSample] - old) / SAMPLE_PERIOD; 118 if (t->BestOctetsPerSecond < t->OctetsPerSecond) { 119 t->BestOctetsPerSecond = t->OctetsPerSecond; --- 23 unchanged lines hidden (view full) --- 143 144void 145throughput_stop(struct pppThroughput *t) 146{ 147 timer_Stop(&t->Timer); 148} 149 150void |
151throughput_addin(struct pppThroughput *t, int n) | 151throughput_addin(struct pppThroughput *t, long long n) |
152{ 153 t->OctetsIn += n; 154} 155 156void | 152{ 153 t->OctetsIn += n; 154} 155 156void |
157throughput_addout(struct pppThroughput *t, int n) | 157throughput_addout(struct pppThroughput *t, long long n) |
158{ 159 t->OctetsOut += n; 160} 161 162void 163throughput_clear(struct pppThroughput *t, int clear_type, struct prompt *prompt) 164{ 165 if (clear_type & (THROUGHPUT_OVERALL|THROUGHPUT_CURRENT)) { 166 int i; 167 168 for (i = 0; i < SAMPLE_PERIOD; i++) 169 t->SampleOctets[i] = 0; 170 t->nSample = 0; 171 } 172 173 if (clear_type & THROUGHPUT_OVERALL) { 174 int secs_up; 175 176 secs_up = t->uptime ? time(NULL) - t->uptime : 1; | 158{ 159 t->OctetsOut += n; 160} 161 162void 163throughput_clear(struct pppThroughput *t, int clear_type, struct prompt *prompt) 164{ 165 if (clear_type & (THROUGHPUT_OVERALL|THROUGHPUT_CURRENT)) { 166 int i; 167 168 for (i = 0; i < SAMPLE_PERIOD; i++) 169 t->SampleOctets[i] = 0; 170 t->nSample = 0; 171 } 172 173 if (clear_type & THROUGHPUT_OVERALL) { 174 int secs_up; 175 176 secs_up = t->uptime ? time(NULL) - t->uptime : 1; |
177 prompt_Printf(prompt, "overall cleared (was %5ld bytes/sec)\n", | 177 prompt_Printf(prompt, "overall cleared (was %6qu bytes/sec)\n", |
178 (t->OctetsIn + t->OctetsOut)/secs_up); 179 t->OctetsIn = t->OctetsOut = 0; 180 t->uptime = time(NULL); 181 } 182 183 if (clear_type & THROUGHPUT_CURRENT) { | 178 (t->OctetsIn + t->OctetsOut)/secs_up); 179 t->OctetsIn = t->OctetsOut = 0; 180 t->uptime = time(NULL); 181 } 182 183 if (clear_type & THROUGHPUT_CURRENT) { |
184 prompt_Printf(prompt, "current cleared (was %5d bytes/sec)\n", | 184 prompt_Printf(prompt, "current cleared (was %6qu bytes/sec)\n", |
185 t->OctetsPerSecond); 186 t->OctetsPerSecond = 0; 187 } 188 189 if (clear_type & THROUGHPUT_PEAK) { 190 char *time_buf, *last; 191 192 time_buf = ctime(&t->BestOctetsPerSecondTime); 193 last = time_buf + strlen(time_buf); 194 if (last > time_buf && *--last == '\n') 195 *last = '\0'; | 185 t->OctetsPerSecond); 186 t->OctetsPerSecond = 0; 187 } 188 189 if (clear_type & THROUGHPUT_PEAK) { 190 char *time_buf, *last; 191 192 time_buf = ctime(&t->BestOctetsPerSecondTime); 193 last = time_buf + strlen(time_buf); 194 if (last > time_buf && *--last == '\n') 195 *last = '\0'; |
196 prompt_Printf(prompt, "peak cleared (was %5d bytes/sec on %s)\n", | 196 prompt_Printf(prompt, "peak cleared (was %6qu bytes/sec on %s)\n", |
197 t->BestOctetsPerSecond, time_buf); 198 t->BestOctetsPerSecond = 0; 199 t->BestOctetsPerSecondTime = time(NULL); 200 } 201} | 197 t->BestOctetsPerSecond, time_buf); 198 t->BestOctetsPerSecond = 0; 199 t->BestOctetsPerSecondTime = time(NULL); 200 } 201} |