llstat.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @file llstat.h
  3. * @brief Runtime statistics accumulation.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLSTAT_H
  33. #define LL_LLSTAT_H
  34. #include "llframetimer.h"
  35. class LLSD;
  36. class LLStat
  37. {
  38. public:
  39. LLStat(U32 num_bins = 32, bool use_frame_timer = false);
  40. ~LLStat();
  41. void reset();
  42. // Start the timer for the current "frame", otherwise uses the time tracked
  43. // from the last addValue
  44. void start();
  45. // Adds the current value being tracked, and tracks the DT.
  46. void addValue(F32 value = 1.f);
  47. LL_INLINE void addValue(S32 value) { addValue((F32)value); }
  48. LL_INLINE void addValue(U32 value) { addValue((F32)value); }
  49. LL_INLINE void setBeginTime(F64 time) { mBeginTime[mNextBin] = time; }
  50. void addValueTime(F64 time, F32 value = 1.f);
  51. LL_INLINE S32 getCurBin() const { return mCurBin; }
  52. LL_INLINE S32 getNextBin() const { return mNextBin; }
  53. LL_INLINE F32 getCurrent() const { return mBins[mCurBin]; }
  54. LL_INLINE F32 getCurrentPerSec() const { return mBins[mCurBin] / mDT[mCurBin]; }
  55. LL_INLINE F64 getCurrentBeginTime() const { return mBeginTime[mCurBin]; }
  56. LL_INLINE F64 getCurrentTime() const { return mTime[mCurBin]; }
  57. LL_INLINE F32 getCurrentDuration() const { return mDT[mCurBin]; }
  58. // Age is how many "addValues" previously - zero is current
  59. F32 getPrev(S32 age) const;
  60. F32 getPrevPerSec(S32 age) const;
  61. F64 getPrevBeginTime(S32 age) const;
  62. F64 getPrevTime(S32 age) const;
  63. LL_INLINE F32 getBin(S32 bin) const { return mBins[bin]; }
  64. LL_INLINE F32 getBinPerSec(S32 bin) const { return mBins[bin] / mDT[bin]; }
  65. LL_INLINE F64 getBinBeginTime(S32 bin) const { return mBeginTime[bin]; }
  66. LL_INLINE F64 getBinTime(S32 bin) const { return mTime[bin]; }
  67. F32 getMax() const;
  68. F32 getMaxPerSec() const;
  69. F32 getMean() const;
  70. F32 getMeanPerSec() const;
  71. F32 getMeanDuration() const;
  72. F32 getMin() const;
  73. F32 getMinPerSec() const;
  74. F32 getMinDuration() const;
  75. F32 getSum() const;
  76. F32 getSumDuration() const;
  77. LL_INLINE U32 getNumValues() const { return mNumValues; }
  78. LL_INLINE S32 getNumBins() const { return mNumBins; }
  79. LL_INLINE F64 getLastTime() const { return mLastTime; }
  80. private:
  81. void init();
  82. private:
  83. U32 mNumValues;
  84. U32 mNumBins;
  85. F32 mLastValue;
  86. F64 mLastTime;
  87. F32* mBins;
  88. F64* mBeginTime;
  89. F64* mTime;
  90. F32* mDT;
  91. S32 mCurBin;
  92. S32 mNextBin;
  93. bool mUseFrameTimer;
  94. static LLTimer sTimer;
  95. static LLFrameTimer sFrameTimer;
  96. };
  97. #endif // LL_LLSTAT_H