30 #include <sys/times.h>
38 _m_timeAtInitialization=GetCpuTime();
49 newTimer.
start=GetCpuTime();
52 _m_timesMap[id].push_back(newTimer);
57 map <string, vector<Times> >::iterator it=_m_timesMap.find(
id);
58 if(it==_m_timesMap.end())
61 ss <<
"Timing::Stop Could not stop timing event called \""
62 <<
id <<
"\", no such event ever started";
68 it->second.back().end=endTime;
69 it->second.back().hasEnded=
true;
75 Stop(
id,GetCpuTime());
80 map<string, vector<Times> >::const_iterator i;
81 for(i=_m_timesMap.begin(); i!=_m_timesMap.end(); ++i)
83 const vector<Times> ×=i->second;
84 const string &
id=i->first;
85 for(vector<Times>::const_iterator j=times.begin();
91 cout << j->end - j->start
93 << j->start <<
" end "
97 cout <<
"still running, started at " << j->start
105 map<string, vector<Times> >::const_iterator i;
106 for(i=_m_timesMap.begin(); i!=_m_timesMap.end(); ++i)
108 const vector<Times> ×=i->second;
109 const string &
id=i->first;
110 clock_t total=0,maxTime=0,minTime=INT_MAX,current;
112 for(vector<Times>::const_iterator j=times.begin();
117 current=j->end - j->start;
130 cout << ClockToSeconds(total)
131 <<
" s in " << nrSamples <<
" measurements"
132 <<
", max " << ClockToSeconds(maxTime)
133 <<
", min " << ClockToSeconds(minTime)
135 else if((times.size()-nrSamples)>0)
140 cout << (times.size()-nrSamples) <<
" still running, spent "
141 << (ClockToSeconds(GetCpuTime()) -
142 ClockToSeconds(i->second[0].start)) << endl;
148 ofstream fp(filename.c_str());
152 ss <<
"Timing::Save: failed to open file " << filename;
161 of << _m_timeAtInitialization << endl;
163 map<string, vector<Times> >::const_iterator i;
164 for(i=_m_timesMap.begin(); i!=_m_timesMap.end(); ++i)
166 const vector<Times> ×=i->second;
167 const string &
id=i->first;
169 for(vector<Times>::const_iterator j=times.begin();
173 of <<
id <<
" " << j->start <<
" " << j->end << endl;
180 const int bufsize=65536;
181 char buffer[bufsize];
184 ifstream fp(filename.c_str());
186 cerr <<
"Timing::Load: failed to open file " << filename << endl;
190 while(!fp.getline(buffer,bufsize).eof())
193 string identification;
197 istringstream is(buffer);
202 _m_timeAtInitialization=start;
206 is >> identification;
211 _m_timesMap[identification].push_back(times);
219 struct tms timeStruct;
221 return(timeStruct.tms_utime + timeStruct.tms_stime);
229 return(static_cast<double>(clockTicks) / sysconf(_SC_CLK_TCK));
235 Stop(
id,GetCpuTime()+duration);
240 vector<double> durations;
242 map <string, vector<Times> >::iterator it=_m_timesMap.find(
id);
243 if(it==_m_timesMap.end())
246 ss <<
"Timing::GetEventDurations No events called \""
247 <<
id <<
"\" have been stored";
252 const vector<Times> ×=it->second;
253 for(vector<Times>::const_iterator j=times.begin();
257 durations.push_back(ClockToSeconds(j->end - j->start));