WebStatsModule.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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 System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Net; // to be used for REST-->Grid shortly
  32. using System.Reflection;
  33. using System.Text;
  34. using System.Threading;
  35. using log4net;
  36. using Nini.Config;
  37. using OpenMetaverse;
  38. using OpenMetaverse.StructuredData;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Servers;
  41. using OpenSim.Framework.Servers.HttpServer;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. using Mono.Data.SqliteClient;
  45. using Mono.Addins;
  46. using Caps = OpenSim.Framework.Capabilities.Caps;
  47. using OSD = OpenMetaverse.StructuredData.OSD;
  48. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  49. [assembly: Addin("WebStats", "1.0")]
  50. [assembly: AddinDependency("OpenSim", "0.5")]
  51. namespace OpenSim.Region.UserStatistics
  52. {
  53. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WebStatsModule")]
  54. public class WebStatsModule : ISharedRegionModule
  55. {
  56. private static readonly ILog m_log =
  57. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  58. private static SqliteConnection dbConn;
  59. /// <summary>
  60. /// User statistics sessions keyed by agent ID
  61. /// </summary>
  62. private Dictionary<UUID, UserSession> m_sessions = new Dictionary<UUID, UserSession>();
  63. private List<Scene> m_scenes = new List<Scene>();
  64. private Dictionary<string, IStatsController> reports = new Dictionary<string, IStatsController>();
  65. private Dictionary<UUID, USimStatsData> m_simstatsCounters = new Dictionary<UUID, USimStatsData>();
  66. private const int updateStatsMod = 6;
  67. private int updateLogMod = 1;
  68. private volatile int updateLogCounter = 0;
  69. private volatile int concurrencyCounter = 0;
  70. private bool enabled = false;
  71. private string m_loglines = String.Empty;
  72. private volatile int lastHit = 12000;
  73. #region ISharedRegionModule
  74. public virtual void Initialise(IConfigSource config)
  75. {
  76. IConfig cnfg = config.Configs["WebStats"];
  77. if (cnfg != null)
  78. enabled = cnfg.GetBoolean("enabled", false);
  79. }
  80. public virtual void PostInitialise()
  81. {
  82. if (!enabled)
  83. return;
  84. if (Util.IsWindows())
  85. Util.LoadArchSpecificWindowsDll("sqlite3.dll");
  86. //IConfig startupConfig = config.Configs["Startup"];
  87. dbConn = new SqliteConnection("URI=file:LocalUserStatistics.db,version=3");
  88. dbConn.Open();
  89. CreateTables(dbConn);
  90. Prototype_distributor protodep = new Prototype_distributor();
  91. Updater_distributor updatedep = new Updater_distributor();
  92. ActiveConnectionsAJAX ajConnections = new ActiveConnectionsAJAX();
  93. SimStatsAJAX ajSimStats = new SimStatsAJAX();
  94. LogLinesAJAX ajLogLines = new LogLinesAJAX();
  95. Default_Report defaultReport = new Default_Report();
  96. Clients_report clientReport = new Clients_report();
  97. Sessions_Report sessionsReport = new Sessions_Report();
  98. reports.Add("prototype.js", protodep);
  99. reports.Add("updater.js", updatedep);
  100. reports.Add("activeconnectionsajax.html", ajConnections);
  101. reports.Add("simstatsajax.html", ajSimStats);
  102. reports.Add("activelogajax.html", ajLogLines);
  103. reports.Add("default.report", defaultReport);
  104. reports.Add("clients.report", clientReport);
  105. reports.Add("sessions.report", sessionsReport);
  106. ////
  107. // Add Your own Reports here (Do Not Modify Lines here Devs!)
  108. ////
  109. ////
  110. // End Own reports section
  111. ////
  112. MainServer.Instance.AddHTTPHandler("/SStats/", HandleStatsRequest);
  113. MainServer.Instance.AddHTTPHandler("/CAPS/VS/", HandleUnknownCAPSRequest);
  114. }
  115. public virtual void AddRegion(Scene scene)
  116. {
  117. if (!enabled)
  118. return;
  119. lock (m_scenes)
  120. {
  121. m_scenes.Add(scene);
  122. updateLogMod = m_scenes.Count * 2;
  123. m_simstatsCounters.Add(scene.RegionInfo.RegionID, new USimStatsData(scene.RegionInfo.RegionID));
  124. scene.EventManager.OnRegisterCaps += OnRegisterCaps;
  125. scene.EventManager.OnDeregisterCaps += OnDeRegisterCaps;
  126. scene.EventManager.OnClientClosed += OnClientClosed;
  127. scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
  128. scene.StatsReporter.OnSendStatsResult += ReceiveClassicSimStatsPacket;
  129. }
  130. }
  131. public void RegionLoaded(Scene scene)
  132. {
  133. }
  134. public void RemoveRegion(Scene scene)
  135. {
  136. if (!enabled)
  137. return;
  138. lock (m_scenes)
  139. {
  140. m_scenes.Remove(scene);
  141. updateLogMod = m_scenes.Count * 2;
  142. m_simstatsCounters.Remove(scene.RegionInfo.RegionID);
  143. }
  144. }
  145. public virtual void Close()
  146. {
  147. if (!enabled)
  148. return;
  149. dbConn.Close();
  150. dbConn.Dispose();
  151. m_sessions.Clear();
  152. m_scenes.Clear();
  153. reports.Clear();
  154. m_simstatsCounters.Clear();
  155. }
  156. public virtual string Name
  157. {
  158. get { return "ViewerStatsModule"; }
  159. }
  160. public Type ReplaceableInterface
  161. {
  162. get { return null; }
  163. }
  164. #endregion
  165. private void ReceiveClassicSimStatsPacket(SimStats stats)
  166. {
  167. if (!enabled)
  168. return;
  169. try
  170. {
  171. // Ignore the update if there's a report running right now
  172. // ignore the update if there hasn't been a hit in 30 seconds.
  173. if (concurrencyCounter > 0 || System.Environment.TickCount - lastHit > 30000)
  174. return;
  175. // We will conduct this under lock so that fields such as updateLogCounter do not potentially get
  176. // confused if a scene is removed.
  177. // XXX: Possibly the scope of this lock could be reduced though it's not critical.
  178. lock (m_scenes)
  179. {
  180. if (updateLogMod != 0 && updateLogCounter++ % updateLogMod == 0)
  181. {
  182. m_loglines = readLogLines(10);
  183. if (updateLogCounter > 10000)
  184. updateLogCounter = 1;
  185. }
  186. USimStatsData ss = m_simstatsCounters[stats.RegionUUID];
  187. if ((++ss.StatsCounter % updateStatsMod) == 0)
  188. {
  189. ss.ConsumeSimStats(stats);
  190. }
  191. }
  192. }
  193. catch (KeyNotFoundException)
  194. {
  195. }
  196. }
  197. private Hashtable HandleUnknownCAPSRequest(Hashtable request)
  198. {
  199. //string regpath = request["uri"].ToString();
  200. int response_code = 200;
  201. string contenttype = "text/html";
  202. UpdateUserStats(ParseViewerStats(request["body"].ToString(), UUID.Zero), dbConn);
  203. Hashtable responsedata = new Hashtable();
  204. responsedata["int_response_code"] = response_code;
  205. responsedata["content_type"] = contenttype;
  206. responsedata["keepalive"] = false;
  207. responsedata["str_response_string"] = string.Empty;
  208. return responsedata;
  209. }
  210. private Hashtable HandleStatsRequest(Hashtable request)
  211. {
  212. lastHit = System.Environment.TickCount;
  213. Hashtable responsedata = new Hashtable();
  214. string regpath = request["uri"].ToString();
  215. int response_code = 404;
  216. string contenttype = "text/html";
  217. string strOut = string.Empty;
  218. regpath = regpath.Remove(0, 8);
  219. if (regpath.Length == 0) regpath = "default.report";
  220. if (reports.ContainsKey(regpath))
  221. {
  222. IStatsController rep = reports[regpath];
  223. Hashtable repParams = new Hashtable();
  224. if (request.ContainsKey("requestvars"))
  225. repParams["RequestVars"] = request["requestvars"];
  226. else
  227. repParams["RequestVars"] = new Hashtable();
  228. if (request.ContainsKey("querystringkeys"))
  229. repParams["QueryStringKeys"] = request["querystringkeys"];
  230. else
  231. repParams["QueryStringKeys"] = new string[0];
  232. repParams["DatabaseConnection"] = dbConn;
  233. repParams["Scenes"] = m_scenes;
  234. repParams["SimStats"] = m_simstatsCounters;
  235. repParams["LogLines"] = m_loglines;
  236. repParams["Reports"] = reports;
  237. concurrencyCounter++;
  238. strOut = rep.RenderView(rep.ProcessModel(repParams));
  239. if (regpath.EndsWith("js"))
  240. {
  241. contenttype = "text/javascript";
  242. }
  243. concurrencyCounter--;
  244. response_code = 200;
  245. }
  246. else
  247. {
  248. strOut = MainServer.Instance.GetHTTP404("");
  249. }
  250. responsedata["int_response_code"] = response_code;
  251. responsedata["content_type"] = contenttype;
  252. responsedata["keepalive"] = false;
  253. responsedata["str_response_string"] = strOut;
  254. return responsedata;
  255. }
  256. private void CreateTables(SqliteConnection db)
  257. {
  258. using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db))
  259. {
  260. createcmd.ExecuteNonQuery();
  261. }
  262. }
  263. private void OnRegisterCaps(UUID agentID, Caps caps)
  264. {
  265. // m_log.DebugFormat("[WEB STATS MODULE]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
  266. string capsPath = "/CAPS/VS/" + UUID.Random();
  267. caps.RegisterHandler(
  268. "ViewerStats",
  269. new RestStreamHandler(
  270. "POST",
  271. capsPath,
  272. (request, path, param, httpRequest, httpResponse)
  273. => ViewerStatsReport(request, path, param, agentID, caps),
  274. "ViewerStats",
  275. agentID.ToString()));
  276. }
  277. private void OnDeRegisterCaps(UUID agentID, Caps caps)
  278. {
  279. }
  280. protected virtual void AddEventHandlers()
  281. {
  282. lock (m_scenes)
  283. {
  284. updateLogMod = m_scenes.Count * 2;
  285. foreach (Scene scene in m_scenes)
  286. {
  287. scene.EventManager.OnRegisterCaps += OnRegisterCaps;
  288. scene.EventManager.OnDeregisterCaps += OnDeRegisterCaps;
  289. scene.EventManager.OnClientClosed += OnClientClosed;
  290. scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
  291. }
  292. }
  293. }
  294. private void OnMakeRootAgent(ScenePresence agent)
  295. {
  296. // m_log.DebugFormat(
  297. // "[WEB STATS MODULE]: Looking for session {0} for {1} in {2}",
  298. // agent.ControllingClient.SessionId, agent.Name, agent.Scene.Name);
  299. lock (m_sessions)
  300. {
  301. UserSession uid;
  302. if (!m_sessions.ContainsKey(agent.UUID))
  303. {
  304. UserSessionData usd = UserSessionUtil.newUserSessionData();
  305. uid = new UserSession();
  306. uid.name_f = agent.Firstname;
  307. uid.name_l = agent.Lastname;
  308. uid.session_data = usd;
  309. m_sessions.Add(agent.UUID, uid);
  310. }
  311. else
  312. {
  313. uid = m_sessions[agent.UUID];
  314. }
  315. uid.region_id = agent.Scene.RegionInfo.RegionID;
  316. uid.session_id = agent.ControllingClient.SessionId;
  317. }
  318. }
  319. private void OnClientClosed(UUID agentID, Scene scene)
  320. {
  321. lock (m_sessions)
  322. {
  323. if (m_sessions.ContainsKey(agentID) && m_sessions[agentID].region_id == scene.RegionInfo.RegionID)
  324. {
  325. m_sessions.Remove(agentID);
  326. }
  327. }
  328. }
  329. private string readLogLines(int amount)
  330. {
  331. Encoding encoding = Encoding.ASCII;
  332. int sizeOfChar = encoding.GetByteCount("\n");
  333. byte[] buffer = encoding.GetBytes("\n");
  334. string logfile = Util.logDir() + "/" + "OpenSim.log";
  335. FileStream fs = new FileStream(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
  336. Int64 tokenCount = 0;
  337. Int64 endPosition = fs.Length / sizeOfChar;
  338. for (Int64 position = sizeOfChar; position < endPosition; position += sizeOfChar)
  339. {
  340. fs.Seek(-position, SeekOrigin.End);
  341. fs.Read(buffer, 0, buffer.Length);
  342. if (encoding.GetString(buffer) == "\n")
  343. {
  344. tokenCount++;
  345. if (tokenCount == amount)
  346. {
  347. byte[] returnBuffer = new byte[fs.Length - fs.Position];
  348. fs.Read(returnBuffer, 0, returnBuffer.Length);
  349. fs.Close();
  350. fs.Dispose();
  351. return encoding.GetString(returnBuffer);
  352. }
  353. }
  354. }
  355. // handle case where number of tokens in file is less than numberOfTokens
  356. fs.Seek(0, SeekOrigin.Begin);
  357. buffer = new byte[fs.Length];
  358. fs.Read(buffer, 0, buffer.Length);
  359. fs.Close();
  360. fs.Dispose();
  361. return encoding.GetString(buffer);
  362. }
  363. /// <summary>
  364. /// Callback for a viewerstats cap
  365. /// </summary>
  366. /// <param name="request"></param>
  367. /// <param name="path"></param>
  368. /// <param name="param"></param>
  369. /// <param name="agentID"></param>
  370. /// <param name="caps"></param>
  371. /// <returns></returns>
  372. private string ViewerStatsReport(string request, string path, string param,
  373. UUID agentID, Caps caps)
  374. {
  375. // m_log.DebugFormat("[WEB STATS MODULE]: Received viewer starts report from {0}", agentID);
  376. UpdateUserStats(ParseViewerStats(request, agentID), dbConn);
  377. return String.Empty;
  378. }
  379. private UserSession ParseViewerStats(string request, UUID agentID)
  380. {
  381. UserSession uid = new UserSession();
  382. UserSessionData usd;
  383. OSD message = OSDParser.DeserializeLLSDXml(request);
  384. OSDMap mmap;
  385. lock (m_sessions)
  386. {
  387. if (agentID != UUID.Zero)
  388. {
  389. if (!m_sessions.ContainsKey(agentID))
  390. {
  391. m_log.WarnFormat("[WEB STATS MODULE]: no session for stat disclosure for agent {0}", agentID);
  392. return new UserSession();
  393. }
  394. uid = m_sessions[agentID];
  395. // m_log.DebugFormat("[WEB STATS MODULE]: Got session {0} for {1}", uid.session_id, agentID);
  396. }
  397. else
  398. {
  399. // parse through the beginning to locate the session
  400. if (message.Type != OSDType.Map)
  401. return new UserSession();
  402. mmap = (OSDMap)message;
  403. {
  404. UUID sessionID = mmap["session_id"].AsUUID();
  405. if (sessionID == UUID.Zero)
  406. return new UserSession();
  407. // search through each session looking for the owner
  408. foreach (UUID usersessionid in m_sessions.Keys)
  409. {
  410. // got it!
  411. if (m_sessions[usersessionid].session_id == sessionID)
  412. {
  413. agentID = usersessionid;
  414. uid = m_sessions[usersessionid];
  415. break;
  416. }
  417. }
  418. // can't find a session
  419. if (agentID == UUID.Zero)
  420. {
  421. return new UserSession();
  422. }
  423. }
  424. }
  425. }
  426. usd = uid.session_data;
  427. if (message.Type != OSDType.Map)
  428. return new UserSession();
  429. mmap = (OSDMap)message;
  430. {
  431. if (mmap["agent"].Type != OSDType.Map)
  432. return new UserSession();
  433. OSDMap agent_map = (OSDMap)mmap["agent"];
  434. usd.agent_id = agentID;
  435. usd.name_f = uid.name_f;
  436. usd.name_l = uid.name_l;
  437. usd.region_id = uid.region_id;
  438. usd.a_language = agent_map["language"].AsString();
  439. usd.mem_use = (float)agent_map["mem_use"].AsReal();
  440. usd.meters_traveled = (float)agent_map["meters_traveled"].AsReal();
  441. usd.regions_visited = agent_map["regions_visited"].AsInteger();
  442. usd.run_time = (float)agent_map["run_time"].AsReal();
  443. usd.start_time = (float)agent_map["start_time"].AsReal();
  444. usd.client_version = agent_map["version"].AsString();
  445. UserSessionUtil.UpdateMultiItems(ref usd, agent_map["agents_in_view"].AsInteger(),
  446. (float)agent_map["ping"].AsReal(),
  447. (float)agent_map["sim_fps"].AsReal(),
  448. (float)agent_map["fps"].AsReal());
  449. if (mmap["downloads"].Type != OSDType.Map)
  450. return new UserSession();
  451. OSDMap downloads_map = (OSDMap)mmap["downloads"];
  452. usd.d_object_kb = (float)downloads_map["object_kbytes"].AsReal();
  453. usd.d_texture_kb = (float)downloads_map["texture_kbytes"].AsReal();
  454. usd.d_world_kb = (float)downloads_map["workd_kbytes"].AsReal();
  455. // m_log.DebugFormat("[WEB STATS MODULE]: mmap[\"session_id\"] = [{0}]", mmap["session_id"].AsUUID());
  456. usd.session_id = mmap["session_id"].AsUUID();
  457. if (mmap["system"].Type != OSDType.Map)
  458. return new UserSession();
  459. OSDMap system_map = (OSDMap)mmap["system"];
  460. usd.s_cpu = system_map["cpu"].AsString();
  461. usd.s_gpu = system_map["gpu"].AsString();
  462. usd.s_os = system_map["os"].AsString();
  463. usd.s_ram = system_map["ram"].AsInteger();
  464. if (mmap["stats"].Type != OSDType.Map)
  465. return new UserSession();
  466. OSDMap stats_map = (OSDMap)mmap["stats"];
  467. {
  468. if (stats_map["failures"].Type != OSDType.Map)
  469. return new UserSession();
  470. OSDMap stats_failures = (OSDMap)stats_map["failures"];
  471. usd.f_dropped = stats_failures["dropped"].AsInteger();
  472. usd.f_failed_resends = stats_failures["failed_resends"].AsInteger();
  473. usd.f_invalid = stats_failures["invalid"].AsInteger();
  474. usd.f_resent = stats_failures["resent"].AsInteger();
  475. usd.f_send_packet = stats_failures["send_packet"].AsInteger();
  476. if (stats_map["net"].Type != OSDType.Map)
  477. return new UserSession();
  478. OSDMap stats_net = (OSDMap)stats_map["net"];
  479. {
  480. if (stats_net["in"].Type != OSDType.Map)
  481. return new UserSession();
  482. OSDMap net_in = (OSDMap)stats_net["in"];
  483. usd.n_in_kb = (float)net_in["kbytes"].AsReal();
  484. usd.n_in_pk = net_in["packets"].AsInteger();
  485. if (stats_net["out"].Type != OSDType.Map)
  486. return new UserSession();
  487. OSDMap net_out = (OSDMap)stats_net["out"];
  488. usd.n_out_kb = (float)net_out["kbytes"].AsReal();
  489. usd.n_out_pk = net_out["packets"].AsInteger();
  490. }
  491. }
  492. }
  493. uid.session_data = usd;
  494. m_sessions[agentID] = uid;
  495. // m_log.DebugFormat(
  496. // "[WEB STATS MODULE]: Parse data for {0} {1}, session {2}", uid.name_f, uid.name_l, uid.session_id);
  497. return uid;
  498. }
  499. private void UpdateUserStats(UserSession uid, SqliteConnection db)
  500. {
  501. // m_log.DebugFormat(
  502. // "[WEB STATS MODULE]: Updating user stats for {0} {1}, session {2}", uid.name_f, uid.name_l, uid.session_id);
  503. if (uid.session_id == UUID.Zero)
  504. return;
  505. lock (db)
  506. {
  507. using (SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_INSERT, db))
  508. {
  509. updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString()));
  510. updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString()));
  511. updatecmd.Parameters.Add(new SqliteParameter(":region_id", uid.session_data.region_id.ToString()));
  512. updatecmd.Parameters.Add(new SqliteParameter(":last_updated", (int) uid.session_data.last_updated));
  513. updatecmd.Parameters.Add(new SqliteParameter(":remote_ip", uid.session_data.remote_ip));
  514. updatecmd.Parameters.Add(new SqliteParameter(":name_f", uid.session_data.name_f));
  515. updatecmd.Parameters.Add(new SqliteParameter(":name_l", uid.session_data.name_l));
  516. updatecmd.Parameters.Add(new SqliteParameter(":avg_agents_in_view", uid.session_data.avg_agents_in_view));
  517. updatecmd.Parameters.Add(new SqliteParameter(":min_agents_in_view",
  518. (int) uid.session_data.min_agents_in_view));
  519. updatecmd.Parameters.Add(new SqliteParameter(":max_agents_in_view",
  520. (int) uid.session_data.max_agents_in_view));
  521. updatecmd.Parameters.Add(new SqliteParameter(":mode_agents_in_view",
  522. (int) uid.session_data.mode_agents_in_view));
  523. updatecmd.Parameters.Add(new SqliteParameter(":avg_fps", uid.session_data.avg_fps));
  524. updatecmd.Parameters.Add(new SqliteParameter(":min_fps", uid.session_data.min_fps));
  525. updatecmd.Parameters.Add(new SqliteParameter(":max_fps", uid.session_data.max_fps));
  526. updatecmd.Parameters.Add(new SqliteParameter(":mode_fps", uid.session_data.mode_fps));
  527. updatecmd.Parameters.Add(new SqliteParameter(":a_language", uid.session_data.a_language));
  528. updatecmd.Parameters.Add(new SqliteParameter(":mem_use", uid.session_data.mem_use));
  529. updatecmd.Parameters.Add(new SqliteParameter(":meters_traveled", uid.session_data.meters_traveled));
  530. updatecmd.Parameters.Add(new SqliteParameter(":avg_ping", uid.session_data.avg_ping));
  531. updatecmd.Parameters.Add(new SqliteParameter(":min_ping", uid.session_data.min_ping));
  532. updatecmd.Parameters.Add(new SqliteParameter(":max_ping", uid.session_data.max_ping));
  533. updatecmd.Parameters.Add(new SqliteParameter(":mode_ping", uid.session_data.mode_ping));
  534. updatecmd.Parameters.Add(new SqliteParameter(":regions_visited", uid.session_data.regions_visited));
  535. updatecmd.Parameters.Add(new SqliteParameter(":run_time", uid.session_data.run_time));
  536. updatecmd.Parameters.Add(new SqliteParameter(":avg_sim_fps", uid.session_data.avg_sim_fps));
  537. updatecmd.Parameters.Add(new SqliteParameter(":min_sim_fps", uid.session_data.min_sim_fps));
  538. updatecmd.Parameters.Add(new SqliteParameter(":max_sim_fps", uid.session_data.max_sim_fps));
  539. updatecmd.Parameters.Add(new SqliteParameter(":mode_sim_fps", uid.session_data.mode_sim_fps));
  540. updatecmd.Parameters.Add(new SqliteParameter(":start_time", uid.session_data.start_time));
  541. updatecmd.Parameters.Add(new SqliteParameter(":client_version", uid.session_data.client_version));
  542. updatecmd.Parameters.Add(new SqliteParameter(":s_cpu", uid.session_data.s_cpu));
  543. updatecmd.Parameters.Add(new SqliteParameter(":s_gpu", uid.session_data.s_gpu));
  544. updatecmd.Parameters.Add(new SqliteParameter(":s_os", uid.session_data.s_os));
  545. updatecmd.Parameters.Add(new SqliteParameter(":s_ram", uid.session_data.s_ram));
  546. updatecmd.Parameters.Add(new SqliteParameter(":d_object_kb", uid.session_data.d_object_kb));
  547. updatecmd.Parameters.Add(new SqliteParameter(":d_texture_kb", uid.session_data.d_texture_kb));
  548. updatecmd.Parameters.Add(new SqliteParameter(":d_world_kb", uid.session_data.d_world_kb));
  549. updatecmd.Parameters.Add(new SqliteParameter(":n_in_kb", uid.session_data.n_in_kb));
  550. updatecmd.Parameters.Add(new SqliteParameter(":n_in_pk", uid.session_data.n_in_pk));
  551. updatecmd.Parameters.Add(new SqliteParameter(":n_out_kb", uid.session_data.n_out_kb));
  552. updatecmd.Parameters.Add(new SqliteParameter(":n_out_pk", uid.session_data.n_out_pk));
  553. updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped));
  554. updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends));
  555. updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid));
  556. updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit));
  557. updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent));
  558. updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet));
  559. // StringBuilder parameters = new StringBuilder();
  560. // SqliteParameterCollection spc = updatecmd.Parameters;
  561. // foreach (SqliteParameter sp in spc)
  562. // parameters.AppendFormat("{0}={1},", sp.ParameterName, sp.Value);
  563. //
  564. // m_log.DebugFormat("[WEB STATS MODULE]: Parameters {0}", parameters);
  565. // m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id);
  566. updatecmd.ExecuteNonQuery();
  567. }
  568. }
  569. }
  570. #region SQL
  571. private const string SQL_STATS_TABLE_CREATE = @"CREATE TABLE IF NOT EXISTS stats_session_data (
  572. session_id VARCHAR(36) NOT NULL PRIMARY KEY,
  573. agent_id VARCHAR(36) NOT NULL DEFAULT '',
  574. region_id VARCHAR(36) NOT NULL DEFAULT '',
  575. last_updated INT NOT NULL DEFAULT '0',
  576. remote_ip VARCHAR(16) NOT NULL DEFAULT '',
  577. name_f VARCHAR(50) NOT NULL DEFAULT '',
  578. name_l VARCHAR(50) NOT NULL DEFAULT '',
  579. avg_agents_in_view FLOAT NOT NULL DEFAULT '0',
  580. min_agents_in_view INT NOT NULL DEFAULT '0',
  581. max_agents_in_view INT NOT NULL DEFAULT '0',
  582. mode_agents_in_view INT NOT NULL DEFAULT '0',
  583. avg_fps FLOAT NOT NULL DEFAULT '0',
  584. min_fps FLOAT NOT NULL DEFAULT '0',
  585. max_fps FLOAT NOT NULL DEFAULT '0',
  586. mode_fps FLOAT NOT NULL DEFAULT '0',
  587. a_language VARCHAR(25) NOT NULL DEFAULT '',
  588. mem_use FLOAT NOT NULL DEFAULT '0',
  589. meters_traveled FLOAT NOT NULL DEFAULT '0',
  590. avg_ping FLOAT NOT NULL DEFAULT '0',
  591. min_ping FLOAT NOT NULL DEFAULT '0',
  592. max_ping FLOAT NOT NULL DEFAULT '0',
  593. mode_ping FLOAT NOT NULL DEFAULT '0',
  594. regions_visited INT NOT NULL DEFAULT '0',
  595. run_time FLOAT NOT NULL DEFAULT '0',
  596. avg_sim_fps FLOAT NOT NULL DEFAULT '0',
  597. min_sim_fps FLOAT NOT NULL DEFAULT '0',
  598. max_sim_fps FLOAT NOT NULL DEFAULT '0',
  599. mode_sim_fps FLOAT NOT NULL DEFAULT '0',
  600. start_time FLOAT NOT NULL DEFAULT '0',
  601. client_version VARCHAR(255) NOT NULL DEFAULT '',
  602. s_cpu VARCHAR(255) NOT NULL DEFAULT '',
  603. s_gpu VARCHAR(255) NOT NULL DEFAULT '',
  604. s_os VARCHAR(2255) NOT NULL DEFAULT '',
  605. s_ram INT NOT NULL DEFAULT '0',
  606. d_object_kb FLOAT NOT NULL DEFAULT '0',
  607. d_texture_kb FLOAT NOT NULL DEFAULT '0',
  608. d_world_kb FLOAT NOT NULL DEFAULT '0',
  609. n_in_kb FLOAT NOT NULL DEFAULT '0',
  610. n_in_pk INT NOT NULL DEFAULT '0',
  611. n_out_kb FLOAT NOT NULL DEFAULT '0',
  612. n_out_pk INT NOT NULL DEFAULT '0',
  613. f_dropped INT NOT NULL DEFAULT '0',
  614. f_failed_resends INT NOT NULL DEFAULT '0',
  615. f_invalid INT NOT NULL DEFAULT '0',
  616. f_off_circuit INT NOT NULL DEFAULT '0',
  617. f_resent INT NOT NULL DEFAULT '0',
  618. f_send_packet INT NOT NULL DEFAULT '0'
  619. );";
  620. private const string SQL_STATS_TABLE_INSERT = @"INSERT OR REPLACE INTO stats_session_data (
  621. session_id, agent_id, region_id, last_updated, remote_ip, name_f, name_l, avg_agents_in_view, min_agents_in_view, max_agents_in_view,
  622. mode_agents_in_view, avg_fps, min_fps, max_fps, mode_fps, a_language, mem_use, meters_traveled, avg_ping, min_ping, max_ping, mode_ping,
  623. regions_visited, run_time, avg_sim_fps, min_sim_fps, max_sim_fps, mode_sim_fps, start_time, client_version, s_cpu, s_gpu, s_os, s_ram,
  624. d_object_kb, d_texture_kb, d_world_kb, n_in_kb, n_in_pk, n_out_kb, n_out_pk, f_dropped, f_failed_resends, f_invalid, f_off_circuit,
  625. f_resent, f_send_packet
  626. )
  627. VALUES
  628. (
  629. :session_id, :agent_id, :region_id, :last_updated, :remote_ip, :name_f, :name_l, :avg_agents_in_view, :min_agents_in_view, :max_agents_in_view,
  630. :mode_agents_in_view, :avg_fps, :min_fps, :max_fps, :mode_fps, :a_language, :mem_use, :meters_traveled, :avg_ping, :min_ping, :max_ping, :mode_ping,
  631. :regions_visited, :run_time, :avg_sim_fps, :min_sim_fps, :max_sim_fps, :mode_sim_fps, :start_time, :client_version, :s_cpu, :s_gpu, :s_os, :s_ram,
  632. :d_object_kb, :d_texture_kb, :d_world_kb, :n_in_kb, :n_in_pk, :n_out_kb, :n_out_pk, :f_dropped, :f_failed_resends, :f_invalid, :f_off_circuit,
  633. :f_resent, :f_send_packet
  634. )
  635. ";
  636. #endregion
  637. }
  638. public static class UserSessionUtil
  639. {
  640. public static UserSessionData newUserSessionData()
  641. {
  642. UserSessionData obj = ZeroSession(new UserSessionData());
  643. return obj;
  644. }
  645. public static void UpdateMultiItems(ref UserSessionData s, int agents_in_view, float ping, float sim_fps, float fps)
  646. {
  647. // don't insert zero values here or it'll skew the statistics.
  648. if (agents_in_view == 0 && fps == 0 && sim_fps == 0 && ping == 0)
  649. return;
  650. s._agents_in_view.Add(agents_in_view);
  651. s._fps.Add(fps);
  652. s._sim_fps.Add(sim_fps);
  653. s._ping.Add(ping);
  654. int[] __agents_in_view = s._agents_in_view.ToArray();
  655. s.avg_agents_in_view = ArrayAvg_i(__agents_in_view);
  656. s.min_agents_in_view = ArrayMin_i(__agents_in_view);
  657. s.max_agents_in_view = ArrayMax_i(__agents_in_view);
  658. s.mode_agents_in_view = ArrayMode_i(__agents_in_view);
  659. float[] __fps = s._fps.ToArray();
  660. s.avg_fps = ArrayAvg_f(__fps);
  661. s.min_fps = ArrayMin_f(__fps);
  662. s.max_fps = ArrayMax_f(__fps);
  663. s.mode_fps = ArrayMode_f(__fps);
  664. float[] __sim_fps = s._sim_fps.ToArray();
  665. s.avg_sim_fps = ArrayAvg_f(__sim_fps);
  666. s.min_sim_fps = ArrayMin_f(__sim_fps);
  667. s.max_sim_fps = ArrayMax_f(__sim_fps);
  668. s.mode_sim_fps = ArrayMode_f(__sim_fps);
  669. float[] __ping = s._ping.ToArray();
  670. s.avg_ping = ArrayAvg_f(__ping);
  671. s.min_ping = ArrayMin_f(__ping);
  672. s.max_ping = ArrayMax_f(__ping);
  673. s.mode_ping = ArrayMode_f(__ping);
  674. }
  675. #region Statistics
  676. public static int ArrayMin_i(int[] arr)
  677. {
  678. int cnt = arr.Length;
  679. if (cnt == 0)
  680. return 0;
  681. Array.Sort(arr);
  682. return arr[0];
  683. }
  684. public static int ArrayMax_i(int[] arr)
  685. {
  686. int cnt = arr.Length;
  687. if (cnt == 0)
  688. return 0;
  689. Array.Sort(arr);
  690. return arr[cnt-1];
  691. }
  692. public static float ArrayMin_f(float[] arr)
  693. {
  694. int cnt = arr.Length;
  695. if (cnt == 0)
  696. return 0;
  697. Array.Sort(arr);
  698. return arr[0];
  699. }
  700. public static float ArrayMax_f(float[] arr)
  701. {
  702. int cnt = arr.Length;
  703. if (cnt == 0)
  704. return 0;
  705. Array.Sort(arr);
  706. return arr[cnt - 1];
  707. }
  708. public static float ArrayAvg_i(int[] arr)
  709. {
  710. int cnt = arr.Length;
  711. if (cnt == 0)
  712. return 0;
  713. float result = arr[0];
  714. for (int i = 1; i < cnt; i++)
  715. result += arr[i];
  716. return result / cnt;
  717. }
  718. public static float ArrayAvg_f(float[] arr)
  719. {
  720. int cnt = arr.Length;
  721. if (cnt == 0)
  722. return 0;
  723. float result = arr[0];
  724. for (int i = 1; i < cnt; i++)
  725. result += arr[i];
  726. return result / cnt;
  727. }
  728. public static float ArrayMode_f(float[] arr)
  729. {
  730. List<float> mode = new List<float>();
  731. float[] srtArr = new float[arr.Length];
  732. float[,] freq = new float[arr.Length, 2];
  733. Array.Copy(arr, srtArr, arr.Length);
  734. Array.Sort(srtArr);
  735. float tmp = srtArr[0];
  736. int index = 0;
  737. int i = 0;
  738. while (i < srtArr.Length)
  739. {
  740. freq[index, 0] = tmp;
  741. while (tmp == srtArr[i])
  742. {
  743. freq[index, 1]++;
  744. i++;
  745. if (i > srtArr.Length - 1)
  746. break;
  747. }
  748. if (i < srtArr.Length)
  749. {
  750. tmp = srtArr[i];
  751. index++;
  752. }
  753. }
  754. Array.Clear(srtArr, 0, srtArr.Length);
  755. for (i = 0; i < srtArr.Length; i++)
  756. srtArr[i] = freq[i, 1];
  757. Array.Sort(srtArr);
  758. if ((srtArr[srtArr.Length - 1]) == 0 || (srtArr[srtArr.Length - 1]) == 1)
  759. return 0;
  760. float freqtest = (float)freq.Length / freq.Rank;
  761. for (i = 0; i < freqtest; i++)
  762. {
  763. if (freq[i, 1] == srtArr[index])
  764. mode.Add(freq[i, 0]);
  765. }
  766. return mode.ToArray()[0];
  767. }
  768. public static int ArrayMode_i(int[] arr)
  769. {
  770. List<int> mode = new List<int>();
  771. int[] srtArr = new int[arr.Length];
  772. int[,] freq = new int[arr.Length, 2];
  773. Array.Copy(arr, srtArr, arr.Length);
  774. Array.Sort(srtArr);
  775. int tmp = srtArr[0];
  776. int index = 0;
  777. int i = 0;
  778. while (i < srtArr.Length)
  779. {
  780. freq[index, 0] = tmp;
  781. while (tmp == srtArr[i])
  782. {
  783. freq[index, 1]++;
  784. i++;
  785. if (i > srtArr.Length - 1)
  786. break;
  787. }
  788. if (i < srtArr.Length)
  789. {
  790. tmp = srtArr[i];
  791. index++;
  792. }
  793. }
  794. Array.Clear(srtArr, 0, srtArr.Length);
  795. for (i = 0; i < srtArr.Length; i++)
  796. srtArr[i] = freq[i, 1];
  797. Array.Sort(srtArr);
  798. if ((srtArr[srtArr.Length - 1]) == 0 || (srtArr[srtArr.Length - 1]) == 1)
  799. return 0;
  800. float freqtest = (float)freq.Length / freq.Rank;
  801. for (i = 0; i < freqtest; i++)
  802. {
  803. if (freq[i, 1] == srtArr[index])
  804. mode.Add(freq[i, 0]);
  805. }
  806. return mode.ToArray()[0];
  807. }
  808. #endregion
  809. private static UserSessionData ZeroSession(UserSessionData s)
  810. {
  811. s.session_id = UUID.Zero;
  812. s.agent_id = UUID.Zero;
  813. s.region_id = UUID.Zero;
  814. s.last_updated = Util.UnixTimeSinceEpoch();
  815. s.remote_ip = "";
  816. s.name_f = "";
  817. s.name_l = "";
  818. s.avg_agents_in_view = 0;
  819. s.min_agents_in_view = 0;
  820. s.max_agents_in_view = 0;
  821. s.mode_agents_in_view = 0;
  822. s.avg_fps = 0;
  823. s.min_fps = 0;
  824. s.max_fps = 0;
  825. s.mode_fps = 0;
  826. s.a_language = "";
  827. s.mem_use = 0;
  828. s.meters_traveled = 0;
  829. s.avg_ping = 0;
  830. s.min_ping = 0;
  831. s.max_ping = 0;
  832. s.mode_ping = 0;
  833. s.regions_visited = 0;
  834. s.run_time = 0;
  835. s.avg_sim_fps = 0;
  836. s.min_sim_fps = 0;
  837. s.max_sim_fps = 0;
  838. s.mode_sim_fps = 0;
  839. s.start_time = 0;
  840. s.client_version = "";
  841. s.s_cpu = "";
  842. s.s_gpu = "";
  843. s.s_os = "";
  844. s.s_ram = 0;
  845. s.d_object_kb = 0;
  846. s.d_texture_kb = 0;
  847. s.d_world_kb = 0;
  848. s.n_in_kb = 0;
  849. s.n_in_pk = 0;
  850. s.n_out_kb = 0;
  851. s.n_out_pk = 0;
  852. s.f_dropped = 0;
  853. s.f_failed_resends = 0;
  854. s.f_invalid = 0;
  855. s.f_off_circuit = 0;
  856. s.f_resent = 0;
  857. s.f_send_packet = 0;
  858. s._ping = new List<float>();
  859. s._fps = new List<float>();
  860. s._sim_fps = new List<float>();
  861. s._agents_in_view = new List<int>();
  862. return s;
  863. }
  864. }
  865. #region structs
  866. public class UserSession
  867. {
  868. public UUID session_id;
  869. public UUID region_id;
  870. public string name_f;
  871. public string name_l;
  872. public UserSessionData session_data;
  873. }
  874. public struct UserSessionData
  875. {
  876. public UUID session_id;
  877. public UUID agent_id;
  878. public UUID region_id;
  879. public float last_updated;
  880. public string remote_ip;
  881. public string name_f;
  882. public string name_l;
  883. public float avg_agents_in_view;
  884. public float min_agents_in_view;
  885. public float max_agents_in_view;
  886. public float mode_agents_in_view;
  887. public float avg_fps;
  888. public float min_fps;
  889. public float max_fps;
  890. public float mode_fps;
  891. public string a_language;
  892. public float mem_use;
  893. public float meters_traveled;
  894. public float avg_ping;
  895. public float min_ping;
  896. public float max_ping;
  897. public float mode_ping;
  898. public int regions_visited;
  899. public float run_time;
  900. public float avg_sim_fps;
  901. public float min_sim_fps;
  902. public float max_sim_fps;
  903. public float mode_sim_fps;
  904. public float start_time;
  905. public string client_version;
  906. public string s_cpu;
  907. public string s_gpu;
  908. public string s_os;
  909. public int s_ram;
  910. public float d_object_kb;
  911. public float d_texture_kb;
  912. public float d_world_kb;
  913. public float n_in_kb;
  914. public int n_in_pk;
  915. public float n_out_kb;
  916. public int n_out_pk;
  917. public int f_dropped;
  918. public int f_failed_resends;
  919. public int f_invalid;
  920. public int f_off_circuit;
  921. public int f_resent;
  922. public int f_send_packet;
  923. public List<float> _ping;
  924. public List<float> _fps;
  925. public List<float> _sim_fps;
  926. public List<int> _agents_in_view;
  927. }
  928. #endregion
  929. public class USimStatsData
  930. {
  931. private UUID m_regionID = UUID.Zero;
  932. private volatile int m_statcounter = 0;
  933. private volatile float m_timeDilation;
  934. private volatile float m_simFps;
  935. private volatile float m_physicsFps;
  936. private volatile float m_agentUpdates;
  937. private volatile float m_rootAgents;
  938. private volatile float m_childAgents;
  939. private volatile float m_totalPrims;
  940. private volatile float m_activePrims;
  941. private volatile float m_totalFrameTime;
  942. private volatile float m_netFrameTime;
  943. private volatile float m_physicsFrameTime;
  944. private volatile float m_otherFrameTime;
  945. private volatile float m_imageFrameTime;
  946. private volatile float m_inPacketsPerSecond;
  947. private volatile float m_outPacketsPerSecond;
  948. private volatile float m_unackedBytes;
  949. private volatile float m_agentFrameTime;
  950. private volatile float m_pendingDownloads;
  951. private volatile float m_pendingUploads;
  952. private volatile float m_activeScripts;
  953. private volatile float m_scriptLinesPerSecond;
  954. public UUID RegionId { get { return m_regionID; } }
  955. public int StatsCounter { get { return m_statcounter; } set { m_statcounter = value;}}
  956. public float TimeDilation { get { return m_timeDilation; } }
  957. public float SimFps { get { return m_simFps; } }
  958. public float PhysicsFps { get { return m_physicsFps; } }
  959. public float AgentUpdates { get { return m_agentUpdates; } }
  960. public float RootAgents { get { return m_rootAgents; } }
  961. public float ChildAgents { get { return m_childAgents; } }
  962. public float TotalPrims { get { return m_totalPrims; } }
  963. public float ActivePrims { get { return m_activePrims; } }
  964. public float TotalFrameTime { get { return m_totalFrameTime; } }
  965. public float NetFrameTime { get { return m_netFrameTime; } }
  966. public float PhysicsFrameTime { get { return m_physicsFrameTime; } }
  967. public float OtherFrameTime { get { return m_otherFrameTime; } }
  968. public float ImageFrameTime { get { return m_imageFrameTime; } }
  969. public float InPacketsPerSecond { get { return m_inPacketsPerSecond; } }
  970. public float OutPacketsPerSecond { get { return m_outPacketsPerSecond; } }
  971. public float UnackedBytes { get { return m_unackedBytes; } }
  972. public float AgentFrameTime { get { return m_agentFrameTime; } }
  973. public float PendingDownloads { get { return m_pendingDownloads; } }
  974. public float PendingUploads { get { return m_pendingUploads; } }
  975. public float ActiveScripts { get { return m_activeScripts; } }
  976. public float ScriptLinesPerSecond { get { return m_scriptLinesPerSecond; } }
  977. public USimStatsData(UUID pRegionID)
  978. {
  979. m_regionID = pRegionID;
  980. }
  981. public void ConsumeSimStats(SimStats stats)
  982. {
  983. m_regionID = stats.RegionUUID;
  984. m_timeDilation = stats.StatsBlock[0].StatValue;
  985. m_simFps = stats.StatsBlock[1].StatValue;
  986. m_physicsFps = stats.StatsBlock[2].StatValue;
  987. m_agentUpdates = stats.StatsBlock[3].StatValue;
  988. m_rootAgents = stats.StatsBlock[4].StatValue;
  989. m_childAgents = stats.StatsBlock[5].StatValue;
  990. m_totalPrims = stats.StatsBlock[6].StatValue;
  991. m_activePrims = stats.StatsBlock[7].StatValue;
  992. m_totalFrameTime = stats.StatsBlock[8].StatValue;
  993. m_netFrameTime = stats.StatsBlock[9].StatValue;
  994. m_physicsFrameTime = stats.StatsBlock[10].StatValue;
  995. m_otherFrameTime = stats.StatsBlock[11].StatValue;
  996. m_imageFrameTime = stats.StatsBlock[12].StatValue;
  997. m_inPacketsPerSecond = stats.StatsBlock[13].StatValue;
  998. m_outPacketsPerSecond = stats.StatsBlock[14].StatValue;
  999. m_unackedBytes = stats.StatsBlock[15].StatValue;
  1000. m_agentFrameTime = stats.StatsBlock[16].StatValue;
  1001. m_pendingDownloads = stats.StatsBlock[17].StatValue;
  1002. m_pendingUploads = stats.StatsBlock[18].StatValue;
  1003. m_activeScripts = stats.StatsBlock[19].StatValue;
  1004. m_scriptLinesPerSecond = stats.StatsBlock[20].StatValue;
  1005. }
  1006. }
  1007. }