wmifs: Make sampling and scrolling intervals customizable.

Patch by Peter Samuelson <peter@samba-tng.org>.  First appeared in Debian
package version 1.3b1-14.

For more information, see:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=226689
This commit is contained in:
Doug Torrance 2014-10-22 16:34:37 -05:00 committed by Carlos R. Mafra
parent 49ecb83c8d
commit 279d4dee91

View file

@ -74,6 +74,9 @@
---- ----
Changes: Changes:
--- ---
01/08/2004 (Peter Samuelson, peter@samba-tng.org)
* Patch to make make sampling and scrolling intervals
customizable, adds new options -I and -s.
01/15/2002 (Matyas Koszik, koszik@debijan.lonyay.edu.hu) 01/15/2002 (Matyas Koszik, koszik@debijan.lonyay.edu.hu)
* Patch that fixes segfaults on long interface names. * Patch that fixes segfaults on long interface names.
08/31/2001 (Davi Leal, davileal@terra.es) 08/31/2001 (Davi Leal, davileal@terra.es)
@ -183,6 +186,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/time.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/xpm.h> #include <X11/xpm.h>
@ -197,8 +201,11 @@
#include "wmifs-master.xpm" #include "wmifs-master.xpm"
#include "wmifs-mask.xbm" #include "wmifs-mask.xbm"
/* How often to check for new network interface, in seconds */ /* How often to check for new network interface, in ms */
#define CHECK_INTERFACE_INTERVAL 5 #define CHECK_INTERFACE_INTERVAL 5000
/* How often to query the interfaces, in ms */
#define DEFAULT_SAMPLE_INTERVAL 50
/***********/ /***********/
/* Defines */ /* Defines */
@ -234,6 +241,8 @@ char *active_interface = NULL;
int TimerDivisor=60; int TimerDivisor=60;
int WaveForm=0; int WaveForm=0;
int LockMode=0; int LockMode=0;
int SampleInt = DEFAULT_SAMPLE_INTERVAL;
int ScrollSpeed = CHECK_INTERFACE_INTERVAL;
/*****************/ /*****************/
/* PPP variables */ /* PPP variables */
@ -296,9 +305,17 @@ int main(int argc, char *argv[]) {
active_interface = argv[i+1]; active_interface = argv[i+1];
i++; i++;
break; break;
case 'I' :
SampleInt = atof(argv[i+1]) * 1000;
i++;
break;
case 'l' : case 'l' :
LockMode = 1; LockMode = 1;
break; break;
case 's' :
ScrollSpeed = atof(argv[i+1]) * 1000;
i++;
break;
case 'v' : case 'v' :
printversion(); printversion();
exit(0); exit(0);
@ -361,9 +378,9 @@ void wmifs_routine(int argc, char **argv) {
int stat_online; int stat_online;
int stat_current; int stat_current;
time_t starttime; unsigned int curtime;
time_t curtime; unsigned int nexttime;
time_t nexttime; struct timeval tv, tv2;
long ipacket, opacket, istat, ostat; long ipacket, opacket, istat, ostat;
@ -410,8 +427,8 @@ void wmifs_routine(int argc, char **argv) {
AddMouseRegion(0, 5, 5, 35, 15); AddMouseRegion(0, 5, 5, 35, 15);
AddMouseRegion(1, 5, 20, 58, 58); AddMouseRegion(1, 5, 20, 58, 58);
starttime = time(0); gettimeofday(&tv2, NULL);
nexttime = starttime + CHECK_INTERFACE_INTERVAL; nexttime = ScrollSpeed;
for (i=0; i<stat_online; i++) { for (i=0; i<stat_online; i++) {
get_statistics(stat_devices[i].name, &ipacket, &opacket, &istat, &ostat); get_statistics(stat_devices[i].name, &ipacket, &opacket, &istat, &ostat);
@ -422,7 +439,10 @@ void wmifs_routine(int argc, char **argv) {
DrawActiveIFS(stat_devices[stat_current].name); DrawActiveIFS(stat_devices[stat_current].name);
while (1) { while (1) {
curtime = time(0); gettimeofday(&tv, NULL);
curtime = (tv.tv_sec - tv2.tv_sec) * 1000
+ (tv.tv_usec - tv2.tv_usec) / 1000;
waitpid(0, NULL, WNOHANG); waitpid(0, NULL, WNOHANG);
for (i=0; i<stat_online; i++) { for (i=0; i<stat_online; i++) {
@ -455,8 +475,7 @@ void wmifs_routine(int argc, char **argv) {
} }
if (curtime >= nexttime) { if (curtime >= nexttime) {
nexttime=curtime+ScrollSpeed;
nexttime=curtime+CHECK_INTERFACE_INTERVAL;
for (i=0; i<stat_online; i++) { for (i=0; i<stat_online; i++) {
if (i == stat_current) { if (i == stat_current) {
@ -538,7 +557,7 @@ void wmifs_routine(int argc, char **argv) {
} }
} }
usleep(50000L); /* 50 milliseconds */ usleep(SampleInt * 1000);
} }
} }
@ -880,7 +899,9 @@ void usage(void) {
fprintf(stderr, "\t-d <display name>\n"); fprintf(stderr, "\t-d <display name>\n");
fprintf(stderr, "\t-h\tthis help screen\n"); fprintf(stderr, "\t-h\tthis help screen\n");
fprintf(stderr, "\t-i <interface name>\tdefault (as it appears in /proc/net/route)\n"); fprintf(stderr, "\t-i <interface name>\tdefault (as it appears in /proc/net/route)\n");
fprintf(stderr, "\t-I <interval>\tsampling interval, in seconds (default: 0.05)\n");
fprintf(stderr, "\t-l\tstarts in lock mode\n"); fprintf(stderr, "\t-l\tstarts in lock mode\n");
fprintf(stderr, "\t-s <interval>\tscrolling interval, in seconds (default: 5)\n");
fprintf(stderr, "\t-v\tprint the version number\n"); fprintf(stderr, "\t-v\tprint the version number\n");
fprintf(stderr, "\t-w\twaveform load\n"); fprintf(stderr, "\t-w\twaveform load\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");