Browse Source

Add timestamps to debug output in ethstream

git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@9487 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/ethstream-1.3
nilm 13 years ago
parent
commit
bb4912a43c
3 changed files with 27 additions and 2 deletions
  1. +18
    -0
      debug.c
  2. +7
    -0
      debug.h
  3. +2
    -2
      ethstream.c

+ 18
- 0
debug.c View File

@@ -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
- 0
debug.h View File

@@ -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); \
})


+ 2
- 2
ethstream.c View File

@@ -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…
Cancel
Save