On 12/13/06, Gary Johnson <[EMAIL PROTECTED]> wrote:
On 2006-12-03, Yakov Lerner <[EMAIL PROTECTED]> wrote:
> You can try 'gvim.exe -V20/tmp/log' to identity points of slowness.
> You might need timestamps in the logfile for that. To add timestamps,
> you can try to redirect the logfile to the named pipe and the to
> utility which adds timestamps.
What utility that adds timestamps?
I don't know if you can call the [1] and [2] below 'utilities', but
they copy standard input to standard output, adding
the timestamp to microsecond resolution to each line.
[1] is in perl, [2] is in C. Worksforme.
Good luck,
Yakov
[1] --------- timestamp.pl ---------------------------------------------------
#!/usr/bin/perl -w
# timestamp.pl -- copy standard input to standard output, adding
# timestamps with microsecond resolution.
use POSIX qw(strftime);
use Time::HiRes qw(gettimeofday);
my ($seconds, $microseconds, $formatted_time );
while(<STDIN>) {
($seconds, $microseconds) = gettimeofday;
$formatted_time = strftime( "%H:%M:%S", localtime($seconds));
printf "%s.%06d %s", $formatted_time, $microseconds, $_;
}
[2] --------------------timestamp.c
--------------------------------------------------
/* timestamp.c - copy standard input to standard output, adding */
/* timestamps with microsecond resolution */
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
char *timestamp(char *buf, int max, time_t _time) {
struct tm tm_;
localtime_r(&_time, &tm_);
strftime(buf, max, "%H:%M:%S", &tm_);
return buf;
}
int main() {
char buf[1024];
char timebuf[30];
struct timeval tv;
while(fgets(buf, sizeof(buf), stdin) != NULL) {
gettimeofday(&tv, NULL);
printf("%s.%06ld %s",
timestamp(timebuf, sizeof(timebuf), tv.tv_sec),
(long)tv.tv_usec, buf);
}
return 0;
}
-------------------------------------------------------------------------------