Commit a393d31e authored by Bernhard Link's avatar Bernhard Link

add --monotonic-timestamps

parent 2b5dbf86
2010-12-21
* Add --monotonic-timestamps to print timestamps relative to system
start (or whatever CLOCK_MONOTONIC returns on your system).
2010-10-26 2010-10-26
* Add Composite (Thanks to Adam Endrodi) * Add Composite (Thanks to Adam Endrodi)
2010-10-20 2010-10-20
......
...@@ -14,10 +14,28 @@ AC_GNU_SOURCE ...@@ -14,10 +14,28 @@ AC_GNU_SOURCE
AC_PROG_CC AC_PROG_CC
AC_PROG_INSTALL AC_PROG_INSTALL
AC_CHECK_FUNCS([strndup]) AC_CACHE_CHECK([Checking for _POSIX_TIMERS and _POSIX_MONOTONIC_CLOCK],[ac_monotonic_clock],
AC_CHECK_FUNCS([asprintf]) [AC_PREPROC_IFELSE(AC_LANG_PROGRAM([[
#include <unistd.h>
#include <time.h>
]],[[
#ifdef _POSIX_TIMERS
#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
1
#else
#error _POSIX_MONOTONIC_CLOCK not defined, or not positive, not using clock_gettime
#endif
#else
#error _POSIX_TIMERS not defined, not using clock_gettime
#endif
]]), [ac_monotonic_clock=yes], [ac_monotonic_clock=no])])
AC_CHECK_FUNCS(socket) if test $ac_monotonic_clock = yes ; then
AC_DEFINE([HAVE_MONOTONIC_CLOCK], 1, [Define if clock_gettime(CLOCK_MONOTONIC) should work])
AC_CHECK_LIB(rt, clock_gettime, [], [AC_MSG_ERROR([_POSIX_TIMERS suggests clock_gettime should work but it seems not to work, though])])
fi
AC_CHECK_FUNCS([strndup asprintf socket])
if test $ac_cv_func_socket = no; then if test $ac_cv_func_socket = no; then
AC_CHECK_LIB(socket, socket, [AC_DEFINE(HAVE_SOCKET) AC_CHECK_LIB(socket, socket, [AC_DEFINE(HAVE_SOCKET)
LIBS="$LIBS -lsocket -lnsl"; break],[AC_MSG_ERROR([Could not find socket library function])]) LIBS="$LIBS -lsocket -lnsl"; break],[AC_MSG_ERROR([Could not find socket library function])])
......
/* This file is part of "xtrace" /* This file is part of "xtrace"
* Copyright (C) 2005, 2007 Bernhard R. Link * Copyright (C) 2005, 2007, 2010 Bernhard R. Link
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
...@@ -45,6 +45,7 @@ bool denyallextensions = false; ...@@ -45,6 +45,7 @@ bool denyallextensions = false;
bool interactive = false; bool interactive = false;
bool print_timestamps = false; bool print_timestamps = false;
bool print_reltimestamps = false; bool print_reltimestamps = false;
bool print_uptimestamps = false;
static bool buffered = false; static bool buffered = false;
size_t maxshownlistlen = SIZE_MAX; size_t maxshownlistlen = SIZE_MAX;
...@@ -390,7 +391,7 @@ char *strndup(const char *str,size_t n) { ...@@ -390,7 +391,7 @@ char *strndup(const char *str,size_t n) {
} }
#endif #endif
enum {LO_DEFAULT=0, LO_TIMESTAMPS, LO_RELTIMESTAMPS, LO_VERSION, LO_HELP, LO_PRINTCOUNTS, LO_PRINTOFFSETS}; enum {LO_DEFAULT=0, LO_TIMESTAMPS, LO_RELTIMESTAMPS, LO_UPTIMESTAMPS, LO_VERSION, LO_HELP, LO_PRINTCOUNTS, LO_PRINTOFFSETS};
static int long_only_option = 0; static int long_only_option = 0;
static const struct option longoptions[] = { static const struct option longoptions[] = {
{"display", required_argument, NULL, 'd'}, {"display", required_argument, NULL, 'd'},
...@@ -412,6 +413,7 @@ static const struct option longoptions[] = { ...@@ -412,6 +413,7 @@ static const struct option longoptions[] = {
{"version", no_argument, &long_only_option, LO_VERSION}, {"version", no_argument, &long_only_option, LO_VERSION},
{"timestamps", no_argument, &long_only_option, LO_TIMESTAMPS}, {"timestamps", no_argument, &long_only_option, LO_TIMESTAMPS},
{"relative-timestamps", no_argument, &long_only_option, LO_RELTIMESTAMPS}, {"relative-timestamps", no_argument, &long_only_option, LO_RELTIMESTAMPS},
{"monotonic-timestamps",no_argument, &long_only_option, LO_UPTIMESTAMPS},
{"print-counts", no_argument, &long_only_option, LO_PRINTCOUNTS}, {"print-counts", no_argument, &long_only_option, LO_PRINTCOUNTS},
{"print-offsets", no_argument, &long_only_option, LO_PRINTOFFSETS}, {"print-offsets", no_argument, &long_only_option, LO_PRINTOFFSETS},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
...@@ -531,6 +533,18 @@ argv[0]); ...@@ -531,6 +533,18 @@ argv[0]);
case LO_RELTIMESTAMPS: case LO_RELTIMESTAMPS:
print_reltimestamps = true; print_reltimestamps = true;
break; break;
case LO_UPTIMESTAMPS:
#ifndef HAVE_MONOTONIC_CLOCK
fprintf(stderr, "--monotonic-timestamps not supported as clock_gettime(MONOTONIC_CLOCK, ) was not available at compile time\n");
exit(EXIT_FAILURE);
#else
if (sysconf(_SC_MONOTONIC_CLOCK) < 0) {
fprintf(stderr, "--monotonic-timestamps not supported on this system\n");
exit(EXIT_FAILURE);
}
print_uptimestamps = true;
#endif
break;
case LO_PRINTCOUNTS: case LO_PRINTCOUNTS:
print_counts = true; print_counts = true;
break; break;
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/select.h> #include <sys/select.h>
#include <unistd.h> #include <unistd.h>
#include <time.h>
#include <errno.h>
#include "xtrace.h" #include "xtrace.h"
#include "parse.h" #include "parse.h"
...@@ -60,6 +62,24 @@ static void startline(struct connection *c, enum package_direction d, const char ...@@ -60,6 +62,24 @@ static void startline(struct connection *c, enum package_direction d, const char
(unsigned int)((tt - c->starttime)%1000)); (unsigned int)((tt - c->starttime)%1000));
} }
} }
#ifdef HAVE_MONOTONIC_CLOCK
if( print_uptimestamps ) {
static bool already_warned = false;
struct timespec ts;
int i;
i = clock_gettime(CLOCK_MONOTONIC, &ts);
if( i == 0 ) {
fprintf(out, "%lu.%03u ",
(unsigned long)ts.tv_sec,
(unsigned int)(ts.tv_nsec/1000000L));
} else if (!already_warned) {
int e = errno;
fprintf(stderr, "Error %d from clock_gettime(CLOCK_MONOTIC,): %s\n",
e, strerror(e));
already_warned = true;
}
}
#endif
va_start(ap, format); va_start(ap, format);
fprintf(out, "%03d:%c:", c->id, (d == TO_SERVER)?'<':'>'); fprintf(out, "%03d:%c:", c->id, (d == TO_SERVER)?'<':'>');
vfprintf(out, format, ap); vfprintf(out, format, ap);
......
...@@ -117,6 +117,16 @@ Note that the time a packet is printed is between the time ...@@ -117,6 +117,16 @@ Note that the time a packet is printed is between the time
a packet is received and the time a packet is sent, a packet is received and the time a packet is sent,
but it gives no other information than that. but it gives no other information than that.
.TP
.B \-\-monotonic-timestamps
Print a CLOCK_MONOTONIC (see
.BR clock_gettime (3))
timestamp each time a package is printed.
This is likely to be the uptime of your system.
Note that the time a packet is printed is between the time
a packet is received and the time a packet is sent,
but it gives no other information than that.
.TP .TP
.B \-\-print-offsets .B \-\-print-offsets
Print offsets of all fields Print offsets of all fields
......
...@@ -46,6 +46,7 @@ extern bool denyallextensions; ...@@ -46,6 +46,7 @@ extern bool denyallextensions;
extern size_t maxshownlistlen; extern size_t maxshownlistlen;
extern bool print_timestamps; extern bool print_timestamps;
extern bool print_reltimestamps; extern bool print_reltimestamps;
extern bool print_uptimestamps;
#ifdef __GNUC__ #ifdef __GNUC__
#define UNUSED __attribute__ ((unused)) #define UNUSED __attribute__ ((unused))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment