Exemple #1
0
        /// <summary>
        /// Get a thread pool report.
        /// </summary>
        /// <returns></returns>
        public static string GetThreadPoolReport()
        {
            string threadPoolUsed        = null;
            int    maxThreads            = 0;
            int    minThreads            = 0;
            int    allocatedThreads      = 0;
            int    inUseThreads          = 0;
            int    waitingCallbacks      = 0;
            int    completionPortThreads = 0;

            StringBuilder sb = new StringBuilder();

            if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
            {
                STPInfo stpi = Util.GetSmartThreadPoolInfo();

                // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool.
                if (stpi != null)
                {
                    threadPoolUsed   = "SmartThreadPool";
                    maxThreads       = stpi.MaxThreads;
                    minThreads       = stpi.MinThreads;
                    inUseThreads     = stpi.InUseThreads;
                    allocatedThreads = stpi.ActiveThreads;
                    waitingCallbacks = stpi.WaitingCallbacks;
                }
            }
            else if (
                Util.FireAndForgetMethod == FireAndForgetMethod.QueueUserWorkItem ||
                Util.FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem)
            {
                threadPoolUsed = "BuiltInThreadPool";
                ThreadPool.GetMaxThreads(out maxThreads, out completionPortThreads);
                ThreadPool.GetMinThreads(out minThreads, out completionPortThreads);
                int availableThreads;
                ThreadPool.GetAvailableThreads(out availableThreads, out completionPortThreads);
                inUseThreads     = maxThreads - availableThreads;
                allocatedThreads = -1;
                waitingCallbacks = -1;
            }

            if (threadPoolUsed != null)
            {
                sb.AppendFormat("Thread pool used           : {0}\n", threadPoolUsed);
                sb.AppendFormat("Max threads                : {0}\n", maxThreads);
                sb.AppendFormat("Min threads                : {0}\n", minThreads);
                sb.AppendFormat("Allocated threads          : {0}\n", allocatedThreads < 0 ? "not applicable" : allocatedThreads.ToString());
                sb.AppendFormat("In use threads             : {0}\n", inUseThreads);
                sb.AppendFormat("Work items waiting         : {0}\n", waitingCallbacks < 0 ? "not available" : waitingCallbacks.ToString());
            }
            else
            {
                sb.AppendFormat("Thread pool not used\n");
            }

            return(sb.ToString());
        }
Exemple #2
0
        /// <summary>
        /// Get a thread pool report.
        /// </summary>
        /// <returns></returns>
        public static string GetThreadPoolReport()
        {
            StringBuilder sb = new StringBuilder();

            // framework pool is alwasy active
            int maxWorkers;
            int minWorkers;
            int curWorkers;
            int maxComp;
            int minComp;
            int curComp;

            try
            {
                ThreadPool.GetMaxThreads(out maxWorkers, out maxComp);
                ThreadPool.GetMinThreads(out minWorkers, out minComp);
                ThreadPool.GetAvailableThreads(out curWorkers, out curComp);
                curWorkers = maxWorkers - curWorkers;
                curComp    = maxComp - curComp;

                sb.Append("\nFramework main threadpool \n");
                sb.AppendFormat("workers:    {0} ({1} / {2})\n", curWorkers, maxWorkers, minWorkers);
                sb.AppendFormat("Completion: {0} ({1} / {2})\n", curComp, maxComp, minComp);
            }
            catch { }

            if (
                Util.FireAndForgetMethod == FireAndForgetMethod.QueueUserWorkItem ||
                Util.FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem)
            {
                sb.AppendFormat("\nThread pool used: Framework main threadpool\n");
                return(sb.ToString());
            }

            string threadPoolUsed   = null;
            int    maxThreads       = 0;
            int    minThreads       = 0;
            int    allocatedThreads = 0;
            int    inUseThreads     = 0;
            int    waitingCallbacks = 0;

            if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
            {
                STPInfo stpi = Util.GetSmartThreadPoolInfo();

                // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool.
                if (stpi != null)
                {
                    threadPoolUsed   = "SmartThreadPool";
                    maxThreads       = stpi.MaxThreads;
                    minThreads       = stpi.MinThreads;
                    inUseThreads     = stpi.InUseThreads;
                    allocatedThreads = stpi.ActiveThreads;
                    waitingCallbacks = stpi.WaitingCallbacks;
                }
            }

            if (threadPoolUsed != null)
            {
                sb.Append("\nThreadpool (excluding script engine pools)\n");
                sb.AppendFormat("Thread pool used           : {0}\n", threadPoolUsed);
                sb.AppendFormat("Max threads                : {0}\n", maxThreads);
                sb.AppendFormat("Min threads                : {0}\n", minThreads);
                sb.AppendFormat("Allocated threads          : {0}\n", allocatedThreads < 0 ? "not applicable" : allocatedThreads.ToString());
                sb.AppendFormat("In use threads             : {0}\n", inUseThreads);
                sb.AppendFormat("Work items waiting         : {0}\n", waitingCallbacks < 0 ? "not available" : waitingCallbacks.ToString());
            }
            else
            {
                sb.AppendFormat("Thread pool not used\n");
            }

            return(sb.ToString());
        }