Skip to content

Commit 5cc89db

Browse files
authored
Merge pull request #2990 from secondlife/viewer-2921
More detailed frame time logging in ViewerStats
2 parents 58cd840 + 8cad319 commit 5cc89db

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

indra/llcommon/llstatsaccumulator.h

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ class LLStatsAccumulator
5959

6060
inline F32 getSum() const
6161
{
62-
return mSum;
62+
return F32(mSum);
63+
}
64+
65+
inline F32 getSumOfSquares() const
66+
{
67+
return F32(mSumOfSquares);
6368
}
6469

6570
inline F32 getMean() const
@@ -79,8 +84,16 @@ class LLStatsAccumulator
7984

8085
inline F32 getStdDev() const
8186
{
82-
const F32 mean = getMean();
83-
return (mCount < 2) ? 0.f : sqrt(llmax(0.f, mSumOfSquares / mCount - (mean * mean)));
87+
const F64 mean = getMean();
88+
if (mCount < 2)
89+
{
90+
return 0.f;
91+
}
92+
else
93+
{
94+
F32 variance = F32 (mSumOfSquares / mCount - (mean * mean));
95+
return sqrt(llmax(0.f, variance));
96+
}
8497
}
8598

8699
inline U32 getCount() const
@@ -100,21 +113,47 @@ class LLStatsAccumulator
100113
inline LLSD asLLSD() const
101114
{
102115
LLSD data;
116+
data["count"] = S32(getCount());
117+
data["sum"] = getSum();
118+
data["sum_of_squares"] = getSumOfSquares();
103119
data["mean"] = getMean();
104120
data["std_dev"] = getStdDev();
105-
data["count"] = (S32)mCount;
106121
data["min"] = getMinValue();
107122
data["max"] = getMaxValue();
108123
return data;
109124
}
110125

111126
private:
112127
S32 mCount;
113-
F32 mSum;
114-
F32 mSumOfSquares;
128+
F64 mSum;
129+
F64 mSumOfSquares;
115130
F32 mMinValue;
116131
F32 mMaxValue;
117132
U32 mCountOfNextUpdatesToIgnore;
118133
};
119134

135+
// Assumes the samples are frame times
136+
inline F32 fps(LLStatsAccumulator& accum)
137+
{
138+
F32 mean = accum.getMean();
139+
if (mean > 0.f)
140+
{
141+
return 1.0f/mean;
142+
}
143+
return 0.0f;
144+
}
145+
146+
// Assumes the samples are frame times
147+
// ofr = observed frame rate, which has frame times weighted by length, since long frames count more toward user experience.
148+
inline F32 ofr(LLStatsAccumulator& accum)
149+
{
150+
F32 sum = accum.getSum();
151+
F32 sum_of_squares = accum.getSumOfSquares();
152+
if (sum_of_squares > 0.0f)
153+
{
154+
return sum/sum_of_squares;
155+
}
156+
return 0.0f;
157+
}
158+
120159
#endif

indra/newview/llviewerstats.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ void LLViewerStats::updateFrameStats(const F64Seconds time_diff)
274274
// old stats that were never really used
275275
F64Seconds jit = (F64Seconds)std::fabs((mLastTimeDiff - time_diff));
276276
sample(LLStatViewer::FRAMETIME_JITTER, jit);
277+
278+
if (gFocusMgr.getAppHasFocus())
279+
{
280+
mForegroundFrameStats.push(F32(time_diff));
281+
}
282+
else
283+
{
284+
mBackgroundFrameStats.push(F32(time_diff));
285+
}
286+
277287
}
278288

279289
mLastTimeDiff = time_diff;
@@ -525,7 +535,8 @@ void send_viewer_stats(bool include_preferences)
525535

526536
LLSD capture_viewer_stats(bool include_preferences)
527537
{
528-
LLViewerStats& vstats{ LLViewerStats::instance() };
538+
LLViewerStats& vstats = LLViewerStats::instance();
539+
529540
vstats.getRecording().pause();
530541
LL::scope_exit cleanup([&vstats]{ vstats.getRecording().resume(); });
531542

@@ -536,8 +547,6 @@ LLSD capture_viewer_stats(bool include_preferences)
536547
time(&ltime);
537548
F32 run_time = F32(LLFrameTimer::getElapsedSeconds());
538549

539-
agent["start_time"] = S32(ltime - S32(run_time));
540-
541550
// The first stat set must have a 0 run time if it doesn't actually
542551
// contain useful data in terms of FPS, etc. We use half the
543552
// SEND_STATS_PERIOD seconds as the point at which these statistics become
@@ -552,8 +561,19 @@ LLSD capture_viewer_stats(bool include_preferences)
552561
agent["run_time"] = run_time;
553562
}
554563

564+
agent["start_time"] = S32(ltime - S32(run_time));
565+
566+
agent["fg_frame_stats"] = vstats.mForegroundFrameStats.asLLSD();
567+
agent["fg_frame_stats"]["ofr"] = ofr(vstats.mForegroundFrameStats);
568+
agent["fg_frame_stats"]["fps"] = fps(vstats.mForegroundFrameStats);
569+
570+
agent["bg_frame_stats"] = vstats.mBackgroundFrameStats.asLLSD();
571+
agent["bg_frame_stats"]["ofr"] = ofr(vstats.mBackgroundFrameStats);
572+
agent["bg_frame_stats"]["fps"] = fps(vstats.mBackgroundFrameStats);
573+
555574
// report time the viewer has spent in the foreground
556575
agent["foreground_time"] = gForegroundTime.getElapsedTimeF32();
576+
agent["foreground_frame_count"] = (S32) gForegroundFrameCount;
557577

558578
// send fps only for time app spends in foreground
559579
agent["fps"] = (F32)gForegroundFrameCount / gForegroundTime.getElapsedTimeF32();

indra/newview/llviewerstats.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,14 @@ class LLViewerStats : public LLSingleton<LLViewerStats>
271271
LLTrace::Recording& getRecording() { return mRecording; }
272272
const LLTrace::Recording& getRecording() const { return mRecording; }
273273

274+
public:
275+
StatsAccumulator mForegroundFrameStats;
276+
StatsAccumulator mBackgroundFrameStats;
277+
274278
private:
275279
LLTrace::Recording mRecording;
276280

281+
277282
F64Seconds mLastTimeDiff; // used for time stat updates
278283
};
279284

0 commit comments

Comments
 (0)