stats.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. public:
  29. statsRecorder(char *fname);
  30. ~statsRecorder() {
  31. this->flush();
  32. }
  33. char *timestamp();
  34. void timestamp(const char *s);
  35. void comment(const char *s, const int verbose=1);
  36. void comment(const char *s1, const char *s2);
  37. void comment(const int n);
  38. void recordTime(const char *label, long secs);
  39. void recordTime(const char *label, Rtimer rt);
  40. void recordLength(const char *label, off_t len, int siz=0, char *sname=NULL);
  41. template<class T> void recordLength(const char *label, AMI_STREAM<T> *str) {
  42. recordLength(label, str->stream_len(), sizeof(T), str->sprint());
  43. }
  44. };
  45. char *formatNumber(char *buf, off_t val);
  46. #endif