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