PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltextureinfo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 284 lines | 229 code | 30 blank | 25 comment | 19 complexity | 6993341b218cc6b304ac8853bf844d18 MD5 | raw file
  1/** 
  2 * @file lltextureinfo.cpp
  3 * @brief Object which handles local texture info
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "lltextureinfo.h"
 30#include "lltexturestats.h"
 31#include "llviewercontrol.h"
 32
 33LLTextureInfo::LLTextureInfo() : 
 34	mLogTextureDownloadsToViewerLog(false),
 35	mLogTextureDownloadsToSimulator(false),
 36	mTotalBytes(0),
 37	mTotalMilliseconds(0),
 38	mTextureDownloadsStarted(0),
 39	mTextureDownloadsCompleted(0),
 40	mTextureDownloadProtocol("NONE"),
 41	mTextureLogThreshold(100 * 1024),
 42	mCurrentStatsBundleStartTime(0)
 43{
 44	mTextures.clear();
 45}
 46
 47void LLTextureInfo::setUpLogging(bool writeToViewerLog, bool sendToSim, U32 textureLogThreshold)
 48{
 49	mLogTextureDownloadsToViewerLog = writeToViewerLog;
 50	mLogTextureDownloadsToSimulator = sendToSim;
 51	mTextureLogThreshold = textureLogThreshold;
 52}
 53
 54LLTextureInfo::~LLTextureInfo()
 55{
 56	std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator;
 57	for (iterator = mTextures.begin(); iterator != mTextures.end(); iterator++)
 58	{
 59		LLTextureInfoDetails *info = (*iterator).second;
 60		delete info;
 61	}
 62
 63	mTextures.clear();
 64}
 65
 66void LLTextureInfo::addRequest(const LLUUID& id)
 67{
 68	LLTextureInfoDetails *info = new LLTextureInfoDetails();
 69	mTextures[id] = info;
 70}
 71
 72U32 LLTextureInfo::getTextureInfoMapSize()
 73{
 74	return mTextures.size();
 75}
 76
 77bool LLTextureInfo::has(const LLUUID& id)
 78{
 79	std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
 80	if (iterator == mTextures.end())
 81	{
 82		return false;
 83	}
 84	else
 85	{
 86		return true;
 87	}
 88}
 89
 90void LLTextureInfo::setRequestStartTime(const LLUUID& id, U64 startTime)
 91{
 92	if (!has(id))
 93	{
 94		addRequest(id);
 95	}
 96	mTextures[id]->mStartTime = startTime;
 97	mTextureDownloadsStarted++;
 98}
 99
100void LLTextureInfo::setRequestSize(const LLUUID& id, U32 size)
101{
102	if (!has(id))
103	{
104		addRequest(id);
105	}
106	mTextures[id]->mSize = size;
107}
108
109void LLTextureInfo::setRequestOffset(const LLUUID& id, U32 offset)
110{
111	if (!has(id))
112	{
113		addRequest(id);
114	}
115	mTextures[id]->mOffset = offset;
116}
117
118void LLTextureInfo::setRequestType(const LLUUID& id, LLTextureInfoDetails::LLRequestType type)
119{
120	if (!has(id))
121	{
122		addRequest(id);
123	}
124	mTextures[id]->mType = type;
125}
126
127void LLTextureInfo::setRequestCompleteTimeAndLog(const LLUUID& id, U64 completeTime)
128{
129	if (!has(id))
130	{
131		addRequest(id);
132	}
133	mTextures[id]->mCompleteTime = completeTime;
134
135	std::string protocol = "NONE";
136	switch(mTextures[id]->mType)
137	{
138	case LLTextureInfoDetails::REQUEST_TYPE_HTTP:
139		protocol = "HTTP";
140		break;
141
142	case LLTextureInfoDetails::REQUEST_TYPE_UDP:
143		protocol = "UDP";
144		break;
145
146	case LLTextureInfoDetails::REQUEST_TYPE_NONE:
147	default:
148		break;
149	}
150
151	if (mLogTextureDownloadsToViewerLog)
152	{
153		llinfos << "texture=" << id 
154			<< " start=" << mTextures[id]->mStartTime 
155			<< " end=" << mTextures[id]->mCompleteTime
156			<< " size=" << mTextures[id]->mSize
157			<< " offset=" << mTextures[id]->mOffset
158			<< " length_in_ms=" << (mTextures[id]->mCompleteTime - mTextures[id]->mStartTime) / 1000
159			<< " protocol=" << protocol
160			<< llendl;
161	}
162
163	if(mLogTextureDownloadsToSimulator)
164	{
165		S32 texture_stats_upload_threshold = mTextureLogThreshold;
166		mTotalBytes += mTextures[id]->mSize;
167		mTotalMilliseconds += mTextures[id]->mCompleteTime - mTextures[id]->mStartTime;
168		mTextureDownloadsCompleted++;
169		mTextureDownloadProtocol = protocol;
170		if (mTotalBytes >= texture_stats_upload_threshold)
171		{
172			LLSD texture_data;
173			std::stringstream startTime;
174			startTime << mCurrentStatsBundleStartTime;
175			texture_data["start_time"] = startTime.str();
176			std::stringstream endTime;
177			endTime << completeTime;
178			texture_data["end_time"] = endTime.str();
179			texture_data["averages"] = getAverages();
180			send_texture_stats_to_sim(texture_data);
181			resetTextureStatistics();
182		}
183	}
184
185	mTextures.erase(id);
186}
187
188LLSD LLTextureInfo::getAverages()
189{
190	LLSD averagedTextureData;
191	S32 averageDownloadRate;
192	if(mTotalMilliseconds == 0)
193	{
194		averageDownloadRate = 0;
195	}
196	else
197	{
198		averageDownloadRate = (mTotalBytes * 8) / mTotalMilliseconds;
199	}
200
201	averagedTextureData["bits_per_second"] = averageDownloadRate;
202	averagedTextureData["bytes_downloaded"] = mTotalBytes;
203	averagedTextureData["texture_downloads_started"] = mTextureDownloadsStarted;
204	averagedTextureData["texture_downloads_completed"] = mTextureDownloadsCompleted;
205	averagedTextureData["transport"] = mTextureDownloadProtocol;
206
207	return averagedTextureData;
208}
209
210void LLTextureInfo::resetTextureStatistics()
211{
212	mTotalMilliseconds = 0;
213	mTotalBytes = 0;
214	mTextureDownloadsStarted = 0;
215	mTextureDownloadsCompleted = 0;
216	mTextureDownloadProtocol = "NONE";
217	mCurrentStatsBundleStartTime = LLTimer::getTotalTime();
218}
219
220U32 LLTextureInfo::getRequestStartTime(const LLUUID& id)
221{
222	if (!has(id))
223	{
224		return 0;
225	}
226	else
227	{
228		std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
229		return (*iterator).second->mStartTime;
230	}
231}
232
233U32 LLTextureInfo::getRequestSize(const LLUUID& id)
234{
235	if (!has(id))
236	{
237		return 0;
238	}
239	else
240	{
241		std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
242		return (*iterator).second->mSize;
243	}
244}
245
246U32 LLTextureInfo::getRequestOffset(const LLUUID& id)
247{
248	if (!has(id))
249	{
250		return 0;
251	}
252	else
253	{
254		std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
255		return (*iterator).second->mOffset;
256	}
257}
258
259LLTextureInfoDetails::LLRequestType LLTextureInfo::getRequestType(const LLUUID& id)
260{
261	if (!has(id))
262	{
263		return LLTextureInfoDetails::REQUEST_TYPE_NONE;
264	}
265	else
266	{
267		std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
268		return (*iterator).second->mType;
269	}
270}
271
272U32 LLTextureInfo::getRequestCompleteTime(const LLUUID& id)
273{
274	if (!has(id))
275	{
276		return 0;
277	}
278	else
279	{
280		std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
281		return (*iterator).second->mCompleteTime;
282	}
283}
284