GSF.Diagnostics.TimerTrace.GetTrace C# (CSharp) Method

GetTrace() public static method

Gets all of the callbacks for all timers.
public static GetTrace ( StringBuilder sb ) : void
sb StringBuilder
return void
        public static void GetTrace(StringBuilder sb)
        {
            if (!WorksInThisRuntime)
            {
                sb.AppendLine("Not Supported");
                return;
            }

            try
            {

                object timerQueue = s_timerQueueInstanceMethod.Invoke(null, null);
                lock (timerQueue)
                {
                    object timerQueueTimer = s_timerQueueTimersField.GetValue(timerQueue);

                    while (timerQueueTimer != null)
                    {
                        ProcessTimerQueueTimer(sb, timerQueueTimer);
                        timerQueueTimer = s_timerQueueTimerNextField.GetValue(timerQueueTimer);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Publish(MessageLevel.Error, MessageFlags.BugReport, "Error in GetTrace", null, null, ex);

                WorksInThisRuntime = false;
            }
        }

Usage Example

Ejemplo n.º 1
0
        private static void MonitorThreads()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("--------------------------------------------------------");
            sb.AppendLine("Thread Pool Queue");
            sb.AppendLine("--------------------------------------------------------");

            ThreadPoolTrace.GetTrace(sb);

            sb.AppendLine("--------------------------------------------------------");
            sb.AppendLine("Timers");
            sb.AppendLine("--------------------------------------------------------");

            TimerTrace.GetTrace(sb);

            //Since current builds of openPDC appears to be doing better about not blocking all threads on the threadpool
            //this diagnostics functionality has been disabled but the code has been left in place if it's needed in the future.

            //            if (OptimizationOptions.EnableThreadStackDumping)
            //            {
            //#if !MONO
            //                using (var dataTarget = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, 5000, AttachFlag.Passive))
            //                {
            //                    foreach (var clr in dataTarget.ClrVersions)
            //                    {
            //                        var runtime = clr.CreateRuntime();

            //                        sb.AppendLine("--------------------------------------------------------");
            //                        sb.AppendLine("Thread Stacks");
            //                        sb.AppendLine("--------------------------------------------------------");
            //                        foreach (var t in runtime.Threads)
            //                        {
            //                            bool hasWrittenData = false;

            //                            foreach (var item in t.StackTrace)
            //                            {
            //                                if (item.Method != null)
            //                                {
            //                                    if (!hasWrittenData)
            //                                        hasWrittenData = true;
            //                                    sb.AppendLine(item.ToString());
            //                                }
            //                            }
            //                            if (hasWrittenData)
            //                            {
            //                                sb.AppendLine("--------------------------------------------------------");
            //                            }
            //                        }
            //                    }
            //                }
            //#endif
            //            }
            Log.Publish(MessageLevel.Warning, "ThreadPool Stack Trace", "Dumped threadpool stack trace", sb.ToString());
        }