Add timestamps to debug output in ethstream
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@9487 ddd99763-3ecb-0310-9145-efcb8ce7c51f
This commit is contained in:
parent
16bf9f89ef
commit
bb4912a43c
18
debug.c
18
debug.c
|
@ -1,6 +1,7 @@
|
|||
#include "debug.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
7
debug.h
7
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); \
|
||||
})
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in New Issue
Block a user