PageRenderTime 586ms CodeModel.GetById 221ms app.highlight 123ms RepoModel.GetById 239ms app.codeStats 0ms

/indra/newview/llviewerstatsrecorder.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 258 lines | 200 code | 30 blank | 28 comment | 13 complexity | bc3d31fe1ef4b08802619aa7cf46e313 MD5 | raw file
  1/**
  2 * @file llviewerstatsrecorder.cpp
  3 * @brief record info about viewer events to a metrics log file
  4 *
  5 * $LicenseInfo:firstyear=2010&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#include "llviewerstatsrecorder.h"
 29
 30#if LL_RECORD_VIEWER_STATS
 31
 32#include "llfile.h"
 33#include "llviewerregion.h"
 34#include "llviewerobject.h"
 35
 36
 37// To do - something using region name or global position
 38#if LL_WINDOWS
 39	static const std::string STATS_FILE_NAME("C:\\ViewerObjectCacheStats.csv");
 40#else
 41	static const std::string STATS_FILE_NAME("/tmp/viewerstats.csv");
 42#endif
 43
 44LLViewerStatsRecorder* LLViewerStatsRecorder::sInstance = NULL;
 45LLViewerStatsRecorder::LLViewerStatsRecorder() :
 46	mObjectCacheFile(NULL),
 47	mTimer(),
 48	mRegionp(NULL),
 49	mStartTime(0.f),
 50	mProcessingTime(0.f)
 51{
 52	if (NULL != sInstance)
 53	{
 54		llerrs << "Attempted to create multiple instances of LLViewerStatsRecorder!" << llendl;
 55	}
 56	sInstance = this;
 57	clearStats();
 58}
 59
 60LLViewerStatsRecorder::~LLViewerStatsRecorder()
 61{
 62	if (mObjectCacheFile != NULL)
 63	{
 64		LLFile::close(mObjectCacheFile);
 65		mObjectCacheFile = NULL;
 66	}
 67}
 68
 69// static
 70void LLViewerStatsRecorder::initClass()
 71{
 72	sInstance = new LLViewerStatsRecorder();
 73}
 74
 75// static
 76void LLViewerStatsRecorder::cleanupClass()
 77{
 78	delete sInstance;
 79	sInstance = NULL;
 80}
 81
 82
 83void LLViewerStatsRecorder::initStatsRecorder(LLViewerRegion *regionp)
 84{
 85	if (mObjectCacheFile == NULL)
 86	{
 87		mStartTime = LLTimer::getTotalTime();
 88		mObjectCacheFile = LLFile::fopen(STATS_FILE_NAME, "wb");
 89		if (mObjectCacheFile)
 90		{	// Write column headers
 91			std::ostringstream data_msg;
 92			data_msg << "EventTime, "
 93				<< "ProcessingTime, "
 94				<< "CacheHits, "
 95				<< "CacheFullMisses, "
 96				<< "CacheCrcMisses, "
 97				<< "FullUpdates, "
 98				<< "TerseUpdates, "
 99				<< "CacheMissRequests, "
100				<< "CacheMissResponses, "
101				<< "CacheUpdateDupes, "
102				<< "CacheUpdateChanges, "
103				<< "CacheUpdateAdds, "
104				<< "CacheUpdateReplacements, "
105				<< "UpdateFailures"
106				<< "\n";
107
108			fwrite(data_msg.str().c_str(), 1, data_msg.str().size(), mObjectCacheFile );
109		}
110	}
111}
112
113void LLViewerStatsRecorder::beginObjectUpdateEvents(LLViewerRegion *regionp)
114{
115	initStatsRecorder(regionp);
116	mRegionp = regionp;
117	mProcessingTime = LLTimer::getTotalTime();
118	clearStats();
119}
120
121void LLViewerStatsRecorder::clearStats()
122{
123	mObjectCacheHitCount = 0;
124	mObjectCacheMissFullCount = 0;
125	mObjectCacheMissCrcCount = 0;
126	mObjectFullUpdates = 0;
127	mObjectTerseUpdates = 0;
128	mObjectCacheMissRequests = 0;
129	mObjectCacheMissResponses = 0;
130	mObjectCacheUpdateDupes = 0;
131	mObjectCacheUpdateChanges = 0;
132	mObjectCacheUpdateAdds = 0;
133	mObjectCacheUpdateReplacements = 0;
134	mObjectUpdateFailures = 0;
135}
136
137
138void LLViewerStatsRecorder::recordObjectUpdateFailure(U32 local_id, const EObjectUpdateType update_type)
139{
140	mObjectUpdateFailures++;
141}
142
143void LLViewerStatsRecorder::recordCacheMissEvent(U32 local_id, const EObjectUpdateType update_type, U8 cache_miss_type)
144{
145	if (LLViewerRegion::CACHE_MISS_TYPE_FULL == cache_miss_type)
146	{
147		mObjectCacheMissFullCount++;
148	}
149	else
150	{
151		mObjectCacheMissCrcCount++;
152	}
153}
154
155void LLViewerStatsRecorder::recordObjectUpdateEvent(U32 local_id, const EObjectUpdateType update_type, LLViewerObject * objectp)
156{
157	switch (update_type)
158	{
159	case OUT_FULL:
160		mObjectFullUpdates++;
161		break;
162	case OUT_TERSE_IMPROVED:
163		mObjectTerseUpdates++;
164		break;
165	case OUT_FULL_COMPRESSED:
166		mObjectCacheMissResponses++;
167		break;
168	case OUT_FULL_CACHED:
169		mObjectCacheHitCount++;
170		break;
171	default:
172		llwarns << "Unknown update_type" << llendl;
173		break;
174	};
175}
176
177void LLViewerStatsRecorder::recordCacheFullUpdate(U32 local_id, const EObjectUpdateType update_type, LLViewerRegion::eCacheUpdateResult update_result, LLViewerObject* objectp)
178{
179	switch (update_result)
180	{
181		case LLViewerRegion::CACHE_UPDATE_DUPE:
182			mObjectCacheUpdateDupes++;
183			break;
184		case LLViewerRegion::CACHE_UPDATE_CHANGED:
185			mObjectCacheUpdateChanges++;
186			break;
187		case LLViewerRegion::CACHE_UPDATE_ADDED:
188			mObjectCacheUpdateAdds++;
189			break;
190		case LLViewerRegion::CACHE_UPDATE_REPLACED:
191			mObjectCacheUpdateReplacements++;
192			break;
193		default:
194			llwarns << "Unknown update_result type" << llendl;
195			break;
196	};
197}
198
199void LLViewerStatsRecorder::recordRequestCacheMissesEvent(S32 count)
200{
201	mObjectCacheMissRequests += count;
202}
203
204void LLViewerStatsRecorder::endObjectUpdateEvents()
205{
206	llinfos << "ILX: " 
207		<< mObjectCacheHitCount << " hits, " 
208		<< mObjectCacheMissFullCount << " full misses, "
209		<< mObjectCacheMissCrcCount << " crc misses, "
210		<< mObjectFullUpdates << " full updates, "
211		<< mObjectTerseUpdates << " terse updates, "
212		<< mObjectCacheMissRequests << " cache miss requests, "
213		<< mObjectCacheMissResponses << " cache miss responses, "
214		<< mObjectCacheUpdateDupes << " cache update dupes, "
215		<< mObjectCacheUpdateChanges << " cache update changes, "
216		<< mObjectCacheUpdateAdds << " cache update adds, "
217		<< mObjectCacheUpdateReplacements << " cache update replacements, "
218		<< mObjectUpdateFailures << " update failures"
219		<< llendl;
220
221	S32 total_objects = mObjectCacheHitCount + mObjectCacheMissCrcCount + mObjectCacheMissFullCount + mObjectFullUpdates + mObjectTerseUpdates + mObjectCacheMissRequests + mObjectCacheMissResponses + mObjectCacheUpdateDupes + mObjectCacheUpdateChanges + mObjectCacheUpdateAdds + mObjectCacheUpdateReplacements + mObjectUpdateFailures;
222	if (mObjectCacheFile != NULL &&
223		total_objects > 0)
224	{
225		std::ostringstream data_msg;
226		F32 processing32 = (F32) ((LLTimer::getTotalTime() - mProcessingTime) / 1000.0);
227
228		data_msg << getTimeSinceStart()
229			<< ", " << processing32
230			<< ", " << mObjectCacheHitCount
231			<< ", " << mObjectCacheMissFullCount
232			<< ", " << mObjectCacheMissCrcCount
233			<< ", " << mObjectFullUpdates
234			<< ", " << mObjectTerseUpdates
235			<< ", " << mObjectCacheMissRequests
236			<< ", " << mObjectCacheMissResponses
237			<< ", " << mObjectCacheUpdateDupes
238			<< ", " << mObjectCacheUpdateChanges
239			<< ", " << mObjectCacheUpdateAdds
240			<< ", " << mObjectCacheUpdateReplacements
241			<< ", " << mObjectUpdateFailures
242			<< "\n";
243
244		fwrite(data_msg.str().c_str(), 1, data_msg.str().size(), mObjectCacheFile );
245	}
246
247	clearStats();
248}
249
250F32 LLViewerStatsRecorder::getTimeSinceStart()
251{
252	return (F32) ((LLTimer::getTotalTime() - mStartTime) / 1000.0);
253}
254
255#endif
256
257
258