15 #include <QStringList> 27 mIntervalClock.start();
35 mIntervalClock.start();
41 mIntervalClock.restart();
48 this->
time(
"outside");
53 std::vector<Entry>::iterator iter;
54 for (iter=mTiming.begin(); iter!=mTiming.end(); ++iter)
58 iter->time.push_back(mRenderClock.restart());
64 newEntry.time.push_back(mRenderClock.restart());
65 mTiming.push_back(newEntry);
72 if (!mIntervalClock.elapsed())
74 double numberOfRenderings = mTiming.empty() ? 0 : mTiming.front().time.size();
75 double fps = 1000.0 * numberOfRenderings / mIntervalClock.elapsed();
81 return mIntervalClock.elapsed() > mInterval;
127 std::stringstream ss;
128 ss << mName <<
":\t";
129 ss <<
"Elapsed=" << mIntervalClock.elapsed() <<
" ms";
130 ss <<
"\tFPS=" << this->
getFPS() <<
" fps";
135 QStringList meanTimes;
136 QStringList maxTimes;
140 std::vector<Entry>::iterator entry;
141 for (entry=mTiming.begin(); entry!=mTiming.end(); ++entry)
143 double maxTime = this->getMaxTime(entry->time);
144 double meanTime = this->getMeanTime(entry->time);
145 totalTime += meanTime;
152 ss << QString(
"\t(total=%1)").arg(ids.join(
"+"));
153 ss << QString(
"\tMean:(%2=%3) ms/frame").arg(totalTime).arg(meanTimes.join(
"+"));
154 ss << QString(
"\tMax:(%1)").arg(maxTimes.join(
"+"));
159 double CyclicActionLogger::getMeanTime(std::vector<double> &
time)
161 return std::accumulate(time.begin(), time.end(), 0)/time.size();
164 double CyclicActionLogger::getMaxTime(std::vector<double> &time)
166 return *std::max_element(time.begin(), time.end());
171 std::vector<Entry>::iterator entry = getTimingVectorIterator(
id);
172 if(entry == mTiming.end())
174 reportWarning(
"CyclicActionLogger::getTime() unknown id: " +
id);
177 return getMeanTime(entry->time);
180 std::vector<CyclicActionLogger::Entry>::iterator CyclicActionLogger::getTimingVectorIterator(QString
id)
182 std::vector<Entry>::iterator entry;
183 for (entry=mTiming.begin(); entry!=mTiming.end(); ++entry)
193 double totalTime = 0;
194 std::vector<Entry>::iterator entry;
195 for (entry=mTiming.begin(); entry!=mTiming.end(); ++entry)
197 if(entry->id !=
"outside")
199 double meanTime = this->getMeanTime(entry->time);
200 totalTime += meanTime;
QString qstring_cast(const T &val)
void reset(int interval=1000)
void begin()
start timing for this cycle
bool intervalPassed() const
double roundAwayFromZero(double val)
void reportWarning(QString msg)
int getTotalLoggedTime()
Total time contained in entered id's (id outside is not counted)
QString dumpStatisticsSmall()
void time(QString id)
store time from begin or last time()
Namespace for all CustusX production code.