log.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef LOG_H
  2. #define LOG_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/time.h>
  6. #include <stdarg.h>
  7. #include <sys/stat.h>
  8. #ifndef LOG_DIR
  9. #define LOG_DIR "./logs"
  10. #endif
  11. #ifndef LOG_CMP
  12. #define LOG_CMP "cmpr.ps"
  13. #endif
  14. #ifndef LOG_PLT
  15. #define LOG_PLT "cmpr.plot"
  16. #endif
  17. typedef void (*logfunc_t)(void *, ...);
  18. typedef struct stat stat_t;
  19. typedef struct log log_t;
  20. typedef struct logent logent_t;
  21. typedef struct {
  22. FILE *f;
  23. char *fn;
  24. int lines;
  25. const char *mode;
  26. } f_t;
  27. struct log {
  28. f_t *file;
  29. char *xlabel,
  30. *ylabel;
  31. logfunc_t func;
  32. logent_t **entry;
  33. int entries;
  34. };
  35. struct logent {
  36. char *desc;
  37. f_t *file;
  38. unsigned long long t1,
  39. t2;
  40. log_t *log;
  41. };
  42. void gettime(unsigned long long *t);
  43. log_t *log_init(char *name, const char *mode, char *xlabel, char *ylabel, logfunc_t f);
  44. logent_t *logent_init(log_t *l, char *desc, ...);
  45. void logent_start(logent_t *le, ...);
  46. void logent_end(logent_t *le, int idx, int ent, ...);
  47. void log_destroy(log_t *l);
  48. #endif