Exemplo n.º 1
0
        public IReadOnlyCollection <ObjectTypeStatistics> GetInstanceTypeStatistics([FromQuery(Name = "traversing-heap-mode")] TraversingHeapModes traversingMode)
        {
            var analyzer = new ObjectTypeStatisticsAnalyzer(_runtimeContext);

            analyzer.TraversingHeapMode = traversingMode;
            return(analyzer.GetObjectTypeStatistics());
        }
Exemplo n.º 2
0
    private async Task ProcessCommand2(ILogger <Program> logger)
    {
        string filePath       = @"C:\Users\Ne4to\projects\GitHub\Ne4to\Heartbeat\tests\dumps\AsyncStask.dmp";
        string?dacPath        = null;
        bool   ignoreMismatch = false;

        var     dataTarget = DataTarget.LoadDump(filePath);
        ClrInfo clrInfo    = dataTarget.ClrVersions[0];
        var     clrRuntime = dacPath == null
            ? clrInfo.CreateRuntime()
            : clrInfo.CreateRuntime(dacPath, ignoreMismatch);

        var runtimeContext = new RuntimeContext(clrRuntime, filePath);
        var traversingMode = _commandLineOptions.TraversingHeapMode;

        ExecuteWhenTrue(PrintHttpClients, _commandLineOptions.HttpClient);
        ExecuteWhenTrue(PrintStringDuplicates, _commandLineOptions.StringDuplicate);
        ExecuteWhenTrue(PrintObjectTypeStatistics, _commandLineOptions.ObjectTypeStatistics);
        ExecuteWhenTrue(PrintTimerQueueTimers, _commandLineOptions.TimerQueueTimer);
        ExecuteWhenTrue(PrintLongStrings, _commandLineOptions.LongString);

        void PrintHttpClients()
        {
            var analyzer = new HttpClientAnalyzer(runtimeContext);

            analyzer.TraversingHeapMode = traversingMode;

            var httpClients = analyzer.GetClientsInfo();

            foreach (var httpclient in httpClients)
            {
                logger.LogInformation($"{httpclient.Address} timeout = {httpclient.Timeout.TotalSeconds:F2} seconds");
            }
        }

        void PrintStringDuplicates()
        {
            var analyzer = new StringDuplicateAnalyzer(runtimeContext);

            analyzer.TraversingHeapMode = traversingMode;

            var duplicates = analyzer.GetStringDuplicates(10, 100);

            foreach (var duplicate in duplicates)
            {
                logger.LogInformation($"{duplicate.Count} instances of: {duplicate.String}");
            }
        }

        void PrintObjectTypeStatistics()
        {
            var analyzer = new ObjectTypeStatisticsAnalyzer(runtimeContext);

            analyzer.TraversingHeapMode = traversingMode;

            var statistics = analyzer.GetObjectTypeStatistics();

            foreach (var stat in statistics)
            {
                logger.LogInformation($"{stat.TypeName}: {stat.TotalSize} ({stat.InstanceCount} instances)");
            }
        }

        void PrintTimerQueueTimers()
        {
            var analyzer = new TimerQueueTimerAnalyzer(runtimeContext);

            analyzer.TraversingHeapMode = traversingMode;

            var timers = analyzer.GetTimers(traversingMode);

            foreach (var timer in timers)
            {
                logger.LogInformation($"{timer.Address} m_dueTime = {timer.DueTime}, m_period = {timer.Period}, m_canceled = {timer.Cancelled}");

                if (timer.CancellationState != null)
                {
                    logger.LogInformation($"CanBeCanceled: {timer.CancellationState.CanBeCanceled}");
                    logger.LogInformation($"IsCancellationRequested: {timer.CancellationState.IsCancellationRequested}");
                    logger.LogInformation($"IsCancellationCompleted: {timer.CancellationState.IsCancellationCompleted}");
                }
            }
        }

        void PrintLongStrings()
        {
            var analyzer = new LongStringAnalyzer(runtimeContext);

            analyzer.TraversingHeapMode = traversingMode;

            var strings = analyzer.GetStrings(20, null);

            foreach (var s in strings)
            {
                logger.LogInformation($"{s.Address} Length = {s.Length} chars, Value = {s.Value}");
            }
        }
    }