WebStatsModule.cs 47 KB

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