PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewerassetstats.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 328 lines | 105 code | 46 blank | 177 comment | 1 complexity | ed82841b4a11f4a512b280c61ec76260 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerassetstats.h
  3. * @brief Client-side collection of asset request statistics
  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. #ifndef LL_LLVIEWERASSETSTATUS_H
  27. #define LL_LLVIEWERASSETSTATUS_H
  28. #include "linden_common.h"
  29. #include "llpointer.h"
  30. #include "llrefcount.h"
  31. #include "llviewerassettype.h"
  32. #include "llviewerassetstorage.h"
  33. #include "llsimplestat.h"
  34. #include "llsd.h"
  35. /**
  36. * @class LLViewerAssetStats
  37. * @brief Records performance aspects of asset access operations.
  38. *
  39. * This facility is derived from a very similar simulator-based
  40. * one, LLSimAssetStats. It's function is to count asset access
  41. * operations and characterize response times. Collected data
  42. * are binned in several dimensions:
  43. *
  44. * - Asset types collapsed into a few aggregated categories
  45. * - By simulator UUID
  46. * - By transport mechanism (HTTP vs MessageSystem)
  47. * - By persistence (temp vs non-temp)
  48. *
  49. * Statistics collected are fairly basic at this point:
  50. *
  51. * - Counts of enqueue and dequeue operations
  52. * - Min/Max/Mean of asset transfer operations
  53. *
  54. * This collector differs from the simulator-based on in a
  55. * number of ways:
  56. *
  57. * - The front-end/back-end distinction doesn't exist in viewer
  58. * code
  59. * - Multiple threads must be safely accomodated in the viewer
  60. *
  61. * Access to results is by conversion to an LLSD with some standardized
  62. * key names. The intent of this structure is that it be emitted as
  63. * standard syslog-based metrics formatting where it can be picked
  64. * up by interested parties.
  65. *
  66. * For convenience, a set of free functions in namespace
  67. * LLViewerAssetStatsFF is provided for conditional test-and-call
  68. * operations.
  69. */
  70. class LLViewerAssetStats
  71. {
  72. public:
  73. enum EViewerAssetCategories
  74. {
  75. EVACTextureTempHTTPGet, //< Texture GETs - temp/baked, HTTP
  76. EVACTextureTempUDPGet, //< Texture GETs - temp/baked, UDP
  77. EVACTextureNonTempHTTPGet, //< Texture GETs - perm, HTTP
  78. EVACTextureNonTempUDPGet, //< Texture GETs - perm, UDP
  79. EVACWearableUDPGet, //< Wearable GETs
  80. EVACSoundUDPGet, //< Sound GETs
  81. EVACGestureUDPGet, //< Gesture GETs
  82. EVACOtherGet, //< Other GETs
  83. EVACCount // Must be last
  84. };
  85. /**
  86. * Type for duration and other time values in the metrics. Selected
  87. * for compatibility with the pre-existing timestamp on the texture
  88. * fetcher class, LLTextureFetch.
  89. */
  90. typedef U64 duration_t;
  91. /**
  92. * Type for the region identifier used in stats. Currently uses
  93. * the region handle's type (a U64) rather than the regions's LLUUID
  94. * as the latter isn't available immediately.
  95. */
  96. typedef U64 region_handle_t;
  97. /**
  98. * @brief Collected data for a single region visited by the avatar.
  99. *
  100. * Fairly simple, for each asset bin enumerated above a count
  101. * of enqueue and dequeue operations and simple stats on response
  102. * times for completed requests.
  103. */
  104. class PerRegionStats : public LLRefCount
  105. {
  106. public:
  107. PerRegionStats(const region_handle_t region_handle)
  108. : LLRefCount(),
  109. mRegionHandle(region_handle)
  110. {
  111. reset();
  112. }
  113. PerRegionStats(const PerRegionStats & src)
  114. : LLRefCount(),
  115. mRegionHandle(src.mRegionHandle),
  116. mTotalTime(src.mTotalTime),
  117. mStartTimestamp(src.mStartTimestamp),
  118. mFPS(src.mFPS)
  119. {
  120. for (int i = 0; i < LL_ARRAY_SIZE(mRequests); ++i)
  121. {
  122. mRequests[i] = src.mRequests[i];
  123. }
  124. }
  125. // Default assignment and destructor are correct.
  126. void reset();
  127. void merge(const PerRegionStats & src);
  128. // Apply current running time to total and reset start point.
  129. // Return current timestamp as a convenience.
  130. void accumulateTime(duration_t now);
  131. public:
  132. region_handle_t mRegionHandle;
  133. duration_t mTotalTime;
  134. duration_t mStartTimestamp;
  135. LLSimpleStatMMM<> mFPS;
  136. struct prs_group
  137. {
  138. LLSimpleStatCounter mEnqueued;
  139. LLSimpleStatCounter mDequeued;
  140. LLSimpleStatMMM<duration_t> mResponse;
  141. }
  142. mRequests [EVACCount];
  143. };
  144. public:
  145. LLViewerAssetStats();
  146. LLViewerAssetStats(const LLViewerAssetStats &);
  147. // Default destructor is correct.
  148. LLViewerAssetStats & operator=(const LLViewerAssetStats &); // Not defined
  149. // Clear all metrics data. This leaves the currently-active region
  150. // in place but with zero'd data for all metrics. All other regions
  151. // are removed from the collection map.
  152. void reset();
  153. // Set hidden region argument and establish context for subsequent
  154. // collection calls.
  155. void setRegion(region_handle_t region_handle);
  156. // Asset GET Requests
  157. void recordGetEnqueued(LLViewerAssetType::EType at, bool with_http, bool is_temp);
  158. void recordGetDequeued(LLViewerAssetType::EType at, bool with_http, bool is_temp);
  159. void recordGetServiced(LLViewerAssetType::EType at, bool with_http, bool is_temp, duration_t duration);
  160. // Frames-Per-Second Samples
  161. void recordFPS(F32 fps);
  162. // Merge a source instance into a destination instance. This is
  163. // conceptually an 'operator+=()' method:
  164. // - counts are added
  165. // - minimums are min'd
  166. // - maximums are max'd
  167. // - other scalars are ignored ('this' wins)
  168. //
  169. void merge(const LLViewerAssetStats & src);
  170. // Retrieve current metrics for all visited regions (NULL region UUID/handle excluded)
  171. // Returned LLSD is structured as follows:
  172. //
  173. // &stats_group = {
  174. // enqueued : int,
  175. // dequeued : int,
  176. // resp_count : int,
  177. // resp_min : float,
  178. // resp_max : float,
  179. // resp_mean : float
  180. // }
  181. //
  182. // &mmm_group = {
  183. // count : int,
  184. // min : float,
  185. // max : float,
  186. // mean : float
  187. // }
  188. //
  189. // {
  190. // duration: int
  191. // regions: {
  192. // $: { // Keys are strings of the region's handle in hex
  193. // duration: : int,
  194. // fps: : &mmm_group,
  195. // get_texture_temp_http : &stats_group,
  196. // get_texture_temp_udp : &stats_group,
  197. // get_texture_non_temp_http : &stats_group,
  198. // get_texture_non_temp_udp : &stats_group,
  199. // get_wearable_udp : &stats_group,
  200. // get_sound_udp : &stats_group,
  201. // get_gesture_udp : &stats_group,
  202. // get_other : &stats_group
  203. // }
  204. // }
  205. // }
  206. //
  207. // @param compact_output If true, omits from conversion any mmm_block
  208. // or stats_block that would contain all zero data.
  209. // Useful for transmission when the receiver knows
  210. // what is expected and will assume zero for missing
  211. // blocks.
  212. LLSD asLLSD(bool compact_output);
  213. protected:
  214. typedef std::map<region_handle_t, LLPointer<PerRegionStats> > PerRegionContainer;
  215. // Region of the currently-active region. Always valid but may
  216. // be zero after construction or when explicitly set. Unchanged
  217. // by a reset() call.
  218. region_handle_t mRegionHandle;
  219. // Pointer to metrics collection for currently-active region. Always
  220. // valid and unchanged after reset() though contents will be changed.
  221. // Always points to a collection contained in mRegionStats.
  222. LLPointer<PerRegionStats> mCurRegionStats;
  223. // Metrics data for all regions during one collection cycle
  224. PerRegionContainer mRegionStats;
  225. // Time of last reset
  226. duration_t mResetTimestamp;
  227. };
  228. /**
  229. * Global stats collectors one for each independent thread where
  230. * assets and other statistics are gathered. The globals are
  231. * expected to be created at startup time and then picked up by
  232. * their respective threads afterwards. A set of free functions
  233. * are provided to access methods behind the globals while both
  234. * minimally disrupting visual flow and supplying a description
  235. * of intent.
  236. *
  237. * Expected thread assignments:
  238. *
  239. * - Main: main() program execution thread
  240. * - Thread1: TextureFetch worker thread
  241. */
  242. extern LLViewerAssetStats * gViewerAssetStatsMain;
  243. extern LLViewerAssetStats * gViewerAssetStatsThread1;
  244. namespace LLViewerAssetStatsFF
  245. {
  246. /**
  247. * @brief Allocation and deallocation of globals.
  248. *
  249. * init() should be called before threads are started that will access it though
  250. * you'll likely get away with calling it afterwards. cleanup() should only be
  251. * called after threads are shutdown to prevent races on the global pointers.
  252. */
  253. void init();
  254. void cleanup();
  255. /**
  256. * We have many timers, clocks etc. in the runtime. This is the
  257. * canonical timestamp for these metrics which is compatible with
  258. * the pre-existing timestamping in the texture fetcher.
  259. */
  260. inline LLViewerAssetStats::duration_t get_timestamp()
  261. {
  262. return LLTimer::getTotalTime();
  263. }
  264. /**
  265. * Region context, event and duration loggers for the Main thread.
  266. */
  267. void set_region_main(LLViewerAssetStats::region_handle_t region_handle);
  268. void record_enqueue_main(LLViewerAssetType::EType at, bool with_http, bool is_temp);
  269. void record_dequeue_main(LLViewerAssetType::EType at, bool with_http, bool is_temp);
  270. void record_response_main(LLViewerAssetType::EType at, bool with_http, bool is_temp,
  271. LLViewerAssetStats::duration_t duration);
  272. void record_fps_main(F32 fps);
  273. /**
  274. * Region context, event and duration loggers for Thread 1.
  275. */
  276. void set_region_thread1(LLViewerAssetStats::region_handle_t region_handle);
  277. void record_enqueue_thread1(LLViewerAssetType::EType at, bool with_http, bool is_temp);
  278. void record_dequeue_thread1(LLViewerAssetType::EType at, bool with_http, bool is_temp);
  279. void record_response_thread1(LLViewerAssetType::EType at, bool with_http, bool is_temp,
  280. LLViewerAssetStats::duration_t duration);
  281. } // namespace LLViewerAssetStatsFF
  282. #endif // LL_LLVIEWERASSETSTATUS_H