From d3a550bc852dc8be4415f5f11f1d0156b1879878 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 3 Nov 2014 23:49:11 +0000 Subject: [PATCH] Add "show threadpool calls" command to show count of all labelled smartthreadpool calls --- OpenSim/Framework/Servers/ServerBase.cs | 21 +++++++++++++++++++++ OpenSim/Framework/Util.cs | 16 +++++++++++++++- prebuild.xml | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index fd5658787c..379e224855 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs @@ -29,6 +29,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; @@ -291,6 +292,12 @@ namespace OpenSim.Framework.Servers + " 3 = full stack trace, including common threads\n", HandleDebugThreadpoolLevel); + m_console.Commands.AddCommand( + "Debug", false, "show threadpool calls", + "show threadpool calls", + "Show the number of labelled threadpool calls.", + HandleShowThreadpoolCalls); + m_console.Commands.AddCommand( "Debug", false, "force gc", "force gc", @@ -354,6 +361,20 @@ namespace OpenSim.Framework.Servers Notice("serialosdreq is now {0}", setSerializeOsdRequests); } + private void HandleShowThreadpoolCalls(string module, string[] args) + { + List> calls = Util.GetFireAndForgetCallsMade().ToList(); + calls.Sort((kvp1, kvp2) => kvp2.Value.CompareTo(kvp1.Value)); + + ConsoleDisplayList cdl = new ConsoleDisplayList(); + foreach (KeyValuePair kvp in calls) + { + cdl.AddRow(kvp.Key, kvp.Value); + } + + MainConsole.Instance.Output(cdl.ToString()); + } + private void HandleDebugThreadpoolStatus(string module, string[] args) { int workerThreads, iocpThreads; diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index fefa05039a..53bbb066e5 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -2086,14 +2086,28 @@ namespace OpenSim.Framework } } + public static Dictionary GetFireAndForgetCallsMade() + { + return new Dictionary(m_fireAndForgetCallsMade); + } + + private static Dictionary m_fireAndForgetCallsMade = new Dictionary(); public static void FireAndForget(System.Threading.WaitCallback callback, object obj) { FireAndForget(callback, obj, null); } - + public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context) { + if (context != null) + { + if (!m_fireAndForgetCallsMade.ContainsKey(context)) + m_fireAndForgetCallsMade[context] = 1; + else + m_fireAndForgetCallsMade[context]++; + } + WaitCallback realCallback; bool loggingEnabled = LogThreadPool > 0; diff --git a/prebuild.xml b/prebuild.xml index 413736b49c..896f4dee93 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -390,6 +390,7 @@ ../../../bin/ +