Exemplo n.º 1
0
        public static void LogAnalyzerCrashCountSummary(int correlationId, LogAggregator logAggregator)
        {
            if (logAggregator == null)
            {
                return;
            }

            foreach (var analyzerCrash in logAggregator)
            {
                Logger.Log(FunctionId.DiagnosticAnalyzerDriver_AnalyzerCrash, KeyValueLogMessage.Create(m =>
                {
                    var key = (ValueTuple<bool, Type, Type>)analyzerCrash.Key;
                    bool telemetry = key.Item1;
                    m[Id] = correlationId;

                    // we log analyzer name and exception as it is, if telemetry is allowed
                    if (telemetry)
                    {
                        m[AnalyzerName] = key.Item2.FullName;
                        m[AnalyzerCrashCount] = analyzerCrash.Value.GetCount();
                        m[AnalyzerException] = key.Item3.FullName;
                    }
                    else
                    {
                        string analyzerName = key.Item2.FullName;
                        string exceptionName = key.Item3.FullName;

                        m[AnalyzerHashCode] = ComputeSha256Hash(analyzerName);
                        m[AnalyzerCrashCount] = analyzerCrash.Value.GetCount();
                        m[AnalyzerExceptionHashCode] = ComputeSha256Hash(exceptionName);
                    }
                }));
            }
        }
Exemplo n.º 2
0
        public static void LogAnalyzerCrashCount(DiagnosticAnalyzer analyzer, Exception ex, LogAggregator logAggregator, ProjectId projectId)
        {
            if (logAggregator == null || analyzer == null || ex == null || ex is OperationCanceledException)
            {
                return;
            }

            // TODO: once we create description manager, pass that into here.
            bool telemetry = DiagnosticAnalyzerLogger.AllowsTelemetry(null, analyzer, projectId);
            var tuple = ValueTuple.Create(telemetry, analyzer.GetType(), ex.GetType());
            logAggregator.IncreaseCount(tuple);
        }
Exemplo n.º 3
0
            public WorkCoordinator(
                 IAsynchronousOperationListener listener,
                 IEnumerable<Lazy<IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>> analyzerProviders,
                 Registration registration)
            {
                _logAggregator = new LogAggregator();

                _registration = registration;

                _listener = listener;
                _optionService = _registration.GetService<IOptionService>();

                // event and worker queues
                _shutdownNotificationSource = new CancellationTokenSource();
                _shutdownToken = _shutdownNotificationSource.Token;

                _eventProcessingQueue = new SimpleTaskQueue(TaskScheduler.Default);

                var activeFileBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.ActiveFileWorkerBackOffTimeSpanInMS);
                var allFilesWorkerBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.AllFilesWorkerBackOffTimeSpanInMS);
                var entireProjectWorkerBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.EntireProjectWorkerBackOffTimeSpanInMS);

                _documentAndProjectWorkerProcessor = new IncrementalAnalyzerProcessor(
                    listener, analyzerProviders, _registration,
                    activeFileBackOffTimeSpanInMS, allFilesWorkerBackOffTimeSpanInMS, entireProjectWorkerBackOffTimeSpanInMS, _shutdownToken);

                var semanticBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.SemanticChangeBackOffTimeSpanInMS);
                var projectBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.ProjectPropagationBackOffTimeSpanInMS);

                _semanticChangeProcessor = new SemanticChangeProcessor(listener, _registration, _documentAndProjectWorkerProcessor, semanticBackOffTimeSpanInMS, projectBackOffTimeSpanInMS, _shutdownToken);

                // if option is on
                if (_optionService.GetOption(InternalSolutionCrawlerOptions.SolutionCrawler))
                {
                    _registration.Workspace.WorkspaceChanged += OnWorkspaceChanged;
                    _registration.Workspace.DocumentOpened += OnDocumentOpened;
                    _registration.Workspace.DocumentClosed += OnDocumentClosed;
                }

                // subscribe to option changed event after all required fields are set
                // otherwise, we can get null exception when running OnOptionChanged handler
                _optionService.OptionChanged += OnOptionChanged;
            }
Exemplo n.º 4
0
            public WorkCoordinator(
                 IAsynchronousOperationListener listener,
                 IEnumerable<Lazy<IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>> analyzerProviders,
                 int correlationId, Workspace workspace)
            {
                _logAggregator = new LogAggregator();

                _listener = listener;
                _optionService = workspace.Services.GetService<IOptionService>();
                _optionService.OptionChanged += OnOptionChanged;

                // set up workspace 
                _correlationId = correlationId;
                _workspace = workspace;

                // event and worker queues
                _shutdownNotificationSource = new CancellationTokenSource();
                _shutdownToken = _shutdownNotificationSource.Token;

                _eventProcessingQueue = new SimpleTaskQueue(TaskScheduler.Default);

                var activeFileBackOffTimeSpanInMS = _optionService.GetOption(SolutionCrawlerOptions.ActiveFileWorkerBackOffTimeSpanInMS);
                var allFilesWorkerBackOffTimeSpanInMS = _optionService.GetOption(SolutionCrawlerOptions.AllFilesWorkerBackOffTimeSpanInMS);
                var entireProjectWorkerBackOffTimeSpanInMS = _optionService.GetOption(SolutionCrawlerOptions.EntireProjectWorkerBackOffTimeSpanInMS);
                _documentAndProjectWorkerProcessor = new IncrementalAnalyzerProcessor(
                    listener, correlationId, workspace, analyzerProviders, activeFileBackOffTimeSpanInMS, allFilesWorkerBackOffTimeSpanInMS, entireProjectWorkerBackOffTimeSpanInMS, _shutdownToken);

                var semanticBackOffTimeSpanInMS = _optionService.GetOption(SolutionCrawlerOptions.SemanticChangeBackOffTimeSpanInMS);
                var projectBackOffTimeSpanInMS = _optionService.GetOption(SolutionCrawlerOptions.ProjectPropagationBackOffTimeSpanInMS);

                _semanticChangeProcessor = new SemanticChangeProcessor(listener, correlationId, workspace, _documentAndProjectWorkerProcessor, semanticBackOffTimeSpanInMS, projectBackOffTimeSpanInMS, _shutdownToken);

                // if option is on
                if (_optionService.GetOption(SolutionCrawlerOptions.SolutionCrawler))
                {
                    _workspace.WorkspaceChanged += OnWorkspaceChanged;
                    _workspace.DocumentOpened += OnDocumentOpened;
                    _workspace.DocumentClosed += OnDocumentClosed;
                }
            }
Exemplo n.º 5
0
        public static void LogWorkItemEnqueue(
            LogAggregator logAggregator, string language, DocumentId documentId, InvocationReasons reasons, bool lowPriority, SyntaxPath activeMember, bool added)
        {
            logAggregator.IncreaseCount(language);
            logAggregator.IncreaseCount(added ? NewWorkItem : UpdateWorkItem);

            if (documentId != null)
            {
                logAggregator.IncreaseCount(activeMember == null ? TopLevel : MemberLevel);

                if (lowPriority)
                {
                    logAggregator.IncreaseCount(LowerPriority);
                    logAggregator.IncreaseCount(ValueTuple.Create(LowerPriority, documentId.Id));
                }
            }

            foreach (var reason in reasons)
            {
                logAggregator.IncreaseCount(reason);
            }
        }
Exemplo n.º 6
0
 public static void LogActiveFileEnqueue(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(ActiveFileEnqueue);
 }
Exemplo n.º 7
0
        public static void LogWorkCoordinatorShutdown(int correlationId, LogAggregator logAggregator)
        {
            Logger.Log(FunctionId.WorkCoordinator_Shutdown, KeyValueLogMessage.Create(m =>
            {
                m[Id] = correlationId;

                foreach (var kv in logAggregator)
                {
                    var change = ((WorkspaceChangeKind)kv.Key).ToString();
                    m[change] = kv.Value.GetCount();
                }
            }));
        }
Exemplo n.º 8
0
        public static void LogProcessDocument(LogAggregator logAggregator, Guid documentId, bool processed)
        {
            if (processed)
            {
                logAggregator.IncreaseCount(ProcessDocument);
            }
            else
            {
                logAggregator.IncreaseCount(ProcessDocumentCancellation);
            }

            logAggregator.IncreaseCount(ValueTuple.Create(ProcessDocument, documentId));
        }
Exemplo n.º 9
0
 public static void LogProcessDocumentNotExist(LogAggregator logAggregator)
 => logAggregator.IncreaseCount(DocumentNotExist);
Exemplo n.º 10
0
 public static void LogProcessOpenDocument(LogAggregator logAggregator, Guid documentId)
 {
     logAggregator.IncreaseCount(OpenDocument);
     logAggregator.IncreaseCount(ValueTuple.Create(OpenDocument, documentId));
 }
Exemplo n.º 11
0
        public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, LogAggregator logAggregator, ImmutableArray <IIncrementalAnalyzer> analyzers)
        {
            Logger.Log(FunctionId.IncrementalAnalyzerProcessor_Shutdown, KeyValueLogMessage.Create(m =>
            {
                var solutionHash = GetSolutionHash(solution);

                m[Id]           = correlationId;
                m[SolutionHash] = solutionHash.ToString();

                var statMap = new Dictionary <string, List <int> >();
                foreach (var(key, counter) in logAggregator)
                {
                    if (key is string stringKey)
                    {
                        m[stringKey] = counter.GetCount();
                        continue;
                    }

                    if (key is ValueTuple <string, Guid> propertyNameAndId)
                    {
                        var list = statMap.GetOrAdd(propertyNameAndId.Item1, _ => new List <int>());
                        list.Add(counter.GetCount());
                        continue;
                    }

                    throw ExceptionUtilities.Unreachable;
                }

                foreach (var(propertyName, propertyValues) in statMap)
                {
                    var result = LogAggregator.GetStatistics(propertyValues);

                    m[CreateProperty(propertyName, Max)]    = result.Maximum;
                    m[CreateProperty(propertyName, Min)]    = result.Minimum;
                    m[CreateProperty(propertyName, Median)] = result.Median !.Value;
                    m[CreateProperty(propertyName, Mean)]   = result.Mean;
                    m[CreateProperty(propertyName, Mode)]   = result.Mode !.Value;
                    m[CreateProperty(propertyName, Range)]  = result.Range;
                    m[CreateProperty(propertyName, Count)]  = result.Count;
                }
            }));

            foreach (var analyzer in analyzers)
            {
                if (analyzer is DiagnosticIncrementalAnalyzer diagIncrementalAnalyzer)
                {
                    diagIncrementalAnalyzer.LogAnalyzerCountSummary();
                    break;
                }
            }
        }
Exemplo n.º 12
0
        public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, LogAggregator logAggregator, ImmutableArray <IIncrementalAnalyzer> analyzers)
        {
            Logger.Log(FunctionId.IncrementalAnalyzerProcessor_Shutdown, KeyValueLogMessage.Create(m =>
            {
                var solutionHash = GetSolutionHash(solution);

                m[Id]           = correlationId.ToString();
                m[SolutionHash] = solutionHash.ToString();

                var statMap = new Dictionary <string, List <int> >();
                foreach (var kv in logAggregator)
                {
                    if (kv.Key is string)
                    {
                        m[kv.Key.ToString()] = kv.Value.GetCount().ToString();
                        continue;
                    }

                    if (kv.Key is ValueTuple <string, Guid> )
                    {
                        var tuple = (ValueTuple <string, Guid>)kv.Key;
                        var list  = statMap.GetOrAdd(tuple.Item1, _ => new List <int>());
                        list.Add(kv.Value.GetCount());
                        continue;
                    }

                    throw ExceptionUtilities.Unreachable;
                }

                foreach (var kv in statMap)
                {
                    var key    = kv.Key.ToString();
                    var result = LogAggregator.GetStatistics(kv.Value);

                    m[CreateProperty(key, Max)]    = result.Maximum.ToString();
                    m[CreateProperty(key, Min)]    = result.Minimum.ToString();
                    m[CreateProperty(key, Median)] = result.Median.ToString();
                    m[CreateProperty(key, Mean)]   = result.Mean.ToString();
                    m[CreateProperty(key, Mode)]   = result.Mode.ToString();
                    m[CreateProperty(key, Range)]  = result.Range.ToString();
                    m[CreateProperty(key, Count)]  = result.Count.ToString();
                }
            }));

            foreach (var analyzer in analyzers)
            {
                var diagIncrementalAnalyzer = analyzer as DiagnosticAnalyzerService.DiagnosticIncrementalAnalyzer;
                if (diagIncrementalAnalyzer != null)
                {
                    diagIncrementalAnalyzer.LogAnalyzerCountSummary();
                    break;
                }
            }
        }
 public DiagnosticAnalyzerDriver(Project project, LogAggregator logAggregator, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource, CancellationToken cancellationToken)
     : this(project, project.LanguageServices.GetService <ISyntaxNodeAnalyzerService>(), hostDiagnosticUpdateSource, overriddenOnAnalyzerException : null, cancellationToken : cancellationToken)
 {
     _logAggregator = logAggregator;
 }
 public DiagnosticAnalyzerDriver(Document document, TextSpan?span, SyntaxNode root, LogAggregator logAggregator, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource, CancellationToken cancellationToken)
     : this(document, span, root, document.Project.LanguageServices.GetService <ISyntaxNodeAnalyzerService>(), hostDiagnosticUpdateSource, overriddenOnAnalyzerException : null, cancellationToken : cancellationToken)
 {
     _logAggregator = logAggregator;
 }
Exemplo n.º 15
0
 public static void LogResetStates(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(ResetStates);
 }
Exemplo n.º 16
0
 public static void LogProcessOpenDocument(LogAggregator logAggregator, Guid documentId)
 {
     logAggregator.IncreaseCount(OpenDocument);
     logAggregator.IncreaseCount(ValueTuple.Create(OpenDocument, documentId));
 }
Exemplo n.º 17
0
 public static void LogProcessProjectNotExist(LogAggregator logAggregator)
 => logAggregator.IncreaseCount(ProjectNotExist);
Exemplo n.º 18
0
        public static void LogProcessProject(LogAggregator logAggregator, Guid projectId, bool processed)
        {
            if (processed)
            {
                logAggregator.IncreaseCount(ProcessProject);
            }
            else
            {
                logAggregator.IncreaseCount(ProcessProjectCancellation);
            }

            logAggregator.IncreaseCount(ValueTuple.Create(ProcessProject, projectId));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Adds LogAggregator to DisterService
 /// </summary>
 /// <param name="logAggregator">LogAggregator instance</param>
 /// <returns></returns>
 public ServiceBuilder <T> WithLogAggregator(LogAggregator <T> logAggregator)
 {
     service.LogAggregator = logAggregator;
     modules.Add(logAggregator);
     return(this);
 }
Exemplo n.º 20
0
 public DiagnosticAnalyzerDriver(Project project, LogAggregator logAggregator, CancellationToken cancellationToken)
     : this(project, project.LanguageServices.GetService<ISyntaxNodeAnalyzerService>(), cancellationToken)
 {
     _logAggregator = logAggregator;
 }
 private void ResetLogAggregator()
 {
     _logAggregator = new LogAggregator();
 }
Exemplo n.º 22
0
        public static void LogAnalyzerCrashCount(DiagnosticAnalyzer analyzer, Exception ex, LogAggregator logAggregator, ProjectId projectId)
        {
            if (logAggregator == null || analyzer == null || ex == null || ex is OperationCanceledException)
            {
                return;
            }

            // TODO: once we create description manager, pass that into here.
            bool telemetry = DiagnosticAnalyzerLogger.AllowsTelemetry(null, analyzer, projectId);
            var  tuple     = ValueTuple.Create(telemetry, analyzer.GetType(), ex.GetType());

            logAggregator.IncreaseCount(tuple);
        }
Exemplo n.º 23
0
 public static int GetNextId()
 {
     return(LogAggregator.GetNextId());
 }
Exemplo n.º 24
0
 public static void LogWorkspaceEvent(LogAggregator logAggregator, int kind)
 {
     logAggregator.IncreaseCount(kind);
 }
Exemplo n.º 25
0
 public static void LogWorkspaceEvent(LogAggregator logAggregator, int kind)
 {
     logAggregator.IncreaseCount(kind);
 }
Exemplo n.º 26
0
 public static void LogGlobalOperation(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(GlobalOperation);
 }
Exemplo n.º 27
0
 public static void LogGlobalOperation(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(GlobalOperation);
 }
Exemplo n.º 28
0
 public static void LogWorkItemEnqueue(LogAggregator logAggregator, ProjectId projectId)
 {
     logAggregator.IncreaseCount(ProjectEnqueue);
 }
Exemplo n.º 29
0
 public static void LogActiveFileEnqueue(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(ActiveFileEnqueue);
 }
Exemplo n.º 30
0
 public static void LogHigherPriority(LogAggregator logAggregator, Guid documentId)
 {
     logAggregator.IncreaseCount(HigherPriority);
     logAggregator.IncreaseCount(ValueTuple.Create(HigherPriority, documentId));
 }
Exemplo n.º 31
0
 public static void LogWorkItemEnqueue(LogAggregator logAggregator, ProjectId projectId)
 {
     logAggregator.IncreaseCount(ProjectEnqueue);
 }
Exemplo n.º 32
0
        public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, LogAggregator logAggregator, ImmutableArray<IIncrementalAnalyzer> analyzers)
        {
            Logger.Log(FunctionId.IncrementalAnalyzerProcessor_Shutdown, KeyValueLogMessage.Create(m =>
            {
                var solutionHash = GetSolutionHash(solution);

                m[Id] = correlationId;
                m[SolutionHash] = solutionHash.ToString();

                var statMap = new Dictionary<string, List<int>>();
                foreach (var kv in logAggregator)
                {
                    if (kv.Key is string)
                    {
                        m[kv.Key.ToString()] = kv.Value.GetCount();
                        continue;
                    }

                    if (kv.Key is ValueTuple<string, Guid>)
                    {
                        var tuple = (ValueTuple<string, Guid>)kv.Key;
                        var list = statMap.GetOrAdd(tuple.Item1, _ => new List<int>());
                        list.Add(kv.Value.GetCount());
                        continue;
                    }

                    throw ExceptionUtilities.Unreachable;
                }

                foreach (var kv in statMap)
                {
                    var key = kv.Key.ToString();
                    var result = LogAggregator.GetStatistics(kv.Value);

                    m[CreateProperty(key, Max)] = result.Maximum;
                    m[CreateProperty(key, Min)] = result.Minimum;
                    m[CreateProperty(key, Median)] = result.Median;
                    m[CreateProperty(key, Mean)] = result.Mean;
                    m[CreateProperty(key, Mode)] = result.Mode;
                    m[CreateProperty(key, Range)] = result.Range;
                    m[CreateProperty(key, Count)] = result.Count;
                }
            }));

            foreach (var analyzer in analyzers)
            {
                var diagIncrementalAnalyzer = analyzer as BaseDiagnosticIncrementalAnalyzer;
                if (diagIncrementalAnalyzer != null)
                {
                    diagIncrementalAnalyzer.LogAnalyzerCountSummary();
                    break;
                }
            }
        }
Exemplo n.º 33
0
 public static void LogHigherPriority(LogAggregator logAggregator, Guid documentId)
 {
     logAggregator.IncreaseCount(HigherPriority);
     logAggregator.IncreaseCount(ValueTuple.Create(HigherPriority, documentId));
 }
Exemplo n.º 34
0
 public static void LogProcessActiveFileDocument(LogAggregator logAggregator, Guid documentId, bool processed)
 {
     if (processed)
     {
         logAggregator.IncreaseCount(ActiveFileProcessDocument);
     }
     else
     {
         logAggregator.IncreaseCount(ActiveFileProcessDocumentCancellation);
     }
 }
Exemplo n.º 35
0
 public static void LogResetStates(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(ResetStates);
 }
Exemplo n.º 36
0
 public static void LogProcessDocumentNotExist(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(DocumentNotExist);
 }
Exemplo n.º 37
0
 public DiagnosticAnalyzerDriver(Document document, TextSpan? span, SyntaxNode root, LogAggregator logAggregator, CancellationToken cancellationToken)
     : this(document, span, root, document.Project.LanguageServices.GetService<ISyntaxNodeAnalyzerService>(), cancellationToken)
 {
     _logAggregator = logAggregator;
 }
Exemplo n.º 38
0
 public static void LogProcessProjectNotExist(LogAggregator logAggregator)
 {
     logAggregator.IncreaseCount(ProjectNotExist);
 }
Exemplo n.º 39
0
        private async Task LoadLogsAsync(ILogStore logStore)
        {
            var hasPath = !string.IsNullOrEmpty(logStore.Path);

            if (hasPath)
            {
                SetOverlayState(OverlayState.Loading);
            }

            var aggregator  = new LogAggregator();
            var treeBuilder = new LogTreeBuilder();

            List <LogItem> logs = null;

            await Task.Run(async() => logs = await ReadLogsAsync(logStore).ConfigureAwait(false));

            while (logs == null)
            {
                Thread.Sleep(50);
            }

            _logs        = aggregator.Aggregate(logs);
            _lastLogPath = logStore.Path;

            // Generate a data table and bind the date-time client to it.
            dateTimeChartRangeControlClient1.DataProvider.DataSource = _logs;

            // Specify data members to bind the client.
            dateTimeChartRangeControlClient1.DataProvider.ArgumentDataMember = nameof(RangeDatasourceItem.TimeStampLocal);
            dateTimeChartRangeControlClient1.DataProvider.ValueDataMember    = nameof(RangeDatasourceItem.ItemCount);
            dateTimeChartRangeControlClient1.DataProvider.SeriesDataMember   = nameof(RangeDatasourceItem.State);
            dateTimeChartRangeControlClient1.DataProvider.TemplateView       = new BarChartRangeControlClientView()
            {
            };
            dateTimeChartRangeControlClient1.PaletteName = "Solstice";

            var allStates   = Enum.GetValues(typeof(LogItem.State)).OfType <LogItem.State>().ToArray();
            var timestamps  = logs.Select(l => l.TimeStampLocal).Distinct();
            var rangeSource = timestamps.SelectMany(localTime =>
            {
                return(allStates.Select(state => new RangeDatasourceItem
                {
                    TimeStampLocal = localTime,
                    State = state,
                    ItemCount = _logs.Count(l => l.TimeStampLocal == localTime && l.AccumulatedState >= state)
                }));
            });

            dateTimeChartRangeControlClient1.DataProvider.DataSource = rangeSource;

            SetControlVisiblityByContext();

            if (_logs.Any())
            {
                SetOverlayState(OverlayState.None);
            }
            else
            {
                SetOverlayState(OverlayState.Empty);
            }
        }