5 #ifndef STATS_RECORDER_H 111 virtual void start() = 0;
113 virtual void stop() = 0;
122 virtual void print(ostream& os)
const = 0;
130 virtual int setCellValues(
CSVStringTable& st,
unsigned row)
const = 0;
135 virtual void clearStats() = 0;
140 class PAPIRunStat :
public RunStat 152 PAPI_flops ( &rtimeS, &ptimeS, &flpopsS, &mflopsS);
158 float rtimeP, ptimeP, mflopsP;
160 PAPI_flops ( &rtimeP, &ptimeP, &flpopsP, &mflopsP);
161 rtimeACC += (rtimeP-rtimeS);
162 ptimeACC += (ptimeP-ptimeS);
163 flpopsACC += (flpopsP-flpopsS);
170 void print(ostream& os)
const 172 os <<
"HEADERS,PAPI_RTIME,PAPI_PTIME,PAPI_FLPOPS,PAPI_MFLOPS" << endl;
177 << ((double) flpopsACC / (
double) ptimeACC)/1000000.0 << endl;
189 if (st.
nRows() <= row)
return -1;
191 if ((ret = st.
setCell(row,
"PAPI_RTIME",rtimeACC,
true)))
193 if ((ret = st.
setCell(row,
"PAPI_PTIME",ptimeACC,
true)))
195 if ((ret = st.
setCell(row,
"PAPI_FLPOPS",flpopsACC,
true)))
197 double av_mflops = ((double) flpopsACC / (
double) ptimeACC) / 1000000.0;
198 if ((ret = st.
setCell(row,
"PAPI_AV_MFLOPS",av_mflops,
true)))
206 memset(&rtimeACC, 0,
sizeof(rtimeACC));
207 memset(&ptimeACC, 0,
sizeof(ptimeACC));
208 memset(&flpopsACC, 0,
sizeof(flpopsACC));
213 float rtimeS, ptimeS, mflopsS;
216 float rtimeACC, ptimeACC;
223 #ifdef REALpzfpcounter 225 class PZFPCountRunStat :
public RunStat 245 stop_counter -= start_counter;
246 acc_counter += stop_counter;
253 void print(ostream& os)
const 255 stringstream headers;
258 headers <<
"HEADERS";
259 for (
int i=0; i<
gNumOp; i++) {
260 headers <<
"," <<
"PZCOUNT_" << OpNames[i];
263 for (
int i=0; i<
gNumOp; i++) {
264 values <<
"," << acc_counter[i];
266 os << headers << endl;
267 os << values << endl;
279 if (st.
nRows() <= row)
return -1;
282 for (
int i=0; i<
gNumOp; i++) {
284 header <<
"PZCOUNT_" << OpNames[i];
285 if ((ret = st.
setCell(row,header,acc_counter[i],
true)))
307 #include <sys/resource.h> 321 getrusage(RUSAGE_SELF, &lap_self);
322 getrusage(RUSAGE_CHILDREN, &lap_children);
328 struct rusage self, children;
329 getrusage(RUSAGE_SELF, &
self);
330 getrusage(RUSAGE_CHILDREN, &children);
331 #define SET_TOTAL(fld) total_self.fld += (self.fld - lap_self.fld); total_children.fld += (children.fld - lap_children.fld) 333 #define SET_TOTAL_TIMEVAL(fld) \ 334 total_self.fld.tv_sec += (self.fld.tv_sec - lap_self.fld.tv_sec); \ 335 total_self.fld.tv_usec += (self.fld.tv_usec - lap_self.fld.tv_usec); \ 336 total_children.fld.tv_sec += (children.fld.tv_sec - lap_children.fld.tv_sec); \ 337 total_children.fld.tv_usec += (children.fld.tv_usec - lap_children.fld.tv_usec) 366 #define PRINT_FLD(hd,fld) header << ",SELF_" << hd << ",CHD_" << hd; values << "," << total_self.fld << "," << total_children.fld 368 #define TIMEVAL_TO_DOUBLE_MS(s) ( ((double) s.tv_sec) * 1000.0 + ((double) s.tv_usec) / 1000.0) 370 #define PRINT_TIMEVAL_FLD(hd,fld) \ 371 header << ",SELF_" << hd << ",CHD_" << hd; \ 372 values << "," << TIMEVAL_TO_DOUBLE_MS(total_self.fld) << "," << TIMEVAL_TO_DOUBLE_MS(total_children.fld) 390 os <<
"HEADERS" << header.str() << endl;
391 os <<
"VALUES" << values.str() << endl;
403 if (st.
nRows() <= row)
return -1;
405 #define APPEND_LONG_FLD(hd,fld) \ 406 { int ret; string header("SELF_"); header += hd; \ 407 if ((ret = st.setCell(row, header, total_self.fld, true))) \ 409 header = "CHD_"; header += hd; \ 410 if ((ret = st.setCell(row, header, total_children.fld, true))) \ 414 #define APPEND_TIMEVAL_FLD(hd,fld) \ 415 { int ret; string header("SELF_"); header += hd; \ 416 if ((ret = st.setCell(row, header, TIMEVAL_TO_DOUBLE_MS(total_self.fld), true))) \ 418 header = "CHD_"; header += hd; \ 419 if ((ret = st.setCell(row, header, TIMEVAL_TO_DOUBLE_MS(total_children.fld), true))) \ 444 memset(&lap_self, 0,
sizeof(lap_self));
445 memset(&lap_children, 0,
sizeof(lap_children));
446 memset(&total_self, 0,
sizeof(total_self));
447 memset(&total_children, 0,
sizeof(total_children));
452 struct rusage lap_self, lap_children;
453 struct rusage total_self, total_children;
476 perf_event_desc_t event;
480 class LIBPFMRunStat :
public RunStat 484 bool counters_enabled;
485 bool counters_created;
486 vector<perf_event_desc_t> counters;
491 counters_enable(false), counters_created(false)
500 if (!libpfm_man.ok())
return;
503 for (
int i=0; i<counters.size(); i++) {
504 fds[i].hw.read_format = PERF_FORMAT_SCALE;
505 fds[i].hw.disabled = 1;
507 fds[i].fd = perf_event_open(&fds[i].hw, 0, -1, -1, 0);
509 err(1,
"cannot open event %d", i);
515 if (prctl(PR_TASK_PERF_EVENTS_ENABLE)) {
519 counters_enable =
true;
525 if (counters_enable !=
true)
return;
526 if (prctl(PR_TASK_PERF_EVENTS_DISABLE)) {
557 void print(ostream& os)
const 654 gettimeofday(&lap, NULL);
661 gettimeofday(&curr, NULL);
662 total.tv_sec += (curr.tv_sec - lap.tv_sec );
663 total.tv_usec += (curr.tv_usec - lap.tv_usec);
673 os <<
"HEADERS,ELAPSED_MS" << endl;
674 os <<
"VALUES," << getElapsedMS() << endl;
686 if (st.
nRows() <= row)
return -1;
687 return st.
setCell(row,
"ELAPSED", getElapsedMS(),
true);
692 memset(&lap, 0,
sizeof(lap));
693 memset(&total, 0,
sizeof(total));
699 elapsed = (total.tv_sec) * 1000.0;
700 elapsed += (total.tv_usec) / 1000.0;
724 stat_items.push_back(
new LIBPFMRunStat());
732 stat_items.push_back(
new PAPIRunStat());
741 vector<RunStat*>::iterator it;
742 for (it=stat_items.begin(); it!=stat_items.end(); it++) {
753 vector<RunStat*>::iterator it;
754 for (it=stat_items.begin(); it!=stat_items.end(); it++)
761 vector<RunStat*>::reverse_iterator rit;
762 for (rit=stat_items.rbegin(); rit!=stat_items.rend(); rit++)
768 void lap() { stop(); start(); }
773 vector<RunStat*>::const_iterator it;
774 for (it=stat_items.begin(); it!=stat_items.end(); it++)
788 unsigned new_row = st.
addRows(1);
790 if ((ret=update_row(st, new_row)))
805 vector<RunStat*>::const_iterator it;
806 for (it=stat_items.begin(); it!=stat_items.end(); it++) {
807 if ((ret=(*it)->setCellValues(st,row))) {
817 vector<RunStat*>::iterator it;
818 for (it=stat_items.begin(); it!=stat_items.end(); it++)
832 #endif // STATS_RECORDER static TPZCounter gCount
Containts the counter vector by operation performed.
int setCellValues(CSVStringTable &st, unsigned row) const
int setCell(unsigned row_idx, string col_name, string value, bool createNewCol=false)
#define APPEND_LONG_FLD(hd, fld)
#define PRINT_TIMEVAL_FLD(hd, fld)
void print(ostream &os) const
#define PRINT_FLD(hd, fld)
int update_row(CSVStringTable &st, unsigned row) const
int setCellValues(CSVStringTable &st, unsigned row) const
double getElapsedMS() const
#define SET_TOTAL_TIMEVAL(fld)
const int gNumOp
Number of type of the operations actually counted.
int append_to(CSVStringTable &st) const
void print(ostream &os) const
Contains macros and functions to support a string csv table.
unsigned addRows(unsigned n=1)
vector< RunStat * > stat_items
Implements a counter by operations. Common.
void print(ostream &os) const
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
TPZCounter & copy(const TPZCounter &other)
#define APPEND_TIMEVAL_FLD(hd, fld)