From 7fbf42dec8bae638b62676c280b3f042f9458057 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Thu, 19 Apr 2012 14:52:44 -0400 Subject: Move phase tracking to its own set of classes inside LLViewerStats - simplifies llvoavatar and allows adding such tracking to classes that live outside the avatar lifetime --- indra/newview/llviewerstats.cpp | 107 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) mode change 100644 => 100755 indra/newview/llviewerstats.cpp (limited to 'indra/newview/llviewerstats.cpp') diff --git a/indra/newview/llviewerstats.cpp b/indra/newview/llviewerstats.cpp old mode 100644 new mode 100755 index c88122f22c..497e95c5e3 --- a/indra/newview/llviewerstats.cpp +++ b/indra/newview/llviewerstats.cpp @@ -860,3 +860,110 @@ void send_stats() LLHTTPClient::post(url, body, new ViewerStatsResponder()); } +LLFrameTimer& LLViewerStats::PhaseMap::getPhaseTimer(const std::string& phase_name) +{ + phase_map_t::iterator iter = mPhaseMap.find(phase_name); + if (iter == mPhaseMap.end()) + { + LLFrameTimer timer; + mPhaseMap[phase_name] = timer; + } + LLFrameTimer& timer = mPhaseMap[phase_name]; + return timer; +} + +void LLViewerStats::PhaseMap::startPhase(const std::string& phase_name) +{ + LLFrameTimer& timer = getPhaseTimer(phase_name); + lldebugs << "startPhase " << phase_name << llendl; + timer.unpause(); +} + +void LLViewerStats::PhaseMap::stopPhase(const std::string& phase_name) +{ + phase_map_t::iterator iter = mPhaseMap.find(phase_name); + if (iter != mPhaseMap.end()) + { + if (iter->second.getStarted()) + { + // Going from started to paused state - record stats. + recordPhaseStat(phase_name,iter->second.getElapsedTimeF32()); + } + lldebugs << "stopPhase " << phase_name << llendl; + iter->second.pause(); + } + else + { + lldebugs << "stopPhase " << phase_name << " is not started, no-op" << llendl; + } +} + +void LLViewerStats::PhaseMap::stopAllPhases() +{ + for (phase_map_t::iterator iter = mPhaseMap.begin(); + iter != mPhaseMap.end(); ++iter) + { + const std::string& phase_name = iter->first; + if (iter->second.getStarted()) + { + // Going from started to paused state - record stats. + recordPhaseStat(phase_name,iter->second.getElapsedTimeF32()); + } + lldebugs << "stopPhase (all) " << phase_name << llendl; + iter->second.pause(); + } +} + +void LLViewerStats::PhaseMap::clearPhases() +{ + lldebugs << "clearPhases" << llendl; + + mPhaseMap.clear(); +} + +LLSD LLViewerStats::PhaseMap::dumpPhases() +{ + LLSD result; + for (phase_map_t::iterator iter = mPhaseMap.begin(); iter != mPhaseMap.end(); ++iter) + { + const std::string& phase_name = iter->first; + result[phase_name]["completed"] = !(iter->second.getStarted()); + result[phase_name]["elapsed"] = iter->second.getElapsedTimeF32(); +#if 0 // global stats for each phase seem like overkill here + phase_stats_t::iterator stats_iter = sPhaseStats.find(phase_name); + if (stats_iter != sPhaseStats.end()) + { + result[phase_name]["stats"] = stats_iter->second.getData(); + } +#endif + } + return result; +} + +// static initializer +//static +LLViewerStats::phase_stats_t LLViewerStats::PhaseMap::sStats; + +LLViewerStats::PhaseMap::PhaseMap() +{ +} + +// static +LLViewerStats::StatsAccumulator& LLViewerStats::PhaseMap::getPhaseStats(const std::string& phase_name) +{ + phase_stats_t::iterator it = sStats.find(phase_name); + if (it == sStats.end()) + { + LLViewerStats::StatsAccumulator new_stats; + sStats[phase_name] = new_stats; + } + return sStats[phase_name]; +} + +// static +void LLViewerStats::PhaseMap::recordPhaseStat(const std::string& phase_name, F32 value) +{ + LLViewerStats::StatsAccumulator& stats = getPhaseStats(phase_name); + stats.push(value); +} + -- cgit v1.2.3