diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/lltextureinfo.cpp | 290 |
1 files changed, 290 insertions, 0 deletions
diff --git a/linden/indra/newview/lltextureinfo.cpp b/linden/indra/newview/lltextureinfo.cpp new file mode 100644 index 0000000..672a36a --- /dev/null +++ b/linden/indra/newview/lltextureinfo.cpp | |||
@@ -0,0 +1,290 @@ | |||
1 | /** | ||
2 | * @file lltextureinfo.cpp | ||
3 | * @brief Object which handles local texture info | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2000&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2000-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 | |||
33 | #include "llviewerprecompiledheaders.h" | ||
34 | |||
35 | #include "lltextureinfo.h" | ||
36 | #include "lltexturestats.h" | ||
37 | #include "llviewercontrol.h" | ||
38 | |||
39 | LLTextureInfo::LLTextureInfo() : | ||
40 | mLogTextureDownloadsToViewerLog(false), | ||
41 | mLogTextureDownloadsToSimulator(false), | ||
42 | mTotalBytes(0), | ||
43 | mTotalMilliseconds(0), | ||
44 | mTextureDownloadsStarted(0), | ||
45 | mTextureDownloadsCompleted(0), | ||
46 | mTextureDownloadProtocol("NONE"), | ||
47 | mTextureLogThreshold(100 * 1024), | ||
48 | mCurrentStatsBundleStartTime(0) | ||
49 | { | ||
50 | mTextures.clear(); | ||
51 | } | ||
52 | |||
53 | void LLTextureInfo::setUpLogging(bool writeToViewerLog, bool sendToSim, U32 textureLogThreshold) | ||
54 | { | ||
55 | mLogTextureDownloadsToViewerLog = writeToViewerLog; | ||
56 | mLogTextureDownloadsToSimulator = sendToSim; | ||
57 | mTextureLogThreshold = textureLogThreshold; | ||
58 | } | ||
59 | |||
60 | LLTextureInfo::~LLTextureInfo() | ||
61 | { | ||
62 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator; | ||
63 | for (iterator = mTextures.begin(); iterator != mTextures.end(); iterator++) | ||
64 | { | ||
65 | LLTextureInfoDetails *info = (*iterator).second; | ||
66 | delete info; | ||
67 | } | ||
68 | |||
69 | mTextures.clear(); | ||
70 | } | ||
71 | |||
72 | void LLTextureInfo::addRequest(const LLUUID& id) | ||
73 | { | ||
74 | LLTextureInfoDetails *info = new LLTextureInfoDetails(); | ||
75 | mTextures[id] = info; | ||
76 | } | ||
77 | |||
78 | U32 LLTextureInfo::getTextureInfoMapSize() | ||
79 | { | ||
80 | return mTextures.size(); | ||
81 | } | ||
82 | |||
83 | bool LLTextureInfo::has(const LLUUID& id) | ||
84 | { | ||
85 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id); | ||
86 | if (iterator == mTextures.end()) | ||
87 | { | ||
88 | return false; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | return true; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | void LLTextureInfo::setRequestStartTime(const LLUUID& id, U64 startTime) | ||
97 | { | ||
98 | if (!has(id)) | ||
99 | { | ||
100 | addRequest(id); | ||
101 | } | ||
102 | mTextures[id]->mStartTime = startTime; | ||
103 | mTextureDownloadsStarted++; | ||
104 | } | ||
105 | |||
106 | void LLTextureInfo::setRequestSize(const LLUUID& id, U32 size) | ||
107 | { | ||
108 | if (!has(id)) | ||
109 | { | ||
110 | addRequest(id); | ||
111 | } | ||
112 | mTextures[id]->mSize = size; | ||
113 | } | ||
114 | |||
115 | void LLTextureInfo::setRequestOffset(const LLUUID& id, U32 offset) | ||
116 | { | ||
117 | if (!has(id)) | ||
118 | { | ||
119 | addRequest(id); | ||
120 | } | ||
121 | mTextures[id]->mOffset = offset; | ||
122 | } | ||
123 | |||
124 | void LLTextureInfo::setRequestType(const LLUUID& id, LLTextureInfoDetails::LLRequestType type) | ||
125 | { | ||
126 | if (!has(id)) | ||
127 | { | ||
128 | addRequest(id); | ||
129 | } | ||
130 | mTextures[id]->mType = type; | ||
131 | } | ||
132 | |||
133 | void LLTextureInfo::setRequestCompleteTimeAndLog(const LLUUID& id, U64 completeTime) | ||
134 | { | ||
135 | if (!has(id)) | ||
136 | { | ||
137 | addRequest(id); | ||
138 | } | ||
139 | mTextures[id]->mCompleteTime = completeTime; | ||
140 | |||
141 | std::string protocol = "NONE"; | ||
142 | switch(mTextures[id]->mType) | ||
143 | { | ||
144 | case LLTextureInfoDetails::REQUEST_TYPE_HTTP: | ||
145 | protocol = "HTTP"; | ||
146 | break; | ||
147 | |||
148 | case LLTextureInfoDetails::REQUEST_TYPE_UDP: | ||
149 | protocol = "UDP"; | ||
150 | break; | ||
151 | |||
152 | case LLTextureInfoDetails::REQUEST_TYPE_NONE: | ||
153 | default: | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | if (mLogTextureDownloadsToViewerLog) | ||
158 | { | ||
159 | llinfos << "texture=" << id | ||
160 | << " start=" << mTextures[id]->mStartTime | ||
161 | << " end=" << mTextures[id]->mCompleteTime | ||
162 | << " size=" << mTextures[id]->mSize | ||
163 | << " offset=" << mTextures[id]->mOffset | ||
164 | << " length_in_ms=" << (mTextures[id]->mCompleteTime - mTextures[id]->mStartTime) / 1000 | ||
165 | << " protocol=" << protocol | ||
166 | << llendl; | ||
167 | } | ||
168 | |||
169 | if(mLogTextureDownloadsToSimulator) | ||
170 | { | ||
171 | S32 texture_stats_upload_threshold = mTextureLogThreshold; | ||
172 | mTotalBytes += mTextures[id]->mSize; | ||
173 | mTotalMilliseconds += mTextures[id]->mCompleteTime - mTextures[id]->mStartTime; | ||
174 | mTextureDownloadsCompleted++; | ||
175 | mTextureDownloadProtocol = protocol; | ||
176 | if (mTotalBytes >= texture_stats_upload_threshold) | ||
177 | { | ||
178 | LLSD texture_data; | ||
179 | std::stringstream startTime; | ||
180 | startTime << mCurrentStatsBundleStartTime; | ||
181 | texture_data["start_time"] = startTime.str(); | ||
182 | std::stringstream endTime; | ||
183 | endTime << completeTime; | ||
184 | texture_data["end_time"] = endTime.str(); | ||
185 | texture_data["averages"] = getAverages(); | ||
186 | send_texture_stats_to_sim(texture_data); | ||
187 | resetTextureStatistics(); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | mTextures.erase(id); | ||
192 | } | ||
193 | |||
194 | LLSD LLTextureInfo::getAverages() | ||
195 | { | ||
196 | LLSD averagedTextureData; | ||
197 | S32 averageDownloadRate; | ||
198 | if(mTotalMilliseconds == 0) | ||
199 | { | ||
200 | averageDownloadRate = 0; | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | averageDownloadRate = (mTotalBytes * 8) / mTotalMilliseconds; | ||
205 | } | ||
206 | |||
207 | averagedTextureData["bits_per_second"] = averageDownloadRate; | ||
208 | averagedTextureData["bytes_downloaded"] = mTotalBytes; | ||
209 | averagedTextureData["texture_downloads_started"] = mTextureDownloadsStarted; | ||
210 | averagedTextureData["texture_downloads_completed"] = mTextureDownloadsCompleted; | ||
211 | averagedTextureData["transport"] = mTextureDownloadProtocol; | ||
212 | |||
213 | return averagedTextureData; | ||
214 | } | ||
215 | |||
216 | void LLTextureInfo::resetTextureStatistics() | ||
217 | { | ||
218 | mTotalMilliseconds = 0; | ||
219 | mTotalBytes = 0; | ||
220 | mTextureDownloadsStarted = 0; | ||
221 | mTextureDownloadsCompleted = 0; | ||
222 | mTextureDownloadProtocol = "NONE"; | ||
223 | mCurrentStatsBundleStartTime = LLTimer::getTotalTime(); | ||
224 | } | ||
225 | |||
226 | U32 LLTextureInfo::getRequestStartTime(const LLUUID& id) | ||
227 | { | ||
228 | if (!has(id)) | ||
229 | { | ||
230 | return 0; | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id); | ||
235 | return (*iterator).second->mStartTime; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | U32 LLTextureInfo::getRequestSize(const LLUUID& id) | ||
240 | { | ||
241 | if (!has(id)) | ||
242 | { | ||
243 | return 0; | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id); | ||
248 | return (*iterator).second->mSize; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | U32 LLTextureInfo::getRequestOffset(const LLUUID& id) | ||
253 | { | ||
254 | if (!has(id)) | ||
255 | { | ||
256 | return 0; | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id); | ||
261 | return (*iterator).second->mOffset; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | LLTextureInfoDetails::LLRequestType LLTextureInfo::getRequestType(const LLUUID& id) | ||
266 | { | ||
267 | if (!has(id)) | ||
268 | { | ||
269 | return LLTextureInfoDetails::REQUEST_TYPE_NONE; | ||
270 | } | ||
271 | else | ||
272 | { | ||
273 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id); | ||
274 | return (*iterator).second->mType; | ||
275 | } | ||
276 | } | ||
277 | |||
278 | U32 LLTextureInfo::getRequestCompleteTime(const LLUUID& id) | ||
279 | { | ||
280 | if (!has(id)) | ||
281 | { | ||
282 | return 0; | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id); | ||
287 | return (*iterator).second->mCompleteTime; | ||
288 | } | ||
289 | } | ||
290 | |||