stats.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /****************************************************************************
  2. *
  3. * MODULE: r.terraflow
  4. *
  5. * COPYRIGHT (C) 2007 Laura Toma
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. *****************************************************************************/
  18. #ifndef STATS_H
  19. #define STATS_H
  20. #include <sys/types.h>
  21. #include <fstream>
  22. #include <iostream>
  23. #include <grass/iostream/ami.h>
  24. int noclobberFile(char *);
  25. class statsRecorder : public ofstream {
  26. private:
  27. Rtimer tm;
  28. void *bss;
  29. public:
  30. statsRecorder(char *fname);
  31. ~statsRecorder() {
  32. this->flush();
  33. }
  34. char *freeMem(char *);
  35. long freeMem();
  36. char *timestamp();
  37. void timestamp(const char *s);
  38. void comment(const char *s, const int verbose=1);
  39. void comment(const char *s1, const char *s2);
  40. void comment(const int n);
  41. void recordTime(const char *label, long secs);
  42. void recordTime(const char *label, Rtimer rt);
  43. void recordLength(const char *label, off_t len, int siz=0, char *sname=NULL);
  44. template<class T> void recordLength(const char *label, AMI_STREAM<T> *str) {
  45. recordLength(label, str->stream_len(), sizeof(T), str->sprint());
  46. }
  47. };
  48. char *formatNumber(char *buf, off_t val);
  49. #endif