Lines Matching refs:t
46 throughput_init(struct pppThroughput *t, int period) in throughput_init() argument
48 t->OctetsIn = t->OctetsOut = t->PacketsIn = t->PacketsOut = 0; in throughput_init()
49 t->SamplePeriod = period; in throughput_init()
50 t->in.SampleOctets = (long long *) in throughput_init()
51 calloc(period, sizeof *t->in.SampleOctets); in throughput_init()
52 t->in.OctetsPerSecond = 0; in throughput_init()
53 t->out.SampleOctets = (long long *) in throughput_init()
54 calloc(period, sizeof *t->out.SampleOctets); in throughput_init()
55 t->out.OctetsPerSecond = 0; in throughput_init()
56 t->BestOctetsPerSecond = 0; in throughput_init()
57 t->nSample = 0; in throughput_init()
58 time(&t->BestOctetsPerSecondTime); in throughput_init()
59 memset(&t->Timer, '\0', sizeof t->Timer); in throughput_init()
60 t->Timer.name = "throughput"; in throughput_init()
61 t->uptime = 0; in throughput_init()
62 t->downtime = 0; in throughput_init()
63 t->rolling = 0; in throughput_init()
64 t->callback.data = NULL; in throughput_init()
65 t->callback.fn = NULL; in throughput_init()
66 throughput_stop(t); in throughput_init()
70 throughput_destroy(struct pppThroughput *t) in throughput_destroy() argument
72 if (t && t->in.SampleOctets) { in throughput_destroy()
73 throughput_stop(t); in throughput_destroy()
74 free(t->in.SampleOctets); in throughput_destroy()
75 free(t->out.SampleOctets); in throughput_destroy()
76 t->in.SampleOctets = NULL; in throughput_destroy()
77 t->out.SampleOctets = NULL; in throughput_destroy()
82 throughput_uptime(struct pppThroughput *t) in throughput_uptime() argument
86 downat = t->downtime ? t->downtime : time(NULL); in throughput_uptime()
87 if (t->uptime && downat < t->uptime) { in throughput_uptime()
91 for (i = 0; i < t->SamplePeriod; i++) in throughput_uptime()
92 t->in.SampleOctets[i] = t->out.SampleOctets[i] = 0; in throughput_uptime()
93 t->nSample = 0; in throughput_uptime()
94 t->uptime = downat; in throughput_uptime()
96 return t->uptime ? downat - t->uptime : 0; in throughput_uptime()
100 throughput_disp(struct pppThroughput *t, struct prompt *prompt) in throughput_disp() argument
104 secs_up = throughput_uptime(t); in throughput_disp()
107 if (t->downtime) in throughput_disp()
108 prompt_Printf(prompt, " - down at %s", ctime(&t->downtime)); in throughput_disp()
114 t->OctetsIn, t->OctetsOut); in throughput_disp()
116 t->PacketsIn, t->PacketsOut); in throughput_disp()
117 if (t->rolling) { in throughput_disp()
119 (t->OctetsIn + t->OctetsOut) / divisor); in throughput_disp()
122 t->downtime ? "average " : "currently", in throughput_disp()
123 t->in.OctetsPerSecond, t->out.OctetsPerSecond, in throughput_disp()
124 secs_up > t->SamplePeriod ? t->SamplePeriod : secs_up); in throughput_disp()
126 t->BestOctetsPerSecond, ctime(&t->BestOctetsPerSecondTime)); in throughput_disp()
129 (t->OctetsIn + t->OctetsOut) / divisor); in throughput_disp()
134 throughput_log(struct pppThroughput *t, int level, const char *title) in throughput_log() argument
136 if (t->uptime) { in throughput_log()
139 secs_up = throughput_uptime(t); in throughput_log()
143 " out\n", title, *title ? ": " : "", secs_up, t->OctetsIn, in throughput_log()
144 t->OctetsOut); in throughput_log()
146 title, *title ? ": " : "", t->PacketsIn, t->PacketsOut); in throughput_log()
149 if (t->rolling) in throughput_log()
151 (t->OctetsIn + t->OctetsOut) / secs_up, t->BestOctetsPerSecond, in throughput_log()
152 ctime(&t->BestOctetsPerSecondTime)); in throughput_log()
155 (t->OctetsIn + t->OctetsOut) / secs_up); in throughput_log()
162 struct pppThroughput *t = (struct pppThroughput *)v; in throughput_sampler() local
167 timer_Stop(&t->Timer); in throughput_sampler()
169 uptime = throughput_uptime(t); in throughput_sampler()
170 divisor = uptime < t->SamplePeriod ? uptime + 1 : t->SamplePeriod; in throughput_sampler()
172 old = t->in.SampleOctets[t->nSample]; in throughput_sampler()
173 t->in.SampleOctets[t->nSample] = t->OctetsIn; in throughput_sampler()
174 t->in.OctetsPerSecond = (t->in.SampleOctets[t->nSample] - old) / divisor; in throughput_sampler()
176 old = t->out.SampleOctets[t->nSample]; in throughput_sampler()
177 t->out.SampleOctets[t->nSample] = t->OctetsOut; in throughput_sampler()
178 t->out.OctetsPerSecond = (t->out.SampleOctets[t->nSample] - old) / divisor; in throughput_sampler()
180 octets = t->in.OctetsPerSecond + t->out.OctetsPerSecond; in throughput_sampler()
181 if (t->BestOctetsPerSecond < octets) { in throughput_sampler()
182 t->BestOctetsPerSecond = octets; in throughput_sampler()
183 time(&t->BestOctetsPerSecondTime); in throughput_sampler()
186 if (++t->nSample == t->SamplePeriod) in throughput_sampler()
187 t->nSample = 0; in throughput_sampler()
189 if (t->callback.fn != NULL && uptime >= t->SamplePeriod) in throughput_sampler()
190 (*t->callback.fn)(t->callback.data); in throughput_sampler()
192 timer_Start(&t->Timer); in throughput_sampler()
196 throughput_start(struct pppThroughput *t, const char *name, int rolling) in throughput_start() argument
199 timer_Stop(&t->Timer); in throughput_start()
201 for (i = 0; i < t->SamplePeriod; i++) in throughput_start()
202 t->in.SampleOctets[i] = t->out.SampleOctets[i] = 0; in throughput_start()
203 t->nSample = 0; in throughput_start()
204 t->OctetsIn = t->OctetsOut = t->PacketsIn = t->PacketsOut = 0; in throughput_start()
205 t->in.OctetsPerSecond = t->out.OctetsPerSecond = t->BestOctetsPerSecond = 0; in throughput_start()
206 time(&t->BestOctetsPerSecondTime); in throughput_start()
207 t->downtime = 0; in throughput_start()
208 time(&t->uptime); in throughput_start()
209 throughput_restart(t, name, rolling); in throughput_start()
213 throughput_restart(struct pppThroughput *t, const char *name, int rolling) in throughput_restart() argument
215 timer_Stop(&t->Timer); in throughput_restart()
216 t->rolling = rolling ? 1 : 0; in throughput_restart()
217 if (t->rolling) { in throughput_restart()
218 t->Timer.load = SECTICKS; in throughput_restart()
219 t->Timer.func = throughput_sampler; in throughput_restart()
220 t->Timer.name = name; in throughput_restart()
221 t->Timer.arg = t; in throughput_restart()
222 timer_Start(&t->Timer); in throughput_restart()
224 t->Timer.load = 0; in throughput_restart()
225 t->Timer.func = NULL; in throughput_restart()
226 t->Timer.name = NULL; in throughput_restart()
227 t->Timer.arg = NULL; in throughput_restart()
232 throughput_stop(struct pppThroughput *t) in throughput_stop() argument
234 if (t->Timer.state != TIMER_STOPPED) in throughput_stop()
235 time(&t->downtime); in throughput_stop()
236 timer_Stop(&t->Timer); in throughput_stop()
240 throughput_addin(struct pppThroughput *t, long long n) in throughput_addin() argument
242 t->OctetsIn += n; in throughput_addin()
243 t->PacketsIn++; in throughput_addin()
247 throughput_addout(struct pppThroughput *t, long long n) in throughput_addout() argument
249 t->OctetsOut += n; in throughput_addout()
250 t->PacketsOut++; in throughput_addout()
254 throughput_clear(struct pppThroughput *t, int clear_type, struct prompt *prompt) in throughput_clear() argument
259 for (i = 0; i < t->SamplePeriod; i++) in throughput_clear()
260 t->in.SampleOctets[i] = t->out.SampleOctets[i] = 0; in throughput_clear()
261 t->nSample = 0; in throughput_clear()
267 if ((divisor = throughput_uptime(t)) == 0) in throughput_clear()
270 (t->OctetsIn + t->OctetsOut) / divisor); in throughput_clear()
271 t->OctetsIn = t->OctetsOut = t->PacketsIn = t->PacketsOut = 0; in throughput_clear()
272 t->downtime = 0; in throughput_clear()
273 time(&t->uptime); in throughput_clear()
279 t->in.OctetsPerSecond, t->out.OctetsPerSecond); in throughput_clear()
280 t->in.OctetsPerSecond = t->out.OctetsPerSecond = 0; in throughput_clear()
286 time_buf = ctime(&t->BestOctetsPerSecondTime); in throughput_clear()
291 t->BestOctetsPerSecond, time_buf); in throughput_clear()
292 t->BestOctetsPerSecond = 0; in throughput_clear()
293 time(&t->BestOctetsPerSecondTime); in throughput_clear()
298 throughput_callback(struct pppThroughput *t, void (*fn)(void *), void *data) in throughput_callback() argument
300 t->callback.fn = fn; in throughput_callback()
301 t->callback.data = data; in throughput_callback()