From 935dce7d6b0a343cef5b13f53d6da5d0c2dc6a73 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 25 Mar 2013 00:18:06 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics fixed some compile errors made label spacing automatic on stat bars fixed infinite values coming from stats --- indra/llcommon/lltrace.h | 36 +++---- indra/llcommon/lltracerecording.cpp | 12 +-- indra/llcommon/lltracerecording.h | 16 +-- indra/llui/llstatbar.cpp | 107 +++++++++++---------- indra/llui/llstatbar.h | 4 +- indra/newview/llfloaterjoystick.cpp | 4 +- indra/newview/llworld.cpp | 3 +- .../default/xui/en/floater_scene_load_stats.xml | 42 +------- .../newview/skins/default/xui/en/floater_stats.xml | 71 ++------------ indra/newview/tests/llviewerassetstats_test.cpp | 2 +- 10 files changed, 108 insertions(+), 189 deletions(-) diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 71bf1e53e4..a574be02da 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -86,20 +86,17 @@ private: AccumulatorBuffer(StaticAllocationMarker m) : mStorageSize(0), - mStorage(NULL), - mNextStorageSlot(0) - { - } + mStorage(NULL) + {} public: AccumulatorBuffer(const AccumulatorBuffer& other = *getDefaultBuffer()) : mStorageSize(0), - mStorage(NULL), - mNextStorageSlot(other.mNextStorageSlot) + mStorage(NULL) { resize(other.mStorageSize); - for (S32 i = 0; i < mNextStorageSlot; i++) + for (S32 i = 0; i < sNextStorageSlot; i++) { mStorage[i] = other.mStorage[i]; } @@ -126,9 +123,8 @@ public: void addSamples(const AccumulatorBuffer& other) { - llassert(mNextStorageSlot == other.mNextStorageSlot); - - for (size_t i = 0; i < mNextStorageSlot; i++) + llassert(mStorageSize >= sNextStorageSlot && other.mStorageSize > sNextStorageSlot); + for (size_t i = 0; i < sNextStorageSlot; i++) { mStorage[i].addSamples(other.mStorage[i]); } @@ -136,7 +132,8 @@ public: void copyFrom(const AccumulatorBuffer& other) { - for (size_t i = 0; i < mNextStorageSlot; i++) + llassert(mStorageSize >= sNextStorageSlot && other.mStorageSize > sNextStorageSlot); + for (size_t i = 0; i < sNextStorageSlot; i++) { mStorage[i] = other.mStorage[i]; } @@ -144,7 +141,8 @@ public: void reset(const AccumulatorBuffer* other = NULL) { - for (size_t i = 0; i < mNextStorageSlot; i++) + llassert(mStorageSize >= sNextStorageSlot); + for (size_t i = 0; i < sNextStorageSlot; i++) { mStorage[i].reset(other ? &other->mStorage[i] : NULL); } @@ -172,7 +170,7 @@ public: { llerrs << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << llendl; } - size_t next_slot = mNextStorageSlot++; + size_t next_slot = sNextStorageSlot++; if (next_slot >= mStorageSize) { resize(mStorageSize + (mStorageSize >> 2)); @@ -208,7 +206,7 @@ public: size_t size() const { - return mNextStorageSlot; + return sNextStorageSlot; } static self_t* getDefaultBuffer() @@ -226,11 +224,15 @@ public: } private: - ACCUMULATOR* mStorage; - size_t mStorageSize; - size_t mNextStorageSlot; + ACCUMULATOR* mStorage; + size_t mStorageSize; + static size_t sNextStorageSlot; }; +template size_t AccumulatorBuffer::sNextStorageSlot = 0; + + + //TODO: replace with decltype when C++11 is enabled template struct MeanValueType diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index b70d42b082..f78b7942a7 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -116,12 +116,12 @@ void RecordingBuffers::mergeBuffers( const RecordingBuffers& other) void RecordingBuffers::resetBuffers(RecordingBuffers* other) { - mCountsFloat.write()->reset(other ? other->mCountsFloat : NULL); - mMeasurementsFloat.write()->reset(other ? other->mMeasurementsFloat : NULL); - mCounts.write()->reset(other ? other->mCounts : NULL); - mMeasurements.write()->reset(other ? other->mMeasurements : NULL); - mStackTimers.write()->reset(other ? other->mStackTimers : NULL); - mMemStats.write()->reset(other ? other->mMemStats : NULL); + mCountsFloat.write()->reset(other ? other->mCountsFloat : LLCopyOnWritePointer > >()); + mMeasurementsFloat.write()->reset(other ? other->mMeasurementsFloat : LLCopyOnWritePointer > >()); + mCounts.write()->reset(other ? other->mCounts : LLCopyOnWritePointer > >()); + mMeasurements.write()->reset(other ? other->mMeasurements : LLCopyOnWritePointer > >()); + mStackTimers.write()->reset(other ? other->mStackTimers : LLCopyOnWritePointer >()); + mMemStats.write()->reset(other ? other->mMemStats : LLCopyOnWritePointer >()); } /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 3e7ed2b592..b96d0666e5 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -305,7 +305,7 @@ namespace LLTrace U32 num_periods = mRecordingPeriods.size(); for (S32 i = 0; i < num_periods; i++) { - min_val = llmin(min_val, mRecordingPeriods[i].getSum(stat)); + min_val = llmin(min_val, mRecordingPeriods[(mCurPeriod + i) % num_periods].getSum(stat)); } return min_val; } @@ -317,7 +317,7 @@ namespace LLTrace U32 num_periods = mRecordingPeriods.size(); for (S32 i = 0; i < num_periods; i++) { - min_val = llmin(min_val, mRecordingPeriods[i].getPerSec(stat)); + min_val = llmin(min_val, mRecordingPeriods[(mCurPeriod + i) % num_periods].getPerSec(stat)); } return min_val; } @@ -329,7 +329,7 @@ namespace LLTrace U32 num_periods = mRecordingPeriods.size(); for (S32 i = 0; i < num_periods; i++) { - max_val = llmax(max_val, mRecordingPeriods[i].getSum(stat)); + max_val = llmax(max_val, mRecordingPeriods[(mCurPeriod + i) % num_periods].getSum(stat)); } return max_val; } @@ -339,9 +339,9 @@ namespace LLTrace { F64 max_val = (std::numeric_limits::min)(); U32 num_periods = mRecordingPeriods.size(); - for (S32 i = 0; i < num_periods; i++) + for (S32 i = 1; i < num_periods; i++) { - max_val = llmax(max_val, mRecordingPeriods[i].getPerSec(stat)); + max_val = llmax(max_val, mRecordingPeriods[(mCurPeriod + i) % num_periods].getPerSec(stat)); } return max_val; } @@ -353,9 +353,9 @@ namespace LLTrace U32 num_periods = mRecordingPeriods.size(); for (S32 i = 0; i < num_periods; i++) { - if (mRecordingPeriods[i].getDuration() > 0.f) + if (mRecordingPeriods[(mCurPeriod + i) % num_periods].getDuration() > 0.f) { - mean += mRecordingPeriods[i].getSum(stat); + mean += mRecordingPeriods[(mCurPeriod + i) % num_periods].getSum(stat); } } mean /= num_periods; @@ -371,7 +371,7 @@ namespace LLTrace { if (mRecordingPeriods[i].getDuration() > 0.f) { - mean += mRecordingPeriods[i].getPerSec(stat); + mean += mRecordingPeriods[(mCurPeriod + i) % num_periods].getPerSec(stat); } } mean /= num_periods; diff --git a/indra/llui/llstatbar.cpp b/indra/llui/llstatbar.cpp index cda40aac72..d9f3d14ef0 100644 --- a/indra/llui/llstatbar.cpp +++ b/indra/llui/llstatbar.cpp @@ -52,7 +52,6 @@ LLStatBar::LLStatBar(const Params& p) mMeasurementFloatp(LLTrace::MeasurementStatHandle<>::getInstance(p.stat)), mMeasurementIntp(LLTrace::MeasurementStatHandle::getInstance(p.stat)), mTickSpacing(p.tick_spacing), - mLabelSpacing(p.label_spacing), mPrecision(p.precision), mUpdatesPerSec(p.update_rate), mUnitScale(p.unit_scale), @@ -68,26 +67,32 @@ LLStatBar::LLStatBar(const Params& p) BOOL LLStatBar::handleMouseDown(S32 x, S32 y, MASK mask) { - if (mDisplayBar) + BOOL handled = LLView::handleMouseDown(x, y, mask); + if (!handled) { - if (mDisplayHistory) + if (mDisplayBar) { - mDisplayBar = FALSE; - mDisplayHistory = FALSE; + if (mDisplayHistory || mOrientation == HORIZONTAL) + { + mDisplayBar = FALSE; + mDisplayHistory = FALSE; + } + else + { + mDisplayHistory = TRUE; + } } else { - mDisplayHistory = TRUE; + mDisplayBar = TRUE; + if (mOrientation == HORIZONTAL) + { + mDisplayHistory = TRUE; + } } + LLView* parent = getParent(); + parent->reshape(parent->getRect().getWidth(), parent->getRect().getHeight(), FALSE); } - else - { - mDisplayBar = TRUE; - } - - LLView* parent = getParent(); - parent->reshape(parent->getRect().getWidth(), parent->getRect().getHeight(), FALSE); - return TRUE; } @@ -200,10 +205,10 @@ void LLStatBar::draw() if (mScaleRange && num_samples) { - F32 cur_max = mLabelSpacing; - while(max > cur_max) + F32 cur_max = mTickSpacing; + while(max > cur_max && mMaxBar > cur_max) { - cur_max += mLabelSpacing; + cur_max += mTickSpacing; } mCurMaxBar = LLSmoothInterpolation::lerp(mCurMaxBar, cur_max, 0.05f); } @@ -254,42 +259,51 @@ void LLStatBar::draw() // Draw the tick marks. LLGLSUIDefault gls_ui; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - - for (F32 tick_value = mMinBar + mLabelSpacing; tick_value <= mCurMaxBar; tick_value += mTickSpacing) + S32 last_tick = 0; + S32 last_label = 0; + const S32 MIN_TICK_SPACING = mOrientation == HORIZONTAL ? 20 : 30; + const S32 MIN_LABEL_SPACING = mOrientation == HORIZONTAL ? 40 : 60; + for (F32 tick_value = mMinBar + mTickSpacing; tick_value <= mCurMaxBar; tick_value += mTickSpacing) { const S32 begin = llfloor((tick_value - mMinBar)*value_scale); const S32 end = begin + tick_width; - if (mOrientation == HORIZONTAL) + if (begin - last_tick < MIN_TICK_SPACING) { - gl_rect_2d(bar_left, end, bar_right - tick_length/2, begin, LLColor4(1.f, 1.f, 1.f, 0.1f)); + continue; } - else - { - gl_rect_2d(begin, bar_top, end, bar_bottom - tick_length/2, LLColor4(1.f, 1.f, 1.f, 0.1f)); - } - } + last_tick = begin; - // Draw the tick labels (and big ticks). - for (F32 tick_value = mMinBar + mLabelSpacing; tick_value <= mCurMaxBar; tick_value += mLabelSpacing) - { - const S32 begin = llfloor((tick_value - mMinBar)*value_scale); - const S32 end = begin + tick_width; tick_label = llformat( value_format.c_str(), tick_value); - // draw labels for the tick marks if (mOrientation == HORIZONTAL) { - gl_rect_2d(bar_left, end, bar_right - tick_length, begin, LLColor4(1.f, 1.f, 1.f, 0.25f)); - LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, bar_right, begin, - LLColor4(1.f, 1.f, 1.f, 0.5f), - LLFontGL::LEFT, LLFontGL::VCENTER); + if (begin - last_label > MIN_LABEL_SPACING) + { + gl_rect_2d(bar_left, end, bar_right - tick_length, begin, LLColor4(1.f, 1.f, 1.f, 0.25f)); + LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, bar_right, begin, + LLColor4(1.f, 1.f, 1.f, 0.5f), + LLFontGL::LEFT, LLFontGL::VCENTER); + last_label = begin; + } + else + { + gl_rect_2d(bar_left, end, bar_right - tick_length/2, begin, LLColor4(1.f, 1.f, 1.f, 0.1f)); + } } else { - gl_rect_2d(begin, bar_top, end, bar_bottom - tick_length, LLColor4(1.f, 1.f, 1.f, 0.25f)); - LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, begin - 1, bar_bottom - tick_length, - LLColor4(1.f, 1.f, 1.f, 0.5f), - LLFontGL::RIGHT, LLFontGL::TOP); + if (begin - last_label > MIN_LABEL_SPACING) + { + gl_rect_2d(begin, bar_top, end, bar_bottom - tick_length, LLColor4(1.f, 1.f, 1.f, 0.25f)); + LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, begin - 1, bar_bottom - tick_length, + LLColor4(1.f, 1.f, 1.f, 0.5f), + LLFontGL::RIGHT, LLFontGL::TOP); + last_label = begin; + } + else + { + gl_rect_2d(begin, bar_top, end, bar_bottom - tick_length/2, LLColor4(1.f, 1.f, 1.f, 0.1f)); + } } } @@ -457,12 +471,11 @@ void LLStatBar::setStat(const std::string& stat_name) } -void LLStatBar::setRange(F32 bar_min, F32 bar_max, F32 tick_spacing, F32 label_spacing) +void LLStatBar::setRange(F32 bar_min, F32 bar_max, F32 tick_spacing) { mMinBar = bar_min; mMaxBar = bar_max; mTickSpacing = tick_spacing; - mLabelSpacing = label_spacing; } LLRect LLStatBar::getRequiredRect() @@ -473,14 +486,7 @@ LLRect LLStatBar::getRequiredRect() { if (mDisplayHistory) { - if (mOrientation == HORIZONTAL) - { - rect.mTop = mMaxHeight; - } - else - { - rect.mTop = 35 + llmin(mMaxHeight, llmin(mNumFrames, (S32)LLTrace::get_frame_recording().getNumPeriods())); - } + rect.mTop = mMaxHeight; } else { @@ -493,3 +499,4 @@ LLRect LLStatBar::getRequiredRect() } return rect; } + diff --git a/indra/llui/llstatbar.h b/indra/llui/llstatbar.h index 74a3ebde2f..db667aa07d 100644 --- a/indra/llui/llstatbar.h +++ b/indra/llui/llstatbar.h @@ -43,7 +43,6 @@ public: Optional bar_min, bar_max, tick_spacing, - label_spacing, update_rate, unit_scale; @@ -66,7 +65,6 @@ public: bar_min("bar_min", 0.0f), bar_max("bar_max", 50.0f), tick_spacing("tick_spacing", 10.0f), - label_spacing("label_spacing", 10.0f), precision("precision", 0), update_rate("update_rate", 5.0f), unit_scale("unit_scale", 1.f), @@ -90,7 +88,7 @@ public: void setStat(const std::string& stat_name); - void setRange(F32 bar_min, F32 bar_max, F32 tick_spacing, F32 label_spacing); + void setRange(F32 bar_min, F32 bar_max, F32 tick_spacing); void getRange(F32& bar_min, F32& bar_max) { bar_min = mMinBar; bar_max = mMaxBar; } /*virtual*/ LLRect getRequiredRect(); // Return the height of this object, given the set options. diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index 7fcebc965a..dbdf3e5e9f 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -85,7 +85,7 @@ void LLFloaterJoystick::draw() if (llabs(value) > maxbar) { F32 range = llabs(value); - mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f); + mAxisStatsBar[i]->setRange(-range, range, range * 0.25f); } } } @@ -106,7 +106,7 @@ BOOL LLFloaterJoystick::postBuild() if (mAxisStatsBar[i]) { mAxisStatsBar[i]->setStat(stat_name); - mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f); + mAxisStatsBar[i]->setRange(-range, range, range * 0.25f); } } diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp index 12eea513da..9401773886 100644 --- a/indra/newview/llworld.cpp +++ b/indra/newview/llworld.cpp @@ -728,7 +728,8 @@ void LLWorld::updateNetStats() add(LLStatViewer::PACKETS_LOST, packets_lost); if (packets_in) { - sample(LLStatViewer::PACKETS_LOST_PERCENT, 100.f * ((F32)packets_lost/(F32)packets_in)); + F32 packet_loss = 100.f * ((F32)packets_lost/(F32)packets_in); + sample(LLStatViewer::PACKETS_LOST_PERCENT, packet_loss); } mLastPacketsIn = gMessageSystem->mPacketsIn; diff --git a/indra/newview/skins/default/xui/en/floater_scene_load_stats.xml b/indra/newview/skins/default/xui/en/floater_scene_load_stats.xml index f4021d210a..246e8bb256 100644 --- a/indra/newview/skins/default/xui/en/floater_scene_load_stats.xml +++ b/indra/newview/skins/default/xui/en/floater_scene_load_stats.xml @@ -8,7 +8,8 @@ save_visibility="true" title="SCENE LOAD STATISTICS" width="260"> -