1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/**
* @file llviewerassetstats.h
* @brief Client-side collection of asset request statistics
*
* $LicenseInfo:firstyear=2010&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLVIEWERASSETSTATUS_H
#define LL_LLVIEWERASSETSTATUS_H
#include "linden_common.h"
#include "llpointer.h"
#include "llrefcount.h"
#include "llviewerassettype.h"
#include "llviewerassetstorage.h"
#include "llsimplestat.h"
#include "llsd.h"
#include "llvoavatar.h"
#include "lltrace.h"
#include "llinitparam.h"
/**
* @class LLViewerAssetStats
* @brief Records performance aspects of asset access operations.
*
* This facility is derived from a very similar simulator-based
* one, LLSimAssetStats. It's function is to count asset access
* operations and characterize response times. Collected data
* are binned in several dimensions:
*
* - Asset types collapsed into a few aggregated categories
* - By simulator UUID
* - By transport mechanism (HTTP vs MessageSystem)
* - By persistence (temp vs non-temp)
*
* Statistics collected are fairly basic at this point:
*
* - Counts of enqueue and dequeue operations
* - Min/Max/Mean of asset transfer operations
*
* This collector differs from the simulator-based on in a
* number of ways:
*
* - The front-end/back-end distinction doesn't exist in viewer
* code
* - Multiple threads must be safely accomodated in the viewer
*
* Access to results is by conversion to an LLSD with some standardized
* key names. The intent of this structure is that it be emitted as
* standard syslog-based metrics formatting where it can be picked
* up by interested parties.
*
* For convenience, a set of free functions in namespace
* LLViewerAssetStatsFF is provided for conditional test-and-call
* operations.
*/
class LLViewerAssetStats : public LLStopWatchControlsMixin<LLViewerAssetStats>
{
public:
/**
* Type for duration and other time values in the metrics. Selected
* for compatibility with the pre-existing timestamp on the texture
* fetcher class, LLTextureFetch.
*/
typedef LLUnit<LLUnits::Microseconds, U64> duration_t;
/**
* Type for the region identifier used in stats. Currently uses
* the region handle's type (a U64) rather than the regions's LLUUID
* as the latter isn't available immediately.
*/
typedef U64 region_handle_t;
struct AssetRequestType : public LLInitParam::Block<AssetRequestType>
{
Mandatory<S32> enqueued,
dequeued,
resp_count;
Mandatory<F64> resp_min,
resp_max,
resp_mean;
AssetRequestType();
};
struct FPSStats : public LLInitParam::Block<FPSStats>
{
Mandatory<S32> count;
Mandatory<F64> min,
max,
mean;
FPSStats();
};
struct RegionStats : public LLInitParam::Block<RegionStats>
{
Optional<AssetRequestType> get_texture_temp_http,
get_texture_temp_udp,
get_texture_non_temp_http,
get_texture_non_temp_udp,
get_wearable_udp,
get_sound_udp,
get_gesture_udp,
get_other;
Optional<FPSStats> fps;
Optional<S32> grid_x,
grid_y;
Optional<F64> duration;
RegionStats();
};
struct AvatarRezState : public LLInitParam::Block<AvatarRezState>
{
Mandatory<S32> cloud,
gray,
textured;
AvatarRezState();
};
struct AvatarPhaseStats : public LLInitParam::Block<AvatarPhaseStats>
{
Mandatory<LLSD> cloud,
cloud_or_gray;
AvatarPhaseStats()
: cloud("cloud"),
cloud_or_gray("cloud-or-gray")
{}
};
struct AvatarInfo : public LLInitParam::Block<AvatarInfo>
{
Optional<AvatarRezState> nearby;
Optional<AvatarPhaseStats> phase_stats;
AvatarInfo();
};
struct AssetStats : public LLInitParam::Block<AssetStats>
{
Multiple<RegionStats> regions;
Mandatory<F64> duration;
Mandatory<AvatarInfo> avatar;
Mandatory<LLUUID> session_id,
agent_id;
Mandatory<std::string> message;
Mandatory<S32> sequence;
Mandatory<bool> initial,
break_;
AssetStats();
};
public:
LLViewerAssetStats();
LLViewerAssetStats(const LLViewerAssetStats &);
// Default destructor is correct.
LLViewerAssetStats & operator=(const LLViewerAssetStats &); // Not defined
// Clear all metrics data. This leaves the currently-active region
// in place but with zero'd data for all metrics. All other regions
// are removed from the collection map.
void reset();
// Set hidden region argument and establish context for subsequent
// collection calls.
void setRegion(region_handle_t region_handle);
// Avatar-related statistics
void recordAvatarStats();
// gather latest metrics data
// call from main thread
void updateStats();
// Retrieve current metrics for all visited regions (NULL region UUID/handle excluded)
// Uses AssetStats structure seen above
void getStats(AssetStats& stats, bool compact_output);
LLSD asLLSD(bool compact_output);
protected:
void handleStart();
void handleStop();
void handleReset();
typedef std::map<region_handle_t, LLTrace::Recording > PerRegionRecordingContainer;
// Region of the currently-active region. Always valid but may
// be zero after construction or when explicitly set. Unchanged
// by a reset() call.
region_handle_t mRegionHandle;
// Pointer to metrics collection for currently-active region.
LLTrace::Recording* mCurRecording;
// Metrics data for all regions during one collection cycle
PerRegionRecordingContainer mRegionRecordings;
// Nearby avatar stats
std::vector<S32> mAvatarRezStates;
LLViewerStats::phase_stats_t mPhaseStats;
};
/**
* Global stats collectors one for each independent thread where
* assets and other statistics are gathered. The globals are
* expected to be created at startup time and then picked up by
* their respective threads afterwards. A set of free functions
* are provided to access methods behind the globals while both
* minimally disrupting visual flow and supplying a description
* of intent.
*
* Expected thread assignments:
*
* - Main: main() program execution thread
* - Thread1: TextureFetch worker thread
*/
extern LLViewerAssetStats * gViewerAssetStats;
namespace LLViewerAssetStatsFF
{
enum EViewerAssetCategories
{
EVACTextureTempHTTPGet, //< Texture GETs - temp/baked, HTTP
EVACTextureTempUDPGet, //< Texture GETs - temp/baked, UDP
EVACTextureNonTempHTTPGet, //< Texture GETs - perm, HTTP
EVACTextureNonTempUDPGet, //< Texture GETs - perm, UDP
EVACWearableUDPGet, //< Wearable GETs
EVACSoundUDPGet, //< Sound GETs
EVACGestureUDPGet, //< Gesture GETs
EVACOtherGet, //< Other GETs
EVACCount // Must be last
};
/**
* @brief Allocation and deallocation of globals.
*
* init() should be called before threads are started that will access it though
* you'll likely get away with calling it afterwards. cleanup() should only be
* called after threads are shutdown to prevent races on the global pointers.
*/
void init();
void cleanup();
/**
* We have many timers, clocks etc. in the runtime. This is the
* canonical timestamp for these metrics which is compatible with
* the pre-existing timestamping in the texture fetcher.
*/
inline LLViewerAssetStats::duration_t get_timestamp()
{
return LLTimer::getTotalTime();
}
/**
* Region context, event and duration loggers for the Main thread.
*/
void set_region(LLViewerAssetStats::region_handle_t region_handle);
void record_enqueue(LLViewerAssetType::EType at, bool with_http, bool is_temp);
void record_dequeue(LLViewerAssetType::EType at, bool with_http, bool is_temp);
void record_response(LLViewerAssetType::EType at, bool with_http, bool is_temp,
LLViewerAssetStats::duration_t duration);
void record_avatar_stats();
} // namespace LLViewerAssetStatsFF
#endif // LL_LLVIEWERASSETSTATUS_H
|