Exemple #1
0
        public override bool Generate(CommandExecutionContext context)
        {
            var managedThreadNames = GetManagedThreadNames(context.Heap);

            var target = context.NativeDbgEngTarget;
            IDebugSystemObjects3 sysObjects = (IDebugSystemObjects3)target.DebuggerInterface;

            sysObjects.GetCurrentProcessUpTime(out _processUpTimeInSeconds);

            var debugAdvanced = (IDebugAdvanced2)target.DebuggerInterface;
            var stackTraces   = new UnifiedStackTraces(target.DebuggerInterface, context);

            foreach (var thread in stackTraces.Threads)
            {
                var stackTrace = stackTraces.GetStackTrace(thread.Index);
                var threadInfo = new ThreadInfo
                {
                    EngineThreadId     = thread.EngineThreadId,
                    OSThreadId         = thread.OSThreadId,
                    ManagedThreadId    = thread.ManagedThread?.ManagedThreadId ?? -1,
                    SpecialDescription = thread.ManagedThread?.SpecialDescription()
                };

                string threadName;
                if (managedThreadNames.TryGetValue(threadInfo.ManagedThreadId, out threadName))
                {
                    threadInfo.ThreadName = threadName;
                }

                threadInfo.Fill(debugAdvanced);
                foreach (var frame in stackTrace)
                {
                    threadInfo.StackFrames.Add(new StackFrame
                    {
                        Module           = frame.Module,
                        Method           = frame.Method,
                        SourceFileName   = frame.SourceFileName,
                        SourceLineNumber = frame.SourceLineNumber
                    });
                }
                Threads.Add(threadInfo);
            }

            RecommendFinalizerThreadHighCPU(context);
            RecommendHighNumberOfThreads();

            return(true);
        }