SimExtraStatsCollector.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using libsecondlife;
  31. using OpenSim.Framework.Statistics.Interfaces;
  32. namespace OpenSim.Framework.Statistics
  33. {
  34. /// <summary>
  35. /// Collects sim statistics which aren't already being collected for the linden viewer's statistics pane
  36. /// </summary>
  37. public class SimExtraStatsCollector : IStatsCollector
  38. {
  39. private long assetsInCache;
  40. private long texturesInCache;
  41. private long assetCacheMemoryUsage;
  42. private long textureCacheMemoryUsage;
  43. private long blockedMissingTextureRequests;
  44. private long inventoryServiceRetrievalFailures;
  45. public long AssetsInCache { get { return assetsInCache; } }
  46. public long TexturesInCache { get { return texturesInCache; } }
  47. public long AssetCacheMemoryUsage { get { return assetCacheMemoryUsage; } }
  48. public long TextureCacheMemoryUsage { get { return textureCacheMemoryUsage; } }
  49. /// <summary>
  50. /// Number of persistent requests for missing textures we have started blocking from clients. To some extent
  51. /// this is just a temporary statistic to keep this problem in view - the root cause of this lies either
  52. /// in a mishandling of the reply protocol, related to avatar appearance or may even originate in graphics
  53. /// driver bugs on clients (though this seems less likely).
  54. /// </summary>
  55. public long BlockedMissingTextureRequests { get { return blockedMissingTextureRequests; } }
  56. /// <summary>
  57. /// Number of known failures to retrieve avatar inventory from the inventory service. This does not
  58. /// cover situations where the inventory service accepts the request but never returns any data, since
  59. /// we do not yet timeout this situation.
  60. /// </summary>
  61. public long InventoryServiceRetrievalFailures { get { return inventoryServiceRetrievalFailures; } }
  62. /// <summary>
  63. /// Retain a dictionary of all packet queues stats reporters
  64. /// </summary>
  65. private IDictionary<LLUUID, PacketQueueStatsCollector> packetQueueStatsCollectors
  66. = new Dictionary<LLUUID, PacketQueueStatsCollector>();
  67. public void AddAsset(AssetBase asset)
  68. {
  69. assetsInCache++;
  70. assetCacheMemoryUsage += asset.Data.Length;
  71. }
  72. public void AddTexture(AssetBase image)
  73. {
  74. if (image.Data != null)
  75. {
  76. texturesInCache++;
  77. // This could have been a pull stat, though there was originally a nebulous idea to measure flow rates
  78. textureCacheMemoryUsage += image.Data.Length;
  79. }
  80. }
  81. public void AddBlockedMissingTextureRequest()
  82. {
  83. blockedMissingTextureRequests++;
  84. }
  85. public void AddInventoryServiceRetrievalFailure()
  86. {
  87. inventoryServiceRetrievalFailures++;
  88. }
  89. /// <summary>
  90. /// Register as a packet queue stats provider
  91. /// </summary>
  92. /// <param name="uuid">An agent LLUUID</param>
  93. /// <param name="provider"></param>
  94. public void RegisterPacketQueueStatsProvider(LLUUID uuid, IPullStatsProvider provider)
  95. {
  96. lock (packetQueueStatsCollectors)
  97. {
  98. packetQueueStatsCollectors[uuid] = new PacketQueueStatsCollector(provider);
  99. }
  100. }
  101. /// <summary>
  102. /// Deregister a packet queue stats provider
  103. /// </summary>
  104. /// <param name="uuid">An agent LLUUID</param>
  105. public void DeregisterPacketQueueStatsProvider(LLUUID uuid)
  106. {
  107. lock (packetQueueStatsCollectors)
  108. {
  109. packetQueueStatsCollectors.Remove(uuid);
  110. }
  111. }
  112. /// <summary>
  113. /// Report back collected statistical information.
  114. /// </summary>
  115. /// <returns></returns>
  116. public string Report()
  117. {
  118. StringBuilder sb = new StringBuilder(Environment.NewLine);
  119. sb.Append("ASSET STATISTICS");
  120. sb.Append(Environment.NewLine);
  121. sb.Append(
  122. string.Format(
  123. @"Asset cache contains {0,6} assets using {1,10:0.000}K" + Environment.NewLine,
  124. AssetsInCache, AssetCacheMemoryUsage / 1024.0));
  125. sb.Append(Environment.NewLine);
  126. sb.Append("TEXTURE STATISTICS");
  127. sb.Append(Environment.NewLine);
  128. sb.Append(
  129. string.Format(
  130. @"Texture cache contains {0,6} textures using {1,10:0.000}K
  131. Blocked requests for missing textures: {2}" + Environment.NewLine,
  132. TexturesInCache, TextureCacheMemoryUsage / 1024.0,
  133. BlockedMissingTextureRequests));
  134. sb.Append(Environment.NewLine);
  135. sb.Append("INVENTORY STATISTICS");
  136. sb.Append(Environment.NewLine);
  137. sb.Append(
  138. string.Format(
  139. "Initial inventory caching failures: {0}" + Environment.NewLine,
  140. InventoryServiceRetrievalFailures));
  141. sb.Append(Environment.NewLine);
  142. sb.Append("PACKET QUEUE STATISTICS");
  143. sb.Append(Environment.NewLine);
  144. sb.Append("Agent UUID ");
  145. sb.Append(
  146. string.Format(
  147. " {0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7}",
  148. "Send", "In", "Out", "Resend", "Land", "Wind", "Cloud", "Task", "Texture", "Asset"));
  149. sb.Append(Environment.NewLine);
  150. foreach (LLUUID key in packetQueueStatsCollectors.Keys)
  151. {
  152. sb.Append(string.Format("{0}: ", key));
  153. sb.Append(packetQueueStatsCollectors[key].Report());
  154. sb.Append(Environment.NewLine);
  155. }
  156. return sb.ToString();
  157. }
  158. }
  159. /// <summary>
  160. /// Pull packet queue stats from packet queues and report
  161. /// </summary>
  162. public class PacketQueueStatsCollector : IStatsCollector
  163. {
  164. private IPullStatsProvider m_statsProvider;
  165. public PacketQueueStatsCollector(IPullStatsProvider provider)
  166. {
  167. m_statsProvider = provider;
  168. }
  169. /// <summary>
  170. /// Report back collected statistical information.
  171. /// </summary>
  172. /// <returns></returns>
  173. public string Report()
  174. {
  175. return m_statsProvider.GetStats();
  176. }
  177. }
  178. }