1
0

LindenUDPInfoModule.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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: show image queues <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}\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. report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", "");
  345. report.AppendFormat(
  346. "{0,7} {1,7} {2,7} {3,7} {4,9} {5,7} {6,7} {7,7} {8,7} {9,7} {10,8} {11,7}\n",
  347. "Last In",
  348. "In",
  349. "Out",
  350. "Resent",
  351. "Unacked",
  352. "Resend",
  353. "Land",
  354. "Wind",
  355. "Cloud",
  356. "Task",
  357. "Texture",
  358. "Asset");
  359. lock (m_scenes)
  360. {
  361. foreach (Scene scene in m_scenes.Values)
  362. {
  363. scene.ForEachClient(
  364. delegate(IClientAPI client)
  365. {
  366. if (client is IStatsCollector)
  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. IStatsCollector stats = (IStatsCollector)client;
  379. report.AppendLine(stats.Report());
  380. }
  381. });
  382. }
  383. }
  384. return report.ToString();
  385. }
  386. /// <summary>
  387. /// Show throttle data
  388. /// </summary>
  389. /// <param name="showParams"></param>
  390. /// <returns></returns>
  391. protected string GetThrottlesReport(string[] showParams)
  392. {
  393. bool showChildren = false;
  394. string pname = "";
  395. if (showParams.Length > 2 && showParams[2] == "full")
  396. showChildren = true;
  397. else if (showParams.Length > 3)
  398. pname = showParams[2] + " " + showParams[3];
  399. StringBuilder report = new StringBuilder();
  400. int columnPadding = 2;
  401. int maxNameLength = 18;
  402. int maxRegionNameLength = 14;
  403. int maxTypeLength = 4;
  404. int totalInfoFieldsLength = maxNameLength + columnPadding + maxRegionNameLength + columnPadding + maxTypeLength + columnPadding;
  405. report.Append(GetColumnEntry("User", maxNameLength, columnPadding));
  406. report.Append(GetColumnEntry("Region", maxRegionNameLength, columnPadding));
  407. report.Append(GetColumnEntry("Type", maxTypeLength, columnPadding));
  408. report.AppendFormat(
  409. "{0,8} {1,8} {2,7} {3,8} {4,7} {5,7} {6,7} {7,7} {8,9} {9,7}\n",
  410. "Max",
  411. "Target",
  412. "Actual",
  413. "Resend",
  414. "Land",
  415. "Wind",
  416. "Cloud",
  417. "Task",
  418. "Texture",
  419. "Asset");
  420. report.AppendFormat("{0,-" + totalInfoFieldsLength + "}", "");
  421. report.AppendFormat(
  422. "{0,8} {1,8} {2,7} {3,8} {4,7} {5,7} {6,7} {7,7} {8,9} {9,7}\n",
  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. "kb/s",
  432. "kb/s");
  433. report.AppendLine();
  434. lock (m_scenes)
  435. {
  436. foreach (Scene scene in m_scenes.Values)
  437. {
  438. scene.ForEachClient(
  439. delegate(IClientAPI client)
  440. {
  441. if (client is LLClientView)
  442. {
  443. LLClientView llClient = client as LLClientView;
  444. bool isChild = client.SceneAgent.IsChildAgent;
  445. if (isChild && !showChildren)
  446. return;
  447. string name = client.Name;
  448. if (pname != "" && name != pname)
  449. return;
  450. string regionName = scene.RegionInfo.RegionName;
  451. LLUDPClient llUdpClient = llClient.UDPClient;
  452. ClientInfo ci = llUdpClient.GetClientInfo();
  453. report.Append(GetColumnEntry(name, maxNameLength, columnPadding));
  454. report.Append(GetColumnEntry(regionName, maxRegionNameLength, columnPadding));
  455. report.Append(GetColumnEntry(isChild ? "Cd" : "Rt", maxTypeLength, columnPadding));
  456. report.AppendFormat(
  457. "{0,8} {1,8} {2,7} {3,8} {4,7} {5,7} {6,7} {7,7} {8,9} {9,7}\n",
  458. ci.maxThrottle > 0 ? ((ci.maxThrottle * 8) / 1000).ToString() : "-",
  459. llUdpClient.FlowThrottle.AdaptiveEnabled
  460. ? ((ci.targetThrottle * 8) / 1000).ToString()
  461. : (llUdpClient.FlowThrottle.TotalDripRequest * 8 / 1000).ToString(),
  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. }
  471. });
  472. }
  473. }
  474. return report.ToString();
  475. }
  476. /// <summary>
  477. /// Show client stats data
  478. /// </summary>
  479. /// <param name="showParams"></param>
  480. /// <returns></returns>
  481. protected string HandleClientStatsReport(string[] showParams)
  482. {
  483. // NOTE: This writes to m_log on purpose. We want to store this information
  484. // in case we need to analyze it later.
  485. //
  486. if (showParams.Length <= 4)
  487. {
  488. m_log.InfoFormat("[INFO]: {0,-12} {1,-20} {2,-6} {3,-11} {4,-11} {5,-16}", "Region", "Name", "Root", "Time", "Reqs/min", "AgentUpdates");
  489. foreach (Scene scene in m_scenes.Values)
  490. {
  491. scene.ForEachClient(
  492. delegate(IClientAPI client)
  493. {
  494. if (client is LLClientView)
  495. {
  496. LLClientView llClient = client as LLClientView;
  497. ClientInfo cinfo = llClient.UDPClient.GetClientInfo();
  498. int avg_reqs = cinfo.AsyncRequests.Values.Sum() + cinfo.GenericRequests.Values.Sum() + cinfo.SyncRequests.Values.Sum();
  499. avg_reqs = avg_reqs / ((DateTime.Now - cinfo.StartedTime).Minutes + 1);
  500. string childAgentStatus;
  501. if (llClient.SceneAgent != null)
  502. childAgentStatus = llClient.SceneAgent.IsChildAgent ? "N" : "Y";
  503. else
  504. childAgentStatus = "Off!";
  505. m_log.InfoFormat("[INFO]: {0,-12} {1,-20} {2,-6} {3,-11} {4,-11} {5,-16}",
  506. scene.RegionInfo.RegionName, llClient.Name,
  507. childAgentStatus,
  508. (DateTime.Now - cinfo.StartedTime).Minutes,
  509. avg_reqs,
  510. string.Format(
  511. "{0} ({1:0.00}%)",
  512. llClient.TotalAgentUpdates,
  513. cinfo.SyncRequests.ContainsKey("AgentUpdate")
  514. ? (float)cinfo.SyncRequests["AgentUpdate"] / llClient.TotalAgentUpdates * 100
  515. : 0));
  516. }
  517. });
  518. }
  519. return string.Empty;
  520. }
  521. string fname = "", lname = "";
  522. if (showParams.Length > 3)
  523. fname = showParams[3];
  524. if (showParams.Length > 4)
  525. lname = showParams[4];
  526. foreach (Scene scene in m_scenes.Values)
  527. {
  528. scene.ForEachClient(
  529. delegate(IClientAPI client)
  530. {
  531. if (client is LLClientView)
  532. {
  533. LLClientView llClient = client as LLClientView;
  534. if (llClient.Name == fname + " " + lname)
  535. {
  536. ClientInfo cinfo = llClient.GetClientInfo();
  537. AgentCircuitData aCircuit = scene.AuthenticateHandler.GetAgentCircuitData(llClient.CircuitCode);
  538. if (aCircuit == null) // create a dummy one
  539. aCircuit = new AgentCircuitData();
  540. if (!llClient.SceneAgent.IsChildAgent)
  541. m_log.InfoFormat("[INFO]: {0} # {1} # {2}", llClient.Name, Util.GetViewerName(aCircuit), aCircuit.Id0);
  542. int avg_reqs = cinfo.AsyncRequests.Values.Sum() + cinfo.GenericRequests.Values.Sum() + cinfo.SyncRequests.Values.Sum();
  543. avg_reqs = avg_reqs / ((DateTime.Now - cinfo.StartedTime).Minutes + 1);
  544. m_log.InfoFormat("[INFO]:");
  545. m_log.InfoFormat("[INFO]: {0} # {1} # Time: {2}min # Avg Reqs/min: {3}", scene.RegionInfo.RegionName,
  546. (llClient.SceneAgent.IsChildAgent ? "Child" : "Root"), (DateTime.Now - cinfo.StartedTime).Minutes, avg_reqs);
  547. Dictionary<string, int> sortedDict = (from entry in cinfo.AsyncRequests orderby entry.Value descending select entry)
  548. .ToDictionary(pair => pair.Key, pair => pair.Value);
  549. PrintRequests("TOP ASYNC", sortedDict, cinfo.AsyncRequests.Values.Sum());
  550. sortedDict = (from entry in cinfo.SyncRequests orderby entry.Value descending select entry)
  551. .ToDictionary(pair => pair.Key, pair => pair.Value);
  552. PrintRequests("TOP SYNC", sortedDict, cinfo.SyncRequests.Values.Sum());
  553. sortedDict = (from entry in cinfo.GenericRequests orderby entry.Value descending select entry)
  554. .ToDictionary(pair => pair.Key, pair => pair.Value);
  555. PrintRequests("TOP GENERIC", sortedDict, cinfo.GenericRequests.Values.Sum());
  556. }
  557. }
  558. });
  559. }
  560. return string.Empty;
  561. }
  562. private void PrintRequests(string type, Dictionary<string, int> sortedDict, int sum)
  563. {
  564. m_log.InfoFormat("[INFO]:");
  565. m_log.InfoFormat("[INFO]: {0,25}", type);
  566. foreach (KeyValuePair<string, int> kvp in sortedDict.Take(12))
  567. m_log.InfoFormat("[INFO]: {0,25} {1,-6}", kvp.Key, kvp.Value);
  568. m_log.InfoFormat("[INFO]: {0,25}", "...");
  569. m_log.InfoFormat("[INFO]: {0,25} {1,-6}", "Total", sum);
  570. }
  571. }
  572. }