--- Begin Message ---
Package: procps
Version: 1:2.0.7-10asd1
Severity: normal
File: /usr/bin/watch
Tags: patch
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
(NOTE: This patch also fixes bug #182246)
This patch adds in support for a --precision / -p option and documents
it in the manpage and --help output.
The -p option causes watch to attempt to run the command every <interval>
seconds (instead of run the command <interval> seconds after the last
command exited). You can quickly see the effect with things like
watch sleep 1
Without -p, the time in watch's header will switch between even and odd
seconds; with -p, it will stay with which ever it started with. To
really see how precise -p is, try
watch -n1 ntptime
Without -p, you can see the fractional seconds in the time continuously
increasing; eventaully, a second will be skipped. With -p, that doesn't
happen. The fractional seconds change a little due to kernel scheduling
accuracy, but it hovers around the correct value.
And now, for the patch. I've tested this, I don't think it breaks
anything (unlike my last watch patch...); the only thing that worries me
is what -p will do in the face of daylight savings time. Not sure what
gettimeofday does then.
IGNORE THE VERSION HEADER! This patch is against 1:3.1.6-1.
diff -rdbU3 procps-3.1.6.orig/watch.1 procps-3.1.6/watch.1
- --- procps-3.1.6.orig/watch.1 2003-02-09 02:05:25.000000000 -0500
+++ procps-3.1.6/watch.1 2003-03-05 04:03:06.000000000 -0500
@@ -1,9 +1,9 @@
- -.TH WATCH 1 "1999 Apr 3" " " "Linux User's Manual"
+.TH WATCH 1 "2003 Mar 5" " " "Linux User's Manual"
.SH NAME
watch \- execute a program periodically, showing output fullscreen
.SH SYNOPSIS
.B watch
- -.I [\-dhvt] [\-n <seconds>] [\-\-differences[=cumulative]] [\-\-help]
[\-\-interval=<seconds>] [\-\-no\-title] [\-\-version] <command>
+.I [\-dhvt] [\-n <seconds>] [\-\-differences[=cumulative]] [\-\-help]
[\-\-interval=<seconds>] [\-\-precise] [\-\-no\-title] [\-\-version] <command>
.SH DESCRIPTION
.BR watch
runs
@@ -14,7 +14,24 @@
.I -n
or
.I --interval
- -to specify a different interval.
+to specify a different interval. Normally, this interval is interpreted
+as the amout of time between the completion of one run of
+.I command
+and the beginning of the next run. However, with the
+.I -p
+or
+.I --precise
+option, you can make
+.BR watch
+attempt to run
+.I command
+every
+.I interval
+seconds. Try it with
+.B ntptime
+and notice how the fractional seconds stays
+(nearly) the same, as opposed to normal mode where they continuously
+increase.
.PP
The
.I -d
@@ -66,11 +83,21 @@
.IP
watch echo "'"'$$'"'"
.PP
+To see the effect of precision time keeping, try adding
+.I -p
+to
+.IP
+watch -n 10 sleep 1
+.PP
You can watch for your administrator to install the latest kernel with
.IP
watch uname -r
.PP
- -(Just kidding.)
+(Note that
+.I -p
+isn't guaranteed to work across reboots, especially in the face of
+.B ntpdate
+or other bootup time-changing mechanisms)
.SH BUGS
Upon terminal resize, the screen will not be correctly repainted until the
next scheduled update. All
@@ -79,9 +106,28 @@
.PP
Non-printing characters are stripped from program output. Use "cat -v" as
part of the command pipeline if you want to see them.
+.PP
+.I --precise
+mode doesn't yet have advanced temporal distortion technology to
+compensate for a
+.I command
+that takes more than
+.I interval
+seconds to execute.
+.B watch
+also can get into a state where it rapid-fires as many executions of
+.I command
+as it can to catch up from a previous executions running longer than
+.I interval
+(for example,
+.B netstat
+taking ages on a DNS lookup).
.SH AUTHORS
The original
.B watch
was written by Tony Rems <[email protected]> in 1991, with mods and
corrections by Francois Pinard. It was reworked and new features added by
- -Mike Coleman <[email protected]> in 1999.
+Mike Coleman <[email protected]> in 1999. On a not so dark and stormy morning
+in March of 2003, Anthony DeRobertis <[email protected]> got sick of
+his watches that should update every minute eventually updating many
+seconds after the minute started, and added microsecond precision.
Only in procps-3.1.6: .watch.1.swp
diff -rdbU3 procps-3.1.6.orig/watch.c procps-3.1.6/watch.c
- --- procps-3.1.6.orig/watch.c 2003-02-09 02:03:45.000000000 -0500
+++ procps-3.1.6/watch.c 2003-03-05 03:58:54.000000000 -0500
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <locale.h>
@@ -29,13 +30,14 @@
{"differences", optional_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"interval", required_argument, 0, 'n'},
+ {"precise", no_argument, 0, 'p'},
{"no-title", no_argument, 0, 't'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static char usage[] =
- - "Usage: %s [-dhntv] [--differences[=cumulative]] [--help]
[--interval=<n>] [--no-title] [--version] <command>\n";
+ "Usage: %s [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>]
[--precise] [--no-title] [--version] <command>\n";
static char *progname;
@@ -44,6 +46,7 @@
static int screen_size_changed = 0;
static int first_screen = 1;
static int show_title = 2; // number of lines used, 2 or 0
+static int precise_timekeeping = 0;
#define min(x,y) ((x) > (y) ? (y) : (x))
@@ -89,6 +92,15 @@
}
}
+/* get current time in usec */
+typedef unsigned long long watch_usec_t;
+#define USECS_PER_SEC (1000000ull)
+watch_usec_t get_time_usec() {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return USECS_PER_SEC*now.tv_sec + now.tv_usec;
+}
+
int
main(int argc, char *argv[])
{
@@ -99,11 +111,14 @@
int interval = 2;
char *command;
int command_length = 0; /* not including final \0 */
+ watch_usec_t next_loop; /* next loop time in us, used for precise time
+ keeping only */
+
setlocale(LC_ALL, "");
progname = argv[0];
- - while ((optc = getopt_long(argc, argv, "+d::hn:vt", longopts, (int *)
0))
+ while ((optc = getopt_long(argc, argv, "+d::hn:vtp", longopts, (int *)
0))
!= EOF) {
switch (optc) {
case 'd':
@@ -125,6 +140,9 @@
do_usage();
}
break;
+ case 'p':
+ precise_timekeeping = 1;
+ break;
case 'v':
option_version = 1;
break;
@@ -152,6 +170,10 @@
fputs
(" -n, --interval=<seconds>\t\tseconds to wait between
updates\n",
stderr);
+ fputs
+ (" -p, --precise\t\t\t\tprecise timing, ignore command
run time\n",
+ stderr);
+ fputs(" -t, --no-title\t\t\tturns of showing the header\n",
stderr);
fputs(" -v, --version\t\t\t\tprint the version number\n",
stderr);
exit(0);
@@ -188,6 +210,9 @@
noecho();
cbreak();
+ if (precise_timekeeping)
+ next_loop = get_time_usec();
+
for (;;) {
time_t t = time(NULL);
char *ts = ctime(&t);
@@ -274,6 +299,12 @@
first_screen = 0;
refresh();
+ if (precise_timekeeping) {
+ watch_usec_t cur_time = get_time_usec();
+ next_loop += USECS_PER_SEC*interval;
+ if (cur_time < next_loop)
+ usleep(next_loop - cur_time);
+ } else
sleep(interval);
}
- -- System Information
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux bohr 2.4.16 #2 SMP Wed Nov 28 05:25:00 EST 2001 i686
Locale: LANG=en_US, LC_CTYPE=en_US
Versions of packages procps depends on:
ii libc6 2.2.5-14.3 GNU C Library: Shared libraries an
ii libncurses5 5.2.20020112a-8 Shared libraries for terminal hand
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)
iD8DBQE+ZcBj+z+IwlXqWf4RApNQAJ0UmV6eE83W6j96cSDZzHJj8SuXBQCffREZ
haMJ1H5MSEeiSH6bAOd6ygw=
=dAGN
-----END PGP SIGNATURE-----
--- End Message ---