/**************************************************************************** * * MODULE: r.terraflow * * COPYRIGHT (C) 2007 Laura Toma * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * *****************************************************************************/ #include #include #include #include #ifndef __MINGW32__ #include #endif #include #include #include "stats.h" #ifdef HAS_UTRACE struct ut { char buf[8]; }; void utrace __P((void *, int)); #define UTRACE(s) \ {struct ut u; strncpy(u.buf,s,8); utrace((void*)&u, sizeof u);} #else /* !HAS_UTRACE */ #define UTRACE(s) #endif /* HAS_UTRACE */ #undef UTRACE #ifdef UTRACE_ENABLE #define UTRACE(s) utrace(s) #else #define UTRACE(s) #endif void utrace(const char *s) { void *p; int len = strlen(s); assert(len < 80); /* cerr << "UT " << len << endl; */ p = malloc(0); /* assert(p); */ free(p); p = malloc(len); /* assert(p); */ free(p); for(int i=0; i (1<<30)) { sprintf(buf, "%.2fG (%" PRI_OFF_T ")", (double)val/(1<<30), val); } else if(val > (1<<20)) { sprintf(buf, "%.2fM (%" PRI_OFF_T ")", (double)val/(1<<20), val); } else if(val > (1<<10)) { sprintf(buf, "%.2fK (%" PRI_OFF_T ")", (double)val/(1<<10), val); } else { sprintf(buf, "%" PRI_OFF_T, val); } return buf; } void statsRecorder::recordTime(const char *label, long secs) { *this << timestamp() << "TIME " << label << ": " << secs << " secs" << endl; this->flush(); UTRACE(label); } void statsRecorder::recordTime(const char *label, Rtimer rt) { char buf[BUFSIZ]; *this << timestamp() << "TIME " << label << ": "; *this << rt_sprint(buf, rt) << endl; this->flush(); UTRACE(label); } void statsRecorder::recordLength(const char *label, off_t len, int siz, char *sname) { UTRACE(label); UTRACE(sname); char lenstr[100]; char suffix[100]=""; if(siz) { formatNumber(suffix, len*siz); strcat(suffix, " bytes"); } formatNumber(lenstr, len); *this << timestamp() << "LEN " << label << ": " << lenstr << " elts " << suffix; if(sname) *this << " " << sname; *this << endl; this->flush(); }