summaryrefslogtreecommitdiff
path: root/indra/llui/llstatbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/llstatbar.cpp')
-rw-r--r--indra/llui/llstatbar.cpp376
1 files changed, 292 insertions, 84 deletions
diff --git a/indra/llui/llstatbar.cpp b/indra/llui/llstatbar.cpp
index 04cce7878e..cda40aac72 100644
--- a/indra/llui/llstatbar.cpp
+++ b/indra/llui/llstatbar.cpp
@@ -34,8 +34,9 @@
#include "llgl.h"
#include "llfontgl.h"
-#include "llstat.h"
#include "lluictrlfactory.h"
+#include "lltracerecording.h"
+#include "llcriticaldamp.h"
///////////////////////////////////////////////////////////////////////////////////
@@ -45,17 +46,25 @@ LLStatBar::LLStatBar(const Params& p)
mUnitLabel(p.unit_label),
mMinBar(p.bar_min),
mMaxBar(p.bar_max),
- mStatp(LLStat::getStat(p.stat)),
+ mCurMaxBar(p.bar_max),
+ mCountFloatp(LLTrace::CountStatHandle<>::getInstance(p.stat)),
+ mCountIntp(LLTrace::CountStatHandle<S64>::getInstance(p.stat)),
+ mMeasurementFloatp(LLTrace::MeasurementStatHandle<>::getInstance(p.stat)),
+ mMeasurementIntp(LLTrace::MeasurementStatHandle<S64>::getInstance(p.stat)),
mTickSpacing(p.tick_spacing),
mLabelSpacing(p.label_spacing),
mPrecision(p.precision),
mUpdatesPerSec(p.update_rate),
+ mUnitScale(p.unit_scale),
+ mNumFrames(p.num_frames),
+ mMaxHeight(p.max_height),
mPerSec(p.show_per_sec),
mDisplayBar(p.show_bar),
mDisplayHistory(p.show_history),
- mDisplayMean(p.show_mean)
-{
-}
+ mDisplayMean(p.show_mean),
+ mOrientation(p.orientation),
+ mScaleRange(p.scale_range)
+{}
BOOL LLStatBar::handleMouseDown(S32 x, S32 y, MASK mask)
{
@@ -79,34 +88,84 @@ BOOL LLStatBar::handleMouseDown(S32 x, S32 y, MASK mask)
LLView* parent = getParent();
parent->reshape(parent->getRect().getWidth(), parent->getRect().getHeight(), FALSE);
- return FALSE;
+ return TRUE;
}
void LLStatBar::draw()
{
- if (!mStatp)
+ F32 current = 0.f,
+ min = 0.f,
+ max = 0.f,
+ mean = 0.f;
+
+ S32 num_samples = 0;
+ LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording();
+
+ if (mCountFloatp)
{
-// llinfos << "No stats for statistics bar!" << llendl;
- return;
+ LLTrace::Recording& last_frame_recording = frame_recording.getLastRecordingPeriod();
+
+ if (mPerSec)
+ {
+ current = last_frame_recording.getPerSec(*mCountFloatp);
+ min = frame_recording.getPeriodMinPerSec(*mCountFloatp);
+ max = frame_recording.getPeriodMaxPerSec(*mCountFloatp);
+ mean = frame_recording.getPeriodMeanPerSec(*mCountFloatp);
+ num_samples = frame_recording.getTotalRecording().getSampleCount(*mCountFloatp);
+ }
+ else
+ {
+ current = last_frame_recording.getSum(*mCountFloatp);
+ min = frame_recording.getPeriodMin(*mCountFloatp);
+ max = frame_recording.getPeriodMax(*mCountFloatp);
+ mean = frame_recording.getPeriodMean(*mCountFloatp);
+ num_samples = frame_recording.getTotalRecording().getSampleCount(*mCountFloatp);
+ }
}
+ else if (mCountIntp)
+ {
+ LLTrace::Recording& last_frame_recording = frame_recording.getLastRecordingPeriod();
- // Get the values.
- F32 current, min, max, mean;
- if (mPerSec)
+ if (mPerSec)
+ {
+ current = last_frame_recording.getPerSec(*mCountIntp);
+ min = frame_recording.getPeriodMinPerSec(*mCountIntp);
+ max = frame_recording.getPeriodMaxPerSec(*mCountIntp);
+ mean = frame_recording.getPeriodMeanPerSec(*mCountIntp);
+ num_samples = frame_recording.getTotalRecording().getSampleCount(*mCountIntp);
+ }
+ else
+ {
+ current = last_frame_recording.getSum(*mCountIntp);
+ min = frame_recording.getPeriodMin(*mCountIntp);
+ max = frame_recording.getPeriodMax(*mCountIntp);
+ mean = frame_recording.getPeriodMean(*mCountIntp);
+ num_samples = frame_recording.getTotalRecording().getSampleCount(*mCountIntp);
+ }
+ }
+ else if (mMeasurementFloatp)
{
- current = mStatp->getCurrentPerSec();
- min = mStatp->getMinPerSec();
- max = mStatp->getMaxPerSec();
- mean = mStatp->getMeanPerSec();
+ LLTrace::Recording& recording = frame_recording.getTotalRecording();
+ current = recording.getLastValue(*mMeasurementFloatp);
+ min = recording.getMin(*mMeasurementFloatp);
+ max = recording.getMax(*mMeasurementFloatp);
+ mean = recording.getMean(*mMeasurementFloatp);
+ num_samples = frame_recording.getTotalRecording().getSampleCount(*mMeasurementFloatp);
}
- else
+ else if (mMeasurementIntp)
{
- current = mStatp->getCurrent();
- min = mStatp->getMin();
- max = mStatp->getMax();
- mean = mStatp->getMean();
+ LLTrace::Recording& recording = frame_recording.getTotalRecording();
+ current = recording.getLastValue(*mMeasurementIntp);
+ min = recording.getMin(*mMeasurementIntp);
+ max = recording.getMax(*mMeasurementIntp);
+ mean = recording.getMean(*mMeasurementIntp);
+ num_samples = frame_recording.getTotalRecording().getSampleCount(*mMeasurementIntp);
}
+ current *= mUnitScale;
+ min *= mUnitScale;
+ max *= mUnitScale;
+ mean *= mUnitScale;
if ((mUpdatesPerSec == 0.f) || (mUpdateTimer.getElapsedTimeF32() > 1.f/mUpdatesPerSec) || (mValue == 0.f))
{
@@ -121,15 +180,41 @@ void LLStatBar::draw()
mUpdateTimer.reset();
}
- S32 width = getRect().getWidth() - 40;
- S32 max_width = width;
- S32 bar_top = getRect().getHeight() - 15; // 16 pixels from top.
- S32 bar_height = bar_top - 20;
- S32 tick_height = 4;
- S32 tick_width = 1;
- S32 left, top, right, bottom;
+ S32 bar_top, bar_left, bar_right, bar_bottom;
+ if (mOrientation == HORIZONTAL)
+ {
+ bar_top = llmax(5, getRect().getHeight() - 15);
+ bar_left = 0;
+ bar_right = getRect().getWidth() - 40;
+ bar_bottom = llmin(bar_top - 5, 0);
+ }
+ else // VERTICAL
+ {
+ bar_top = llmax(5, getRect().getHeight() - 15);
+ bar_left = 0;
+ bar_right = getRect().getWidth();
+ bar_bottom = llmin(bar_top - 5, 20);
+ }
+ const S32 tick_length = 4;
+ const S32 tick_width = 1;
+
+ if (mScaleRange && num_samples)
+ {
+ F32 cur_max = mLabelSpacing;
+ while(max > cur_max)
+ {
+ cur_max += mLabelSpacing;
+ }
+ mCurMaxBar = LLSmoothInterpolation::lerp(mCurMaxBar, cur_max, 0.05f);
+ }
+ else
+ {
+ mCurMaxBar = mMaxBar;
+ }
- F32 value_scale = max_width/(mMaxBar - mMinBar);
+ F32 value_scale = (mOrientation == HORIZONTAL)
+ ? (bar_top - bar_bottom)/(mCurMaxBar - mMinBar)
+ : (bar_right - bar_left)/(mCurMaxBar - mMinBar);
LLFontGL::getFontMonospace()->renderUTF8(mLabel, 0, 0, getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, 1.f),
LLFontGL::LEFT, LLFontGL::TOP);
@@ -148,114 +233,230 @@ void LLStatBar::draw()
}
// Draw the value.
- LLFontGL::getFontMonospace()->renderUTF8(value_str, 0, width, getRect().getHeight(),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLFontGL::RIGHT, LLFontGL::TOP);
+ if (mOrientation == HORIZONTAL)
+ {
+ LLFontGL::getFontMonospace()->renderUTF8(value_str, 0, bar_right, getRect().getHeight(),
+ LLColor4(1.f, 1.f, 1.f, 0.5f),
+ LLFontGL::RIGHT, LLFontGL::TOP);
+ }
+ else
+ {
+ LLFontGL::getFontMonospace()->renderUTF8(value_str, 0, bar_right, getRect().getHeight(),
+ LLColor4(1.f, 1.f, 1.f, 0.5f),
+ LLFontGL::RIGHT, LLFontGL::TOP);
+ }
value_format = llformat( "%%.%df", mPrecision);
- if (mDisplayBar)
+ if (mDisplayBar && (mCountFloatp || mCountIntp || mMeasurementFloatp || mMeasurementIntp))
{
std::string tick_label;
// Draw the tick marks.
- F32 tick_value;
- top = bar_top;
- bottom = bar_top - bar_height - tick_height/2;
-
LLGLSUIDefault gls_ui;
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- for (tick_value = mMinBar; tick_value <= mMaxBar; tick_value += mTickSpacing)
+ for (F32 tick_value = mMinBar + mLabelSpacing; tick_value <= mCurMaxBar; tick_value += mTickSpacing)
{
- left = llfloor((tick_value - mMinBar)*value_scale);
- right = left + tick_width;
- gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.1f));
+ const S32 begin = llfloor((tick_value - mMinBar)*value_scale);
+ const S32 end = begin + tick_width;
+ if (mOrientation == HORIZONTAL)
+ {
+ 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/2, LLColor4(1.f, 1.f, 1.f, 0.1f));
+ }
}
// Draw the tick labels (and big ticks).
- bottom = bar_top - bar_height - tick_height;
- for (tick_value = mMinBar; tick_value <= mMaxBar; tick_value += mLabelSpacing)
+ for (F32 tick_value = mMinBar + mLabelSpacing; tick_value <= mCurMaxBar; tick_value += mLabelSpacing)
{
- left = llfloor((tick_value - mMinBar)*value_scale);
- right = left + tick_width;
- gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.25f));
-
+ 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
- LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, left - 1, bar_top - bar_height - tick_height,
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLFontGL::LEFT, LLFontGL::TOP);
+ 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);
+ }
+ 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);
+ }
}
- // Now, draw the bars
- top = bar_top;
- bottom = bar_top - bar_height;
-
// draw background bar.
- left = 0;
- right = width;
- gl_rect_2d(left, top, right, bottom, LLColor4(0.f, 0.f, 0.f, 0.25f));
+ gl_rect_2d(bar_left, bar_top, bar_right, bar_bottom, LLColor4(0.f, 0.f, 0.f, 0.25f));
- if (mStatp->getNumValues() == 0)
+ if (frame_recording.getNumPeriods() == 0)
{
// No data, don't draw anything...
return;
}
+
// draw min and max
- left = (S32) ((min - mMinBar) * value_scale);
+ S32 begin = (S32) ((min - mMinBar) * value_scale);
- if (left < 0)
+ if (begin < 0)
{
- left = 0;
+ begin = 0;
llwarns << "Min:" << min << llendl;
}
- right = (S32) ((max - mMinBar) * value_scale);
- gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 0.25f));
+ S32 end = (S32) ((max - mMinBar) * value_scale);
+ if (mOrientation == HORIZONTAL)
+ {
+ gl_rect_2d(bar_left, end, bar_right, begin, LLColor4(1.f, 0.f, 0.f, 0.25f));
+ }
+ else // VERTICAL
+ {
+ gl_rect_2d(begin, bar_top, end, bar_bottom, LLColor4(1.f, 0.f, 0.f, 0.25f));
+ }
+
+ F32 span = (mOrientation == HORIZONTAL)
+ ? (bar_right - bar_left)
+ : (bar_top - bar_bottom);
- S32 num_values = mStatp->getNumValues() - 1;
- if (mDisplayHistory)
+ if (mDisplayHistory && (mCountFloatp || mCountIntp || mMeasurementFloatp || mMeasurementIntp))
{
+ const S32 num_values = frame_recording.getNumPeriods() - 1;
+ F32 begin = 0;
+ F32 end = 0;
S32 i;
- for (i = 0; i < num_values; i++)
+ gGL.color4f( 1.f, 0.f, 0.f, 1.f );
+ gGL.begin( LLRender::QUADS );
+ const S32 max_frame = llmin(mNumFrames, num_values);
+ U32 num_samples = 0;
+ for (i = 1; i <= max_frame; i++)
{
- if (i == mStatp->getNextBin())
+ F32 offset = ((F32)i / (F32)mNumFrames) * span;
+ LLTrace::Recording& recording = frame_recording.getPrevRecordingPeriod(i);
+ if (mPerSec)
{
- continue;
+ if (mCountFloatp)
+ {
+ begin = ((recording.getPerSec(*mCountFloatp) - mMinBar) * value_scale);
+ end = ((recording.getPerSec(*mCountFloatp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mCountFloatp);
+ }
+ else if (mCountIntp)
+ {
+ begin = ((recording.getPerSec(*mCountIntp) - mMinBar) * value_scale);
+ end = ((recording.getPerSec(*mCountIntp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mCountIntp);
+ }
+ else if (mMeasurementFloatp)
+ {
+ //rate isn't defined for measurement stats, so use mean
+ begin = ((recording.getMean(*mMeasurementFloatp) - mMinBar) * value_scale);
+ end = ((recording.getMean(*mMeasurementFloatp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mMeasurementFloatp);
+ }
+ else if (mMeasurementIntp)
+ {
+ //rate isn't defined for measurement stats, so use mean
+ begin = ((recording.getMean(*mMeasurementIntp) - mMinBar) * value_scale);
+ end = ((recording.getMean(*mMeasurementIntp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mMeasurementIntp);
+ }
}
- if (mPerSec)
+ else
{
- left = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale);
- right = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale) + 1;
- gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
+ if (mCountFloatp)
+ {
+ begin = ((recording.getSum(*mCountFloatp) - mMinBar) * value_scale);
+ end = ((recording.getSum(*mCountFloatp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mCountFloatp);
+ }
+ else if (mCountIntp)
+ {
+ begin = ((recording.getSum(*mCountIntp) - mMinBar) * value_scale);
+ end = ((recording.getSum(*mCountIntp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mCountIntp);
+ }
+ else if (mMeasurementFloatp)
+ {
+ begin = ((recording.getMean(*mMeasurementFloatp) - mMinBar) * value_scale);
+ end = ((recording.getMean(*mMeasurementFloatp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mMeasurementFloatp);
+ }
+ else if (mMeasurementIntp)
+ {
+ begin = ((recording.getMean(*mMeasurementIntp) - mMinBar) * value_scale);
+ end = ((recording.getMean(*mMeasurementIntp) - mMinBar) * value_scale) + 1;
+ num_samples = recording.getSampleCount(*mMeasurementIntp);
+ }
+ }
+
+ if (!num_samples) continue;
+
+ if (mOrientation == HORIZONTAL)
+ {
+ gGL.vertex2f((F32)bar_right - offset, end);
+ gGL.vertex2f((F32)bar_right - offset, begin);
+ gGL.vertex2f((F32)bar_right - offset - 1.f, begin);
+ gGL.vertex2f((F32)bar_right - offset - 1.f, end);
}
else
{
- left = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale);
- right = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale) + 1;
- gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
+ gGL.vertex2i(begin, (F32)bar_bottom+offset+1.f);
+ gGL.vertex2i(begin, (F32)bar_bottom+offset);
+ gGL.vertex2i(end, (F32)bar_bottom+offset);
+ gGL.vertex2i(end, (F32)bar_bottom+offset+1.f);
}
}
+ gGL.end();
}
else
{
+ S32 begin = (S32) ((current - mMinBar) * value_scale) - 1;
+ S32 end = (S32) ((current - mMinBar) * value_scale) + 1;
// draw current
- left = (S32) ((current - mMinBar) * value_scale) - 1;
- right = (S32) ((current - mMinBar) * value_scale) + 1;
- gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 1.f));
+ if (mOrientation == HORIZONTAL)
+ {
+ gl_rect_2d(bar_left, end, bar_right, begin, LLColor4(1.f, 0.f, 0.f, 1.f));
+ }
+ else
+ {
+ gl_rect_2d(begin, bar_top, end, bar_bottom, LLColor4(1.f, 0.f, 0.f, 1.f));
+ }
}
// draw mean bar
- top = bar_top + 2;
- bottom = bar_top - bar_height - 2;
- left = (S32) ((mean - mMinBar) * value_scale) - 1;
- right = (S32) ((mean - mMinBar) * value_scale) + 1;
- gl_rect_2d(left, top, right, bottom, LLColor4(0.f, 1.f, 0.f, 1.f));
+ {
+ const S32 begin = (S32) ((mean - mMinBar) * value_scale) - 1;
+ const S32 end = (S32) ((mean - mMinBar) * value_scale) + 1;
+ if (mOrientation == HORIZONTAL)
+ {
+ gl_rect_2d(bar_left - 2, begin, bar_right + 2, end, LLColor4(0.f, 1.f, 0.f, 1.f));
+ }
+ else
+ {
+ gl_rect_2d(begin, bar_top + 2, end, bar_bottom - 2, LLColor4(0.f, 1.f, 0.f, 1.f));
+ }
+ }
}
LLView::draw();
}
+void LLStatBar::setStat(const std::string& stat_name)
+{
+ mCountFloatp = LLTrace::CountStatHandle<>::getInstance(stat_name);
+ mCountIntp = LLTrace::CountStatHandle<S64>::getInstance(stat_name);
+ mMeasurementFloatp = LLTrace::MeasurementStatHandle<>::getInstance(stat_name);
+ mMeasurementIntp = LLTrace::MeasurementStatHandle<S64>::getInstance(stat_name);
+}
+
+
void LLStatBar::setRange(F32 bar_min, F32 bar_max, F32 tick_spacing, F32 label_spacing)
{
mMinBar = bar_min;
@@ -272,7 +473,14 @@ LLRect LLStatBar::getRequiredRect()
{
if (mDisplayHistory)
{
- rect.mTop = 35 + mStatp->getNumBins();
+ if (mOrientation == HORIZONTAL)
+ {
+ rect.mTop = mMaxHeight;
+ }
+ else
+ {
+ rect.mTop = 35 + llmin(mMaxHeight, llmin(mNumFrames, (S32)LLTrace::get_frame_recording().getNumPeriods()));
+ }
}
else
{