flog.h 559 Bytes
Newer Older
1 2 3 4 5 6 7
#ifndef _FLOG_H_
#define _FLOG_H_
#include <stdio.h> /* for FILE */
#include <sys/time.h> /* for struct timeval */
void flog(FILE *stream, const char *format, ...);
double duration(struct timeval *start);

Jordan Sissel's avatar
Jordan Sissel committed
8 9 10 11 12 13 14 15 16 17 18 19 20
#define flog_if_slow(stream, max_duration, block, format, args...) \
{ \
  struct timeval __start; \
  gettimeofday(&__start, NULL); \
  { \
    block \
  } \
  double __duration = duration(&__start); \
  if (__duration >= max_duration) { \
    flog(stream, "slow operation (%.3f seconds): " format , __duration, args); \
  } \
}

21
#endif /* _FLOG_H_ */