WebStatsModule.cs 46 KB

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