LindenUDPInfoModule.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Monitoring;
  39. using OpenSim.Region.ClientStack.LindenUDP;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. namespace OpenSim.Region.OptionalModules.UDP.Linden
  43. {
  44. /// <summary>
  45. /// A module that just holds commands for inspecting the current state of the Linden UDP stack.
  46. /// </summary>
  47. /// <remarks>
  48. /// All actual client stack functionality remains in OpenSim.Region.ClientStack.LindenUDP
  49. /// </remarks>
  50. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LindenUDPInfoModule")]
  51. public class LindenUDPInfoModule : ISharedRegionModule
  52. {
  53. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  54. protected Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
  55. public string Name { get { return "Linden UDP Module"; } }
  56. public Type ReplaceableInterface { get { return null; } }
  57. public void Initialise(IConfigSource source)
  58. {
  59. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: INITIALIZED MODULE");
  60. }
  61. public void PostInitialise()
  62. {
  63. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: POST INITIALIZED MODULE");
  64. }
  65. public void Close()
  66. {
  67. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: CLOSED MODULE");
  68. }
  69. public void AddRegion(Scene scene)
  70. {
  71. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  72. lock (m_scenes)
  73. m_scenes[scene.RegionInfo.RegionID] = scene;
  74. scene.AddCommand(
  75. "Comms", this, "show pqueues",
  76. "show pqueues [full]",
  77. "Show priority queue data for each client",
  78. "Without the 'full' option, only root agents are shown."
  79. + " With the 'full' option child agents are also shown.",
  80. (mod, cmd) => MainConsole.Instance.Output(GetPQueuesReport(cmd)));
  81. scene.AddCommand(
  82. "Comms", this, "show queues",
  83. "show queues [full]",
  84. "Show queue data for each client",
  85. "Without the 'full' option, only root agents are shown.\n"
  86. + "With the 'full' option child agents are also shown.\n\n"
  87. + "Type - Rt is a root (avatar) client whilst cd is a child (neighbour interacting) client.\n"
  88. + "Since Last In - Time in milliseconds since last packet received.\n"
  89. + "Pkts In - Number of packets processed from the client.\n"
  90. + "Pkts Out - Number of packets sent to the client.\n"
  91. + "Pkts Resent - Number of packets resent to the client.\n"
  92. + "Bytes Unacked - Number of bytes transferred to the client that are awaiting acknowledgement.\n"
  93. + "Q Pkts * - Number of packets of various types (land, wind, etc.) to be sent to the client that are waiting for available bandwidth.\n",
  94. (mod, cmd) => MainConsole.Instance.Output(GetQueuesReport(cmd)));
  95. scene.AddCommand(
  96. "Comms", this, "show image queues",
  97. "show image queues <first-name> <last-name>",
  98. "Show the image queues (textures downloaded via UDP) for a particular client.",
  99. (mod, cmd) => MainConsole.Instance.Output(GetImageQueuesReport(cmd)));
  100. scene.AddCommand(
  101. "Comms", this, "clear image queues",
  102. "clear image queues <first-name> <last-name>",
  103. "Clear the image queues (textures downloaded via UDP) for a particular client.",
  104. (mod, cmd) => MainConsole.Instance.Output(HandleImageQueuesClear(cmd)));
  105. scene.AddCommand(
  106. "Comms", this, "show throttles",
  107. "show throttles [full]",
  108. "Show throttle settings for each client and for the server overall",
  109. "Without the 'full' option, only root agents are shown."
  110. + " With the 'full' option child agents are also shown.",
  111. (mod, cmd) => MainConsole.Instance.Output(GetThrottlesReport(cmd)));
  112. scene.AddCommand(
  113. "Comms", this, "emergency-monitoring",
  114. "emergency-monitoring",
  115. "Go on/off emergency monitoring mode",
  116. "Go on/off emergency monitoring mode",
  117. HandleEmergencyMonitoring);
  118. scene.AddCommand(
  119. "Comms", this, "show client stats",
  120. "show client stats [first_name last_name]",
  121. "Show client request stats",
  122. "Without the 'first_name last_name' option, all clients are shown."
  123. + " With the 'first_name last_name' option only a specific client is shown.",
  124. (mod, cmd) => MainConsole.Instance.Output(HandleClientStatsReport(cmd)));
  125. }
  126. public void RemoveRegion(Scene scene)
  127. {
  128. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  129. lock (m_scenes)
  130. m_scenes.Remove(scene.RegionInfo.RegionID);
  131. }
  132. public void RegionLoaded(Scene scene)
  133. {
  134. // m_log.DebugFormat("[LINDEN UDP INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  135. }
  136. protected string HandleImageQueuesClear(string[] cmd)
  137. {
  138. if (cmd.Length != 5)
  139. return "Usage: image queues clear <first-name> <last-name>";
  140. string firstName = cmd[3];
  141. string lastName = cmd[4];
  142. List<ScenePresence> foundAgents = new List<ScenePresence>();
  143. lock (m_scenes)
  144. {
  145. foreach (Scene scene in m_scenes.Values)
  146. {
  147. ScenePresence sp = scene.GetScenePresence(firstName, lastName);
  148. if (sp != null)
  149. foundAgents.Add(sp);
  150. }
  151. }
  152. if (foundAgents.Count == 0)
  153. return string.Format("No agents found for {0} {1}", firstName, lastName);
  154. StringBuilder report = new StringBuilder();
  155. foreach (ScenePresence agent in foundAgents)
  156. {
  157. LLClientView client = agent.ControllingClient as LLClientView;
  158. if (client == null)
  159. return "This command is only supported for LLClientView";
  160. int requestsDeleted = client.ImageManager.ClearImageQueue();
  161. report.AppendFormat(
  162. "In region {0} ({1} agent) cleared {2} requests\n",
  163. agent.Scene.RegionInfo.RegionName, agent.IsChildAgent ? "child" : "root", requestsDeleted);
  164. }
  165. return report.ToString();
  166. }
  167. protected void HandleEmergencyMonitoring(string module, string[] cmd)
  168. {
  169. bool mode = true;
  170. if (cmd.Length == 1 || (cmd.Length > 1 && cmd[1] == "on"))
  171. {
  172. mode = true;
  173. MainConsole.Instance.Output("Emergency Monitoring ON");
  174. }
  175. else
  176. {
  177. mode = false;
  178. MainConsole.Instance.Output("Emergency Monitoring OFF");
  179. }
  180. foreach (Scene s in m_scenes.Values)
  181. s.EmergencyMonitoring = mode;
  182. }
  183. protected string GetColumnEntry(string entry, int maxLength, int columnPadding)
  184. {
  185. return string.Format(
  186. "{0,-" + maxLength + "}{1,-" + columnPadding + "}",
  187. entry.Length > maxLength ? entry.Substring(0, maxLength) : entry,
  188. "");
  189. }
  190. /// <summary>
  191. /// Generate UDP Queue data report for each client
  192. /// </summary>
  193. /// <param name="showParams"></param>
  194. /// <returns></returns>
  195. protected string GetPQueuesReport(string[] showParams)
  196. {
  197. bool showChildren = false;
  198. string pname = "";
  199. if (showParams.Length > 2 && showParams[2] == "full")
  200. showChildren = true;
  201. else if (showParams.Length > 3)
  202. pname = showParams[2] + " " + showParams[3];
  203. StringBuilder report = new StringBuilder();
  204. int columnPadding = 2;
  205. int maxNameLength = 18;
  206. int maxRegionNameLength = 14;
  207. int maxTypeLength = 4;
  208. // int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding;
  209. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  210. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  211. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  212. report.AppendFormat(
  213. "{0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7} {10,7} {11,7}\n",
  214. "Pri 0",
  215. "Pri 1",
  216. "Pri 2",
  217. "Pri 3",
  218. "Pri 4",
  219. "Pri 5",
  220. "Pri 6",
  221. "Pri 7",
  222. "Pri 8",
  223. "Pri 9",
  224. "Pri 10",
  225. "Pri 11");
  226. lock (m_scenes)
  227. {
  228. foreach (Scene scene in m_scenes.Values)
  229. {
  230. scene.ForEachClient(
  231. delegate(IClientAPI client)
  232. {
  233. if (client is LLClientView)
  234. {
  235. bool isChild = client.SceneAgent.IsChildAgent;
  236. if (isChild && !showChildren)
  237. return;
  238. string name = client.Name;
  239. if (pname != "" && name != pname)
  240. return;
  241. string regionName = scene.RegionInfo.RegionName;
  242. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  243. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  244. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  245. report.AppendLine(((LLClientView)client).EntityUpdateQueue.ToString());
  246. }
  247. });
  248. }
  249. }
  250. return report.ToString();
  251. }
  252. /// <summary>
  253. /// Generate an image queue report
  254. /// </summary>
  255. /// <param name="showParams"></param>
  256. /// <returns></returns>
  257. private string GetImageQueuesReport(string[] showParams)
  258. {
  259. if (showParams.Length < 5 || showParams.Length > 6)
  260. return "Usage: image queues show <first-name> <last-name> [full]";
  261. string firstName = showParams[3];
  262. string lastName = showParams[4];
  263. bool showChildAgents = showParams.Length == 6;
  264. List<ScenePresence> foundAgents = new List<ScenePresence>();
  265. lock (m_scenes)
  266. {
  267. foreach (Scene scene in m_scenes.Values)
  268. {
  269. ScenePresence sp = scene.GetScenePresence(firstName, lastName);
  270. if (sp != null && (showChildAgents || !sp.IsChildAgent))
  271. foundAgents.Add(sp);
  272. }
  273. }
  274. if (foundAgents.Count == 0)
  275. return string.Format("No agents found for {0} {1}", firstName, lastName);
  276. StringBuilder report = new StringBuilder();
  277. foreach (ScenePresence agent in foundAgents)
  278. {
  279. LLClientView client = agent.ControllingClient as LLClientView;
  280. if (client == null)
  281. return "This command is only supported for LLClientView";
  282. J2KImage[] images = client.ImageManager.GetImages();
  283. report.AppendFormat(
  284. "In region {0} ({1} agent)\n",
  285. agent.Scene.RegionInfo.RegionName, agent.IsChildAgent ? "child" : "root");
  286. report.AppendFormat("Images in queue: {0}\n", images.Length);
  287. if (images.Length > 0)
  288. {
  289. report.AppendFormat(
  290. "{0,-36} {1,-8} {2,-10} {3,-9} {4,-9} {5,-7}\n",
  291. "Texture ID",
  292. "Last Seq",
  293. "Priority",
  294. "Start Pkt",
  295. "Has Asset",
  296. "Decoded");
  297. foreach (J2KImage image in images)
  298. report.AppendFormat(
  299. "{0,36} {1,8} {2,10} {3,10} {4,9} {5,7}\n",
  300. image.TextureID, image.LastSequence, image.Priority, image.StartPacket, image.HasAsset, image.IsDecoded);
  301. }
  302. }
  303. return report.ToString();
  304. }
  305. /// <summary>
  306. /// Generate UDP Queue data report for each client
  307. /// </summary>
  308. /// <param name="showParams"></param>
  309. /// <returns></returns>
  310. protected string GetQueuesReport(string[] showParams)
  311. {
  312. bool showChildren = false;
  313. string pname = "";
  314. if (showParams.Length > 2 && showParams[2] == "full")
  315. showChildren = true;
  316. else if (showParams.Length > 3)
  317. pname = showParams[2] + " " + showParams[3];
  318. StringBuilder report = new StringBuilder();
  319. int columnPadding = 2;
  320. int maxNameLength = 18;
  321. int maxRegionNameLength = 14;
  322. int maxTypeLength = 4;
  323. int totalInfoFieldsLength
  324. = maxNameLength + columnPadding
  325. + maxRegionNameLength + columnPadding
  326. + maxTypeLength + columnPadding;
  327. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  328. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  329. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  330. report.AppendFormat(
  331. "{0,7} {1,7} {2,7} {3,7} {4,9} {5,7} {6,7} {7,7} {8,7} {9,7} {10,8} {11,7} {12,7}\n",
  332. "Since",
  333. "Pkts",
  334. "Pkts",
  335. "Pkts",
  336. "Bytes",
  337. "Q Pkts",
  338. "Q Pkts",
  339. "Q Pkts",
  340. "Q Pkts",
  341. "Q Pkts",
  342. "Q Pkts",
  343. "Q Pkts",
  344. "Q Pkts");
  345. report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", "");
  346. report.AppendFormat(
  347. "{0,7} {1,7} {2,7} {3,7} {4,9} {5,7} {6,7} {7,7} {8,7} {9,7} {10,8} {11,7} {12,7}\n",
  348. "Last In",
  349. "In",
  350. "Out",
  351. "Resent",
  352. "Unacked",
  353. "Resend",
  354. "Land",
  355. "Wind",
  356. "Cloud",
  357. "Task",
  358. "Texture",
  359. "Asset",
  360. "State");
  361. lock (m_scenes)
  362. {
  363. foreach (Scene scene in m_scenes.Values)
  364. {
  365. scene.ForEachClient(
  366. delegate(IClientAPI client)
  367. {
  368. bool isChild = client.SceneAgent.IsChildAgent;
  369. if (isChild && !showChildren)
  370. return;
  371. string name = client.Name;
  372. if (pname != "" && name != pname)
  373. return;
  374. string regionName = scene.RegionInfo.RegionName;
  375. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  376. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  377. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  378. if (client is IStatsCollector)
  379. {
  380. IStatsCollector stats = (IStatsCollector)client;
  381. report.AppendLine(stats.Report());
  382. }
  383. });
  384. }
  385. }
  386. return report.ToString();
  387. }
  388. /// <summary>
  389. /// Show throttle data
  390. /// </summary>
  391. /// <param name="showParams"></param>
  392. /// <returns></returns>
  393. protected string GetThrottlesReport(string[] showParams)
  394. {
  395. bool showChildren = false;
  396. string pname = "";
  397. if (showParams.Length > 2 && showParams[2] == "full")
  398. showChildren = true;
  399. else if (showParams.Length > 3)
  400. pname = showParams[2] + " " + showParams[3];
  401. StringBuilder report = new StringBuilder();
  402. int columnPadding = 2;
  403. int maxNameLength = 18;
  404. int maxRegionNameLength = 14;
  405. int maxTypeLength = 4;
  406. int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding;
  407. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  408. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  409. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  410. report.AppendFormat(
  411. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}\n",
  412. "Total",
  413. "Resend",
  414. "Land",
  415. "Wind",
  416. "Cloud",
  417. "Task",
  418. "Texture",
  419. "Asset");
  420. report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", "");
  421. report.AppendFormat(
  422. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  423. "kb/s",
  424. "kb/s",
  425. "kb/s",
  426. "kb/s",
  427. "kb/s",
  428. "kb/s",
  429. "kb/s",
  430. "kb/s");
  431. report.AppendLine();
  432. bool firstClient = true;
  433. lock (m_scenes)
  434. {
  435. foreach (Scene scene in m_scenes.Values)
  436. {
  437. scene.ForEachClient(
  438. delegate(IClientAPI client)
  439. {
  440. if (client is LLClientView)
  441. {
  442. LLClientView llClient = client as LLClientView;
  443. if (firstClient)
  444. {
  445. report.AppendLine(GetServerThrottlesReport(llClient.UDPServer));
  446. firstClient = false;
  447. }
  448. bool isChild = client.SceneAgent.IsChildAgent;
  449. if (isChild && !showChildren)
  450. return;
  451. string name = client.Name;
  452. if (pname != "" && name != pname)
  453. return;
  454. string regionName = scene.RegionInfo.RegionName;
  455. LLUDPClient llUdpClient = llClient.UDPClient;
  456. ClientInfo ci = llUdpClient.GetClientInfo();
  457. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  458. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  459. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  460. report.AppendFormat(
  461. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  462. (ci.totalThrottle * 8) / 1000,
  463. (ci.resendThrottle * 8) / 1000,
  464. (ci.landThrottle * 8) / 1000,
  465. (ci.windThrottle * 8) / 1000,
  466. (ci.cloudThrottle * 8) / 1000,
  467. (ci.taskThrottle * 8) / 1000,
  468. (ci.textureThrottle * 8) / 1000,
  469. (ci.assetThrottle * 8) / 1000);
  470. report.AppendLine();
  471. }
  472. });
  473. }
  474. }
  475. return report.ToString();
  476. }
  477. protected string GetServerThrottlesReport(LLUDPServer udpServer)
  478. {
  479. StringBuilder report = new StringBuilder();
  480. int columnPadding = 2;
  481. int maxNameLength = 18;
  482. int maxRegionNameLength = 14;
  483. int maxTypeLength = 4;
  484. string name = "SERVER AGENT RATES";
  485. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  486. report.Append(GetColumnEntry("-", maxRegionNameLength, columnPadding));
  487. report.Append(GetColumnEntry("-", maxTypeLength, columnPadding));
  488. ThrottleRates throttleRates = udpServer.ThrottleRates;
  489. report.AppendFormat(
  490. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  491. (throttleRates.Total * 8) / 1000,
  492. (throttleRates.Resend * 8) / 1000,
  493. (throttleRates.Land * 8) / 1000,
  494. (throttleRates.Wind * 8) / 1000,
  495. (throttleRates.Cloud * 8) / 1000,
  496. (throttleRates.Task * 8) / 1000,
  497. (throttleRates.Texture * 8) / 1000,
  498. (throttleRates.Asset * 8) / 1000);
  499. return report.ToString();
  500. }
  501. /// <summary>
  502. /// Show client stats data
  503. /// </summary>
  504. /// <param name="showParams"></param>
  505. /// <returns></returns>
  506. protected string HandleClientStatsReport(string[] showParams)
  507. {
  508. // NOTE: This writes to m_log on purpose. We want to store this information
  509. // in case we need to analyze it later.
  510. //
  511. if (showParams.Length <= 4)
  512. {
  513. m_log.InfoFormat("[INFO]: {0,-12} {1,-20} {2,-6} {3,-11} {4,-11} {5,-16}", "Region", "Name", "Root", "Time", "Reqs/min", "AgentUpdates");
  514. foreach (Scene scene in m_scenes.Values)
  515. {
  516. scene.ForEachClient(
  517. delegate(IClientAPI client)
  518. {
  519. if (client is LLClientView)
  520. {
  521. LLClientView llClient = client as LLClientView;
  522. ClientInfo cinfo = llClient.UDPClient.GetClientInfo();
  523. int avg_reqs = cinfo.AsyncRequests.Values.Sum() + cinfo.GenericRequests.Values.Sum() + cinfo.SyncRequests.Values.Sum();
  524. avg_reqs = avg_reqs / ((DateTime.Now - cinfo.StartedTime).Minutes + 1);
  525. m_log.InfoFormat("[INFO]: {0,-12} {1,-20} {2,-6} {3,-11} {4,-11} {5,-16}",
  526. scene.RegionInfo.RegionName, llClient.Name,
  527. llClient.SceneAgent.IsChildAgent ? "N" : "Y",
  528. (DateTime.Now - cinfo.StartedTime).Minutes,
  529. avg_reqs,
  530. string.Format(
  531. "{0} ({1:0.00}%)",
  532. llClient.TotalAgentUpdates,
  533. (float)cinfo.SyncRequests["AgentUpdate"] / llClient.TotalAgentUpdates * 100));
  534. }
  535. });
  536. }
  537. return string.Empty;
  538. }
  539. string fname = "", lname = "";
  540. if (showParams.Length > 3)
  541. fname = showParams[3];
  542. if (showParams.Length > 4)
  543. lname = showParams[4];
  544. foreach (Scene scene in m_scenes.Values)
  545. {
  546. scene.ForEachClient(
  547. delegate(IClientAPI client)
  548. {
  549. if (client is LLClientView)
  550. {
  551. LLClientView llClient = client as LLClientView;
  552. if (llClient.Name == fname + " " + lname)
  553. {
  554. ClientInfo cinfo = llClient.GetClientInfo();
  555. AgentCircuitData aCircuit = scene.AuthenticateHandler.GetAgentCircuitData(llClient.CircuitCode);
  556. if (aCircuit == null) // create a dummy one
  557. aCircuit = new AgentCircuitData();
  558. if (!llClient.SceneAgent.IsChildAgent)
  559. m_log.InfoFormat("[INFO]: {0} # {1} # {2}", llClient.Name, aCircuit.Viewer, aCircuit.Id0);
  560. int avg_reqs = cinfo.AsyncRequests.Values.Sum() + cinfo.GenericRequests.Values.Sum() + cinfo.SyncRequests.Values.Sum();
  561. avg_reqs = avg_reqs / ((DateTime.Now - cinfo.StartedTime).Minutes + 1);
  562. m_log.InfoFormat("[INFO]:");
  563. m_log.InfoFormat("[INFO]: {0} # {1} # Time: {2}min # Avg Reqs/min: {3}", scene.RegionInfo.RegionName,
  564. (llClient.SceneAgent.IsChildAgent ? "Child" : "Root"), (DateTime.Now - cinfo.StartedTime).Minutes, avg_reqs);
  565. Dictionary<string, int> sortedDict = (from entry in cinfo.AsyncRequests orderby entry.Value descending select entry)
  566. .ToDictionary(pair => pair.Key, pair => pair.Value);
  567. PrintRequests("TOP ASYNC", sortedDict, cinfo.AsyncRequests.Values.Sum());
  568. sortedDict = (from entry in cinfo.SyncRequests orderby entry.Value descending select entry)
  569. .ToDictionary(pair => pair.Key, pair => pair.Value);
  570. PrintRequests("TOP SYNC", sortedDict, cinfo.SyncRequests.Values.Sum());
  571. sortedDict = (from entry in cinfo.GenericRequests orderby entry.Value descending select entry)
  572. .ToDictionary(pair => pair.Key, pair => pair.Value);
  573. PrintRequests("TOP GENERIC", sortedDict, cinfo.GenericRequests.Values.Sum());
  574. }
  575. }
  576. });
  577. }
  578. return string.Empty;
  579. }
  580. private void PrintRequests(string type, Dictionary<string, int> sortedDict, int sum)
  581. {
  582. m_log.InfoFormat("[INFO]:");
  583. m_log.InfoFormat("[INFO]: {0,25}", type);
  584. foreach (KeyValuePair<string, int> kvp in sortedDict.Take(12))
  585. m_log.InfoFormat("[INFO]: {0,25} {1,-6}", kvp.Key, kvp.Value);
  586. m_log.InfoFormat("[INFO]: {0,25}", "...");
  587. m_log.InfoFormat("[INFO]: {0,25} {1,-6}", "Total", sum);
  588. }
  589. }
  590. }