diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llstat.h | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llstat.h b/linden/indra/llcommon/llstat.h new file mode 100644 index 0000000..09b6028 --- /dev/null +++ b/linden/indra/llcommon/llstat.h | |||
@@ -0,0 +1,201 @@ | |||
1 | /** | ||
2 | * @file llstat.h | ||
3 | * @brief Runtime statistics accumulation. | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLSTAT_H | ||
29 | #define LL_LLSTAT_H | ||
30 | |||
31 | #include <deque> | ||
32 | |||
33 | #include "lltimer.h" | ||
34 | #include "llframetimer.h" | ||
35 | |||
36 | // | ||
37 | // Accumulates statistics for an arbitrary length of time. | ||
38 | // Does this by maintaining a chain of accumulators, each one | ||
39 | // accumulation the results of the parent. Can scale to arbitrary | ||
40 | // amounts of time with very low memory cost. | ||
41 | // | ||
42 | |||
43 | class LLStatAccum | ||
44 | { | ||
45 | protected: | ||
46 | LLStatAccum(bool use_frame_timer); | ||
47 | virtual ~LLStatAccum(); | ||
48 | |||
49 | public: | ||
50 | enum TimeScale { | ||
51 | SCALE_SECOND, | ||
52 | SCALE_MINUTE, | ||
53 | SCALE_TWO_MINUTE, | ||
54 | SCALE_HOUR, | ||
55 | SCALE_DAY, | ||
56 | SCALE_WEEK, | ||
57 | |||
58 | NUM_SCALES | ||
59 | }; | ||
60 | |||
61 | F32 meanValue(TimeScale scale) const; | ||
62 | // see the subclasses for the specific meaning of value | ||
63 | |||
64 | F32 meanValueOverLastSecond() const { return meanValue(SCALE_SECOND); } | ||
65 | F32 meanValueOverLastMinute() const { return meanValue(SCALE_MINUTE); } | ||
66 | |||
67 | protected: | ||
68 | class impl; | ||
69 | impl& m; | ||
70 | }; | ||
71 | |||
72 | class LLStatMeasure : public LLStatAccum | ||
73 | // gathers statistics about things that are measured | ||
74 | // ex.: tempature, time dilation | ||
75 | { | ||
76 | public: | ||
77 | LLStatMeasure(bool use_frame_timer = true); | ||
78 | |||
79 | void sample(F64); | ||
80 | void sample(S32 v) { sample((F64)v); } | ||
81 | void sample(U32 v) { sample((F64)v); } | ||
82 | void sample(S64 v) { sample((F64)v); } | ||
83 | void sample(U64 v) { sample((F64)v); } | ||
84 | }; | ||
85 | |||
86 | |||
87 | class LLStatRate : public LLStatAccum | ||
88 | // gathers statistics about things that can be counted over time | ||
89 | // ex.: LSL instructions executed, messages sent, simulator frames completed | ||
90 | // renders it in terms of rate of thing per second | ||
91 | { | ||
92 | public: | ||
93 | LLStatRate(bool use_frame_timer = true); | ||
94 | |||
95 | void count(U32); | ||
96 | // used to note that n items have occured | ||
97 | |||
98 | void mark() { count(1); } | ||
99 | // used for counting the rate thorugh a point in the code | ||
100 | }; | ||
101 | |||
102 | |||
103 | class LLTimeBlock; | ||
104 | |||
105 | class LLStatTime : public LLStatAccum | ||
106 | // gathers statistics about time spent in a block of code | ||
107 | // measure average duration per second in the block | ||
108 | { | ||
109 | public: | ||
110 | LLStatTime(bool use_frame_timer = false); | ||
111 | |||
112 | private: | ||
113 | void start(); | ||
114 | void stop(); | ||
115 | friend class LLTimeBlock; | ||
116 | }; | ||
117 | |||
118 | class LLTimeBlock | ||
119 | { | ||
120 | public: | ||
121 | LLTimeBlock(LLStatTime& stat) : mStat(stat) { mStat.start(); } | ||
122 | ~LLTimeBlock() { mStat.stop(); } | ||
123 | private: | ||
124 | LLStatTime& mStat; | ||
125 | }; | ||
126 | |||
127 | |||
128 | |||
129 | |||
130 | |||
131 | class LLStat | ||
132 | { | ||
133 | public: | ||
134 | LLStat(const U32 num_bins = 32, BOOL use_frame_timer = FALSE); | ||
135 | ~LLStat(); | ||
136 | |||
137 | void reset(); | ||
138 | |||
139 | void start(); // Start the timer for the current "frame", otherwise uses the time tracked from | ||
140 | // the last addValue | ||
141 | void addValue(const F32 value = 1.f); // Adds the current value being tracked, and tracks the DT. | ||
142 | void addValue(const S32 value) { addValue((F32)value); } | ||
143 | void addValue(const U32 value) { addValue((F32)value); } | ||
144 | |||
145 | void setBeginTime(const F64 time); | ||
146 | void addValueTime(const F64 time, const F32 value = 1.f); | ||
147 | |||
148 | S32 getCurBin() const; | ||
149 | S32 getNextBin() const; | ||
150 | |||
151 | F32 getCurrent() const; | ||
152 | F32 getCurrentPerSec() const; | ||
153 | F64 getCurrentBeginTime() const; | ||
154 | F64 getCurrentTime() const; | ||
155 | F32 getCurrentDuration() const; | ||
156 | |||
157 | F32 getPrev(S32 age) const; // Age is how many "addValues" previously - zero is current | ||
158 | F32 getPrevPerSec(S32 age) const; // Age is how many "addValues" previously - zero is current | ||
159 | F64 getPrevBeginTime(S32 age) const; | ||
160 | F64 getPrevTime(S32 age) const; | ||
161 | |||
162 | F32 getBin(S32 bin) const; | ||
163 | F32 getBinPerSec(S32 bin) const; | ||
164 | F64 getBinBeginTime(S32 bin) const; | ||
165 | F64 getBinTime(S32 bin) const; | ||
166 | |||
167 | F32 getMax() const; | ||
168 | F32 getMaxPerSec() const; | ||
169 | |||
170 | F32 getMean() const; | ||
171 | F32 getMeanPerSec() const; | ||
172 | F32 getMeanDuration() const; | ||
173 | |||
174 | F32 getMin() const; | ||
175 | F32 getMinPerSec() const; | ||
176 | F32 getMinDuration() const; | ||
177 | |||
178 | F32 getSum() const; | ||
179 | F32 getSumDuration() const; | ||
180 | |||
181 | U32 getNumValues() const; | ||
182 | S32 getNumBins() const; | ||
183 | |||
184 | F64 getLastTime() const; | ||
185 | private: | ||
186 | BOOL mUseFrameTimer; | ||
187 | U32 mNumValues; | ||
188 | U32 mNumBins; | ||
189 | F32 mLastValue; | ||
190 | F64 mLastTime; | ||
191 | F32 *mBins; | ||
192 | F64 *mBeginTime; | ||
193 | F64 *mTime; | ||
194 | F32 *mDT; | ||
195 | S32 mCurBin; | ||
196 | S32 mNextBin; | ||
197 | static LLTimer sTimer; | ||
198 | static LLFrameTimer sFrameTimer; | ||
199 | }; | ||
200 | |||
201 | #endif // LL_STAT_ | ||