diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llstat.h | 142 |
1 files changed, 126 insertions, 16 deletions
diff --git a/linden/indra/llcommon/llstat.h b/linden/indra/llcommon/llstat.h index 0a7e014..63813e2 100644 --- a/linden/indra/llcommon/llstat.h +++ b/linden/indra/llcommon/llstat.h | |||
@@ -33,9 +33,13 @@ | |||
33 | #define LL_LLSTAT_H | 33 | #define LL_LLSTAT_H |
34 | 34 | ||
35 | #include <deque> | 35 | #include <deque> |
36 | #include <map> | ||
36 | 37 | ||
37 | #include "lltimer.h" | 38 | #include "lltimer.h" |
38 | #include "llframetimer.h" | 39 | #include "llframetimer.h" |
40 | #include "llfile.h" | ||
41 | |||
42 | class LLSD; | ||
39 | 43 | ||
40 | // Set this if longer stats are needed | 44 | // Set this if longer stats are needed |
41 | #define ENABLE_LONG_TIME_STATS 0 | 45 | #define ENABLE_LONG_TIME_STATS 0 |
@@ -58,25 +62,50 @@ public: | |||
58 | SCALE_100MS, | 62 | SCALE_100MS, |
59 | SCALE_SECOND, | 63 | SCALE_SECOND, |
60 | SCALE_MINUTE, | 64 | SCALE_MINUTE, |
61 | SCALE_TWO_MINUTE, | ||
62 | #if ENABLE_LONG_TIME_STATS | 65 | #if ENABLE_LONG_TIME_STATS |
63 | SCALE_HOUR, | 66 | SCALE_HOUR, |
64 | SCALE_DAY, | 67 | SCALE_DAY, |
65 | SCALE_WEEK, | 68 | SCALE_WEEK, |
66 | #endif | 69 | #endif |
67 | NUM_SCALES | 70 | NUM_SCALES, // Use to size storage arrays |
71 | SCALE_PER_FRAME // For latest frame information - should be after NUM_SCALES since this doesn't go into the time buckets | ||
68 | }; | 72 | }; |
69 | 73 | ||
70 | F32 meanValue(TimeScale scale) const; | 74 | static U64 sScaleTimes[NUM_SCALES]; |
75 | |||
76 | virtual F32 meanValue(TimeScale scale) const; | ||
71 | // see the subclasses for the specific meaning of value | 77 | // see the subclasses for the specific meaning of value |
72 | 78 | ||
73 | F32 meanValueOverLast100ms() const { return meanValue(SCALE_100MS); } | 79 | F32 meanValueOverLast100ms() const { return meanValue(SCALE_100MS); } |
74 | F32 meanValueOverLastSecond() const { return meanValue(SCALE_SECOND); } | 80 | F32 meanValueOverLastSecond() const { return meanValue(SCALE_SECOND); } |
75 | F32 meanValueOverLastMinute() const { return meanValue(SCALE_MINUTE); } | 81 | F32 meanValueOverLastMinute() const { return meanValue(SCALE_MINUTE); } |
76 | 82 | ||
77 | protected: | 83 | void reset(U64 when); |
78 | class impl; | 84 | |
79 | impl& m; | 85 | void sum(F64 value); |
86 | void sum(F64 value, U64 when); | ||
87 | |||
88 | U64 getCurrentUsecs() const; | ||
89 | // Get current microseconds based on timer type | ||
90 | |||
91 | BOOL mUseFrameTimer; | ||
92 | BOOL mRunning; | ||
93 | |||
94 | U64 mLastTime; | ||
95 | |||
96 | struct Bucket | ||
97 | { | ||
98 | F64 accum; | ||
99 | U64 endTime; | ||
100 | |||
101 | BOOL lastValid; | ||
102 | F64 lastAccum; | ||
103 | }; | ||
104 | |||
105 | Bucket mBuckets[NUM_SCALES]; | ||
106 | |||
107 | BOOL mLastSampleValid; | ||
108 | F64 mLastSampleValue; | ||
80 | }; | 109 | }; |
81 | 110 | ||
82 | class LLStatMeasure : public LLStatAccum | 111 | class LLStatMeasure : public LLStatAccum |
@@ -105,39 +134,120 @@ public: | |||
105 | void count(U32); | 134 | void count(U32); |
106 | // used to note that n items have occured | 135 | // used to note that n items have occured |
107 | 136 | ||
108 | void mark() { count(1); } | 137 | void mark(); |
109 | // used for counting the rate thorugh a point in the code | 138 | // used for counting the rate thorugh a point in the code |
110 | }; | 139 | }; |
111 | 140 | ||
112 | 141 | ||
113 | class LLTimeBlock; | ||
114 | |||
115 | class LLStatTime : public LLStatAccum | 142 | class LLStatTime : public LLStatAccum |
116 | // gathers statistics about time spent in a block of code | 143 | // gathers statistics about time spent in a block of code |
117 | // measure average duration per second in the block | 144 | // measure average duration per second in the block |
118 | { | 145 | { |
119 | public: | 146 | public: |
120 | LLStatTime(bool use_frame_timer = false); | 147 | LLStatTime( const std::string & key = "undefined" ); |
148 | |||
149 | U32 mFrameNumber; // Current frame number | ||
150 | U64 mTotalTimeInFrame; // Total time (microseconds) accumulated during the last frame | ||
151 | |||
152 | void setKey( const std::string & key ) { mKey = key; }; | ||
153 | |||
154 | virtual F32 meanValue(TimeScale scale) const; | ||
121 | 155 | ||
122 | private: | 156 | private: |
123 | void start(); | 157 | void start(); // Start and stop measuring time block |
124 | void stop(); | 158 | void stop(); |
125 | friend class LLTimeBlock; | 159 | |
160 | std::string mKey; // Tag representing this time block | ||
161 | |||
162 | #if LL_DEBUG | ||
163 | BOOL mRunning; // TRUE if start() has been called | ||
164 | #endif | ||
165 | |||
166 | friend class LLPerfBlock; | ||
126 | }; | 167 | }; |
127 | 168 | ||
128 | class LLTimeBlock | 169 | // ---------------------------------------------------------------------------- |
170 | |||
171 | |||
172 | // Use this class on the stack to record statistics about an area of code | ||
173 | class LLPerfBlock | ||
129 | { | 174 | { |
130 | public: | 175 | public: |
131 | LLTimeBlock(LLStatTime& stat) : mStat(stat) { mStat.start(); } | 176 | struct StatEntry |
132 | ~LLTimeBlock() { mStat.stop(); } | 177 | { |
178 | StatEntry(const std::string& key) : mStat(LLStatTime(key)), mCount(0) {} | ||
179 | LLStatTime mStat; | ||
180 | U32 mCount; | ||
181 | }; | ||
182 | typedef std::map<std::string, StatEntry*> stat_map_t; | ||
183 | |||
184 | // Use this constructor for pre-defined LLStatTime objects | ||
185 | LLPerfBlock(LLStatTime* stat); | ||
186 | |||
187 | // Use this constructor for dynamically created LLStatTime objects (not pre-defined) with a multi-part key | ||
188 | LLPerfBlock( const char* key1, const char* key2 = NULL); | ||
189 | |||
190 | |||
191 | ~LLPerfBlock(); | ||
192 | |||
193 | static void setStatsEnabled( BOOL enable ) { sStatsEnabled = enable; }; | ||
194 | static S32 getStatsEnabled() { return sStatsEnabled; }; | ||
195 | |||
196 | static void clearDynamicStats(); // Reset maps to clear out dynamic objects | ||
197 | static void addStatsToLLSDandReset( LLSD & stats, // Get current information and clear time bin | ||
198 | LLStatAccum::TimeScale scale ); | ||
199 | |||
133 | private: | 200 | private: |
134 | LLStatTime& mStat; | 201 | // Initialize dynamically created LLStatTime objects |
202 | void initDynamicStat(const std::string& key); | ||
203 | |||
204 | std::string mLastPath; // Save sCurrentStatPath when this is called | ||
205 | LLStatTime * mPredefinedStat; // LLStatTime object to get data | ||
206 | StatEntry * mDynamicStat; // StatEntryobject to get data | ||
207 | |||
208 | static BOOL sStatsEnabled; // Normally FALSE | ||
209 | static stat_map_t sStatMap; // Map full path string to LLStatTime objects | ||
210 | static std::string sCurrentStatPath; // Something like "frame/physics/physics step" | ||
135 | }; | 211 | }; |
136 | 212 | ||
213 | // ---------------------------------------------------------------------------- | ||
137 | 214 | ||
215 | class LLPerfStats | ||
216 | { | ||
217 | public: | ||
218 | LLPerfStats(const std::string& process_name = "unknown", S32 process_pid = 0); | ||
219 | virtual ~LLPerfStats(); | ||
220 | |||
221 | virtual void init(); // Reset and start all stat timers | ||
222 | virtual void updatePerFrameStats(); | ||
223 | // Override these function to add process-specific information to the performance log header and per-frame logging. | ||
224 | virtual void addProcessHeaderInfo(LLSD& info) { /* not implemented */ } | ||
225 | virtual void addProcessFrameInfo(LLSD& info, LLStatAccum::TimeScale scale) { /* not implemented */ } | ||
226 | |||
227 | // High-resolution frame stats | ||
228 | BOOL frameStatsIsRunning() { return (mReportPerformanceStatEnd > 0.); }; | ||
229 | F32 getReportPerformanceInterval() const { return mReportPerformanceStatInterval; }; | ||
230 | void setReportPerformanceInterval( F32 interval ) { mReportPerformanceStatInterval = interval; }; | ||
231 | void setReportPerformanceDuration( F32 seconds ); | ||
232 | void setProcessName(const std::string& process_name) { mProcessName = process_name; } | ||
233 | void setProcessPID(S32 process_pid) { mProcessPID = process_pid; } | ||
138 | 234 | ||
235 | protected: | ||
236 | void openPerfStatsFile(); // Open file for high resolution metrics logging | ||
237 | void dumpIntervalPerformanceStats(); | ||
238 | |||
239 | llofstream mFrameStatsFile; // File for per-frame stats | ||
240 | BOOL mFrameStatsFileFailure; // Flag to prevent repeat opening attempts | ||
241 | BOOL mSkipFirstFrameStats; // Flag to skip one (partial) frame report | ||
242 | std::string mProcessName; | ||
243 | S32 mProcessPID; | ||
139 | 244 | ||
245 | private: | ||
246 | F32 mReportPerformanceStatInterval; // Seconds between performance stats | ||
247 | F64 mReportPerformanceStatEnd; // End time (seconds) for performance stats | ||
248 | }; | ||
140 | 249 | ||
250 | // ---------------------------------------------------------------------------- | ||
141 | class LLStat | 251 | class LLStat |
142 | { | 252 | { |
143 | public: | 253 | public: |