Пример #1
0
        public void StatusEventRaised(object sender, BuildStatusEventArgs e)
        {
            try
            {
                lock (syncLock)
                {
                    if (e is ProjectEvaluationStartedEventArgs projectEvaluationStarted)
                    {
                        var evaluationId      = projectEvaluationStarted.BuildEventContext.EvaluationId;
                        var projectFilePath   = Intern(projectEvaluationStarted.ProjectFile);
                        var projectName       = Intern(Path.GetFileName(projectFilePath));
                        var nodeName          = Intern(GetEvaluationProjectName(evaluationId, projectName));
                        var projectEvaluation = new ProjectEvaluation {
                            Name = nodeName
                        };
                        EvaluationFolder.AddChild(projectEvaluation);
                        projectEvaluation.ProjectFile = projectFilePath;

                        projectEvaluation.Id             = evaluationId;
                        projectEvaluation.EvaluationText = Intern("id:" + evaluationId);
                        projectEvaluation.NodeId         = e.BuildEventContext.NodeId;
                        projectEvaluation.StartTime      = e.Timestamp;
                        projectEvaluation.EndTime        = e.Timestamp;
                    }
                    else if (e is ProjectEvaluationFinishedEventArgs projectEvaluationFinished)
                    {
                        var evaluationId      = projectEvaluationFinished.BuildEventContext.EvaluationId;
                        var projectFilePath   = Intern(projectEvaluationFinished.ProjectFile);
                        var projectName       = Intern(Path.GetFileName(projectFilePath));
                        var nodeName          = Intern(GetEvaluationProjectName(evaluationId, projectName));
                        var projectEvaluation = EvaluationFolder.FindLastChild <ProjectEvaluation>(e => e.Id == evaluationId);
                        if (projectEvaluation == null)
                        {
                            // no matching ProjectEvaluationStarted
                            return;
                        }

                        projectEvaluation.EndTime = e.Timestamp;

                        var profilerResult = projectEvaluationFinished.ProfilerResult;
                        if (profilerResult != null && projectName != null)
                        {
                            ConstructProfilerResult(projectEvaluation, profilerResult.Value);
                        }

                        if (projectEvaluationFinished.GlobalProperties != null)
                        {
                            AddGlobalProperties(projectEvaluation, projectEvaluationFinished.GlobalProperties);
                        }

                        AddProperties(projectEvaluation, projectEvaluationFinished.Properties);
                        AddItems(projectEvaluation, projectEvaluationFinished.Items);
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Пример #2
0
        private void ConstructProfilerResult(ProjectEvaluation projectEvaluation, ProfilerResult profilerResult)
        {
            var nodes = new Dictionary <long, EvaluationProfileEntry>();

            foreach (var kvp in profilerResult.ProfiledLocations)
            {
                var location = kvp.Key;
                var result   = kvp.Value;

                if (!nodes.TryGetValue(location.Id, out var node))
                {
                    node = new EvaluationProfileEntry();
                    nodes[location.Id] = node;

                    node.ElementName               = location.ElementName;
                    node.ElementDescription        = location.ElementDescription;
                    node.EvaluationPassDescription = location.EvaluationPassDescription;
                    node.Kind           = location.Kind;
                    node.SourceFilePath = location.File;
                    node.LineNumber     = location.Line ?? 0;

                    node.AddEntry(result);
                }
            }

            foreach (var kvp in profilerResult.ProfiledLocations)
            {
                var location = kvp.Key;

                if (nodes.TryGetValue(location.Id, out var node))
                {
                    if (location.ParentId.HasValue && nodes.TryGetValue(location.ParentId.Value, out var parentNode))
                    {
                        parentNode.AddChild(node);

                        var parentDuration = parentNode.ProfiledLocation.InclusiveTime.TotalMilliseconds;
                        var duration       = node.ProfiledLocation.InclusiveTime.TotalMilliseconds;

                        double ratio = GetRatio(parentDuration, duration);

                        node.Value = ratio;
                    }
                    else
                    {
                        projectEvaluation.AddChildAtBeginning(node);
                        node.Value = 100;
                    }
                }
            }
        }