1
0

SimStats.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 OpenSimulator 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 OpenMetaverse;
  28. using System.Collections.Generic;
  29. namespace OpenSim.Framework
  30. {
  31. /// <summary>
  32. /// These are the IDs of stats required by viewers protocol
  33. /// </summary>
  34. /// <remarks>
  35. /// Some of these are not relevant to OpenSimulator since it is architected differently to other simulators
  36. /// (e.g. script instructions aren't executed as part of the frame loop so 'script time' is tricky).
  37. /// </remarks>
  38. public enum StatsID : uint
  39. {
  40. // viewers defined IDs
  41. TimeDilation = 0,
  42. SimFPS = 1,
  43. PhysicsFPS = 2,
  44. AgentUpdates = 3,
  45. FrameMS = 4,
  46. NetMS = 5,
  47. OtherMS = 6,
  48. PhysicsMS = 7,
  49. AgentMS = 8,
  50. ImageMS = 9,
  51. ScriptMS = 10,
  52. TotalPrim = 11,
  53. ActivePrim = 12,
  54. Agents = 13,
  55. ChildAgents = 14,
  56. ActiveScripts = 15,
  57. LSLScriptLinesPerSecond = 16, // viewers don't like this anymore
  58. InPacketsPerSecond = 17,
  59. OutPacketsPerSecond = 18,
  60. PendingDownloads = 19,
  61. PendingUploads = 20,
  62. VirtualSizeKb = 21,
  63. ResidentSizeKb = 22,
  64. PendingLocalUploads = 23,
  65. UnAckedBytes = 24,
  66. PhysicsPinnedTasks = 25,
  67. PhysicsLodTasks = 26,
  68. SimPhysicsStepMs = 27,
  69. SimPhysicsShapeMs = 28,
  70. SimPhysicsOtherMs = 29,
  71. SimPhysicsMemory = 30,
  72. ScriptEps = 31,
  73. SimSpareMs = 32,
  74. SimSleepMs = 33,
  75. SimIoPumpTime = 34,
  76. SimPCTSscriptsRun = 35,
  77. SimRegionIdle = 36, // dataserver only
  78. SimRegionIdlePossible = 37, // dataserver only
  79. SimAIStepTimeMS = 38,
  80. SimSkippedSillouet_PS = 39,
  81. SimSkippedCharsPerC = 40,
  82. // extra stats IDs, just far from viewer defined ones
  83. SimExtraCountStart = 1000,
  84. internalLSLScriptLinesPerSecond = 1000,
  85. FrameDilation2 = 1001,
  86. UsersLoggingIn = 1002,
  87. TotalGeoPrim = 1003,
  88. TotalMesh = 1004,
  89. ScriptEngineThreadCount = 1005,
  90. NPCs = 1006,
  91. SimExtraCountEnd = 1007
  92. }
  93. // stats values are stored on a float[]
  94. // so we need readable indexes to it
  95. // Values sent to viewers via lludp must be first and up to fake index ViewerArraySize
  96. // fake index ArraySize defines the needed array size
  97. // this does not follow same order as IDs, because legacy order
  98. public enum StatsIndex : int
  99. {
  100. // index into data array
  101. TimeDilation = 0,
  102. SimFPS = 1,
  103. PhysicsFPS = 2,
  104. AgentUpdates = 3,
  105. Agents = 4,
  106. ChildAgents = 5,
  107. TotalPrim = 6,
  108. ActivePrim = 7,
  109. FrameMS = 8,
  110. NetMS = 9,
  111. PhysicsMS = 10,
  112. ImageMS = 11,
  113. OtherMS = 12,
  114. InPacketsPerSecond = 13,
  115. OutPacketsPerSecond = 14,
  116. UnAckedBytes = 15,
  117. AgentMS = 16,
  118. PendingDownloads = 17,
  119. PendingUploads = 18,
  120. ActiveScripts = 19,
  121. SimSleepMs = 20,
  122. SimSpareMs = 21,
  123. SimPhysicsStepMs = 22,
  124. VirtualSizeKb = 23,
  125. ResidentSizeKb = 24,
  126. PendingLocalUploads = 25,
  127. PhysicsPinnedTasks = 26,
  128. PhysicsLodTasks = 27,
  129. ScriptEps = 28,
  130. SimAIStepTimeMS = 29,
  131. SimIoPumpTime = 30,
  132. SimPCTSscriptsRun = 31,
  133. SimRegionIdle = 32,
  134. SimRegionIdlePossible = 33,
  135. SimSkippedSillouet_PS = 34,
  136. SimSkippedCharsPerC = 35,
  137. SimPhysicsMemory = 36,
  138. ScriptMS = 37,
  139. LSLScriptLinesPerSecond = 38,
  140. SimPhysicsShapeMs = 39,
  141. SimPhysicsOtherMs = 40,
  142. ViewerArraySize = 41, // just a marker to the end of viewer only stats and start of extra
  143. internalLSLScriptLinesPerSecond = 41,
  144. FrameDilation2 = 42,
  145. UsersLoggingIn = 43,
  146. TotalGeoPrim = 44,
  147. TotalMesh = 45,
  148. ScriptEngineThreadCount = 46,
  149. NPCs = 47,
  150. ArraySize = 48 // last is marker for array size
  151. }
  152. /// <summary>
  153. /// Enapsulate statistics for a simulator/scene.
  154. ///
  155. /// TODO: This looks very much like the OpenMetaverse SimStatsPacket. It should be much more generic stats
  156. /// storage.
  157. /// </summary>
  158. public class SimStats
  159. {
  160. public uint RegionX;
  161. public uint RegionY;
  162. public uint RegionSizeX;
  163. public uint RegionSizeY;
  164. public uint RegionFlags;
  165. public uint ObjectCapacity;
  166. public UUID RegionUUID;
  167. public string RegionName;
  168. public float[] StatsValues
  169. {
  170. get { return m_statsValues; }
  171. }
  172. private float[] m_statsValues;
  173. // a fixed array with the IDs for each viewer relevant stat
  174. // order and size must match StatsIndex enum
  175. public static readonly uint[] StatsIndexID = new uint[]
  176. {
  177. (uint)StatsID.TimeDilation,
  178. (uint)StatsID.SimFPS,
  179. (uint)StatsID.PhysicsFPS,
  180. (uint)StatsID.AgentUpdates,
  181. (uint)StatsID.Agents,
  182. (uint)StatsID.ChildAgents,
  183. (uint)StatsID.TotalPrim,
  184. (uint)StatsID.ActivePrim,
  185. (uint)StatsID.FrameMS,
  186. (uint)StatsID.NetMS,
  187. (uint)StatsID.PhysicsMS,
  188. (uint)StatsID.ImageMS,
  189. (uint)StatsID.OtherMS,
  190. (uint)StatsID.InPacketsPerSecond,
  191. (uint)StatsID.OutPacketsPerSecond,
  192. (uint)StatsID.UnAckedBytes,
  193. (uint)StatsID.AgentMS,
  194. (uint)StatsID.PendingDownloads,
  195. (uint)StatsID.PendingUploads,
  196. (uint)StatsID.ActiveScripts,
  197. (uint)StatsID.SimSleepMs,
  198. (uint)StatsID.SimSpareMs,
  199. (uint)StatsID.SimPhysicsStepMs,
  200. (uint)StatsID.VirtualSizeKb,
  201. (uint)StatsID.ResidentSizeKb,
  202. (uint)StatsID.PendingLocalUploads,
  203. (uint)StatsID.PhysicsPinnedTasks,
  204. (uint)StatsID.PhysicsLodTasks,
  205. (uint)StatsID.ScriptEps,
  206. (uint)StatsID.SimAIStepTimeMS,
  207. (uint)StatsID.SimIoPumpTime,
  208. (uint)StatsID.SimPCTSscriptsRun,
  209. (uint)StatsID.SimRegionIdle,
  210. (uint)StatsID.SimRegionIdlePossible,
  211. (uint)StatsID.SimSkippedSillouet_PS,
  212. (uint)StatsID.SimSkippedCharsPerC,
  213. (uint)StatsID.SimPhysicsMemory,
  214. (uint)StatsID.ScriptMS,
  215. (uint)StatsID.LSLScriptLinesPerSecond,
  216. (uint)StatsID.SimPhysicsShapeMs,
  217. (uint)StatsID.SimPhysicsOtherMs,
  218. (uint)StatsID.internalLSLScriptLinesPerSecond,
  219. (uint)StatsID.FrameDilation2,
  220. (uint)StatsID.UsersLoggingIn,
  221. (uint)StatsID.TotalGeoPrim,
  222. (uint)StatsID.TotalMesh,
  223. (uint)StatsID.ScriptEngineThreadCount,
  224. (uint)StatsID.NPCs
  225. };
  226. public SimStats(
  227. uint regionX, uint regionY,
  228. uint regionSizeX, uint regionSizeY,
  229. uint regionFlags, uint objectCapacity,
  230. float[] values,
  231. UUID pRUUID, string regionName)
  232. {
  233. RegionUUID = pRUUID;
  234. RegionName = regionName;
  235. RegionX = regionX;
  236. RegionY = regionY;
  237. RegionSizeX = regionSizeX;
  238. RegionSizeY = regionSizeY;
  239. RegionFlags = regionFlags;
  240. ObjectCapacity = objectCapacity;
  241. m_statsValues = values;
  242. }
  243. }
  244. }