From bb4912a43ca4ed254ca5c7252c6c3fdae11d4ce6 Mon Sep 17 00:00:00 2001 From: nilm Date: Tue, 29 Mar 2011 16:08:44 +0000 Subject: [PATCH] Add timestamps to debug output in ethstream git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@9487 ddd99763-3ecb-0310-9145-efcb8ce7c51f --- debug.c | 18 ++++++++++++++++++ debug.h | 7 +++++++ ethstream.c | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/debug.c b/debug.c index 91aca4e..7428977 100644 --- a/debug.c +++ b/debug.c @@ -1,6 +1,7 @@ #include "debug.h" #include #include +#include int verb_count = 0; @@ -8,10 +9,27 @@ int func_fprintf(const char *func, FILE * stream, const char *format, ...) { va_list ap; int ret; + struct timeval tv; + gettimeofday(&tv, NULL); + fprintf(stream, "%ld.%06ld: ", (unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec); fprintf(stream, "%s: ", func); va_start(ap, format); ret = vfprintf(stream, format, ap); va_end(ap); return ret; } + +int my_fprintf(FILE * stream, const char *format, ...) +{ + va_list ap; + int ret; + struct timeval tv; + + gettimeofday(&tv, NULL); + fprintf(stream, "%ld.%06ld: ", (unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec); + va_start(ap, format); + ret = vfprintf(stream, format, ap); + va_end(ap); + return ret; +} diff --git a/debug.h b/debug.h index 1f01e09..bf78964 100644 --- a/debug.h +++ b/debug.h @@ -16,6 +16,8 @@ extern int verb_count; int func_fprintf(const char *func, FILE * stream, const char *format, ...) __attribute__ ((format(printf, 3, 4))); +int my_fprintf(FILE * stream, const char *format, + ...) __attribute__ ((format(printf, 2, 3))); #define debug(x...) ({ \ if(verb_count >= 2) \ @@ -28,6 +30,11 @@ int func_fprintf(const char *func, FILE * stream, const char *format, }) #define info(x...) ({ \ + if(verb_count >= 0) \ + my_fprintf(stderr,x); \ +}) + +#define info_no_timestamp(x...) ({ \ if(verb_count >= 0) \ fprintf(stderr,x); \ }) diff --git a/ethstream.c b/ethstream.c index af071d2..705ffae 100644 --- a/ethstream.c +++ b/ethstream.c @@ -394,8 +394,8 @@ int main(int argc, char *argv[]) if (verb_count) { info("Scanning channels:"); for (i = 0; i < channel_count; i++) - info(" AIN%d", channel_list[i]); - info("\n"); + info_no_timestamp(" AIN%d", channel_list[i]); + info_no_timestamp("\n"); } /* Figure out actual rate. */