Commit bb4912a4 by nilm

Add timestamps to debug output in ethstream

git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@9487 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent 16bf9f89
Showing with 27 additions and 2 deletions
#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;
}
......@@ -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) \
......@@ -29,6 +31,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. */
......
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 sign in to comment