36 #include <QStringList>
48 mIntervalClock.start();
56 mIntervalClock.start();
62 mIntervalClock.restart();
69 this->
time(
"outside");
74 std::vector<Entry>::iterator iter;
75 for (iter=mTiming.begin(); iter!=mTiming.end(); ++iter)
79 iter->time.push_back(mRenderClock.restart());
85 newEntry.time.push_back(mRenderClock.restart());
86 mTiming.push_back(newEntry);
93 if (!mIntervalClock.elapsed())
95 double numberOfRenderings = mTiming.empty() ? 0 : mTiming.front().time.size();
96 double fps = 1000.0 * numberOfRenderings / mIntervalClock.elapsed();
102 return mIntervalClock.elapsed() > mInterval;
148 std::stringstream ss;
149 ss << mName <<
":\t";
150 ss <<
"Elapsed=" << mIntervalClock.elapsed() <<
" ms";
151 ss <<
"\tFPS=" << this->
getFPS() <<
" fps";
156 QStringList meanTimes;
157 QStringList maxTimes;
161 std::vector<Entry>::iterator entry;
162 for (entry=mTiming.begin(); entry!=mTiming.end(); ++entry)
164 double maxTime = this->getMaxTime(entry->time);
165 double meanTime = this->getMeanTime(entry->time);
166 totalTime += meanTime;
173 ss << QString(
"\t(total=%1)").arg(ids.join(
"+"));
174 ss << QString(
"\tMean:(%2=%3) ms/frame").arg(totalTime).arg(meanTimes.join(
"+"));
175 ss << QString(
"\tMax:(%1)").arg(maxTimes.join(
"+"));
180 double CyclicActionLogger::getMeanTime(std::vector<double> &time)
182 return std::accumulate(time.begin(), time.end(), 0)/time.size();
185 double CyclicActionLogger::getMaxTime(std::vector<double> &time)
187 return *std::max_element(time.begin(), time.end());
192 std::vector<Entry>::iterator entry = getTimingVectorIterator(
id);
193 if(entry == mTiming.end())
195 reportWarning(
"CyclicActionLogger::getTime() unknown id: " +
id);
198 return getMeanTime(entry->time);
201 std::vector<CyclicActionLogger::Entry>::iterator CyclicActionLogger::getTimingVectorIterator(QString
id)
203 std::vector<Entry>::iterator entry;
204 for (entry=mTiming.begin(); entry!=mTiming.end(); ++entry)
214 double totalTime = 0;
215 std::vector<Entry>::iterator entry;
216 for (entry=mTiming.begin(); entry!=mTiming.end(); ++entry)
218 if(entry->id !=
"outside")
220 double meanTime = this->getMeanTime(entry->time);
221 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()