Example #1
0
        private void ProcessTaskStartEvent(TaskStartedEvent e, TimelineBuilderContext context)
        {
            Debug.Assert(context.HasOpenBuilds);
            Debug.Assert(context.HasOpenProjects);
            Debug.Assert(context.HasOpenTargets);

            BuildEntry taskEntry = new BuildEntry(e);

            context.OpenTaskEntries.Add(taskEntry);

            // a task's parent is a Target
            TaskEventContext taskContext = taskEntry.Context as TaskEventContext;

            Debug.Assert(taskContext != null);
            BuildEntry parentEntry = context.OpenTargetEntries.Find(targetEntry =>
            {
                TargetEventContext targetContext = targetEntry.Context as TargetEventContext;
                Debug.Assert(targetContext != null);

                return(targetContext.ContextId == taskContext.ContextId &&
                       targetContext.ProjectId == taskContext.ProjectId &&
                       targetContext.TargetId == taskContext.TargetId);
            });

            Debug.Assert(parentEntry != null);
            parentEntry.AddChild(e);
            parentEntry.AddChild(taskEntry);
        }
 public TimelineBuildEntry(BuildEntry buildEntry, BuildData buildData) :
     base(ExtractNameFrom(buildEntry, buildData),
          buildEntry.Context == null ? 0 : buildEntry.Context.NodeId,
          buildEntry.StartEvent.Timestamp,
          buildEntry.EndEvent.Timestamp)
 {
     BuildEntry = buildEntry;
 }
Example #3
0
        private void ProcessProjectStartEvent(ProjectStartedEvent e, TimelineBuilderContext context)
        {
            Debug.Assert(context.HasOpenBuilds);

            BuildEntry projectEntry = new BuildEntry(e);

            context.OpenProjectEntries.Add(projectEntry);

            // projects always have a parent, we know which via parent event context
            BuildEntry parentEntry = null;

            // no parent event context mean we've been spawned from the build itself
            if (e.ParentEventContext == null)
            {
                parentEntry = context.RootEntry;
            }
            else
            {
                // a project's parent is a task, although the parent context refers to the task project's
                parentEntry = context.OpenTaskEntries.Find(taskEntry =>
                {
                    TaskEventContext taskContext = taskEntry.Context as TaskEventContext;
                    Debug.Assert(taskContext != null);

                    return(taskContext.ContextId == e.ParentEventContext.ContextId &&
                           taskContext.ProjectId == e.ParentEventContext.ProjectId);
                });

                // finding no task with matching data means our build was requested by a task that's already completed
                // we may have some luck finding the project that spawned that task
                if (parentEntry == null)
                {
                    // our build couldn't be started before within the same node, hence it was scheduled
                    Debug.Assert(e.Context.NodeId != e.ParentEventContext.NodeId);

                    parentEntry = context.OpenProjectEntries.Find(otherProjectEntry =>
                    {
                        ProjectEventContext projectContext = otherProjectEntry.Context as ProjectEventContext;
                        Debug.Assert(projectContext != null);

                        return(projectContext.ContextId == e.ParentEventContext.ContextId &&
                               projectContext.ProjectId == e.ParentEventContext.ProjectId);
                    });

                    // the project may have also finished
                    if (parentEntry == null)
                    {
                        // just consider the build itself our parent
                        parentEntry = context.RootEntry;
                    }
                }
            }

            Debug.Assert(parentEntry != null);
            parentEntry.AddChild(e);
            parentEntry.AddChild(projectEntry);
        }
Example #4
0
        private void ProcessProjectEndEvent(ProjectFinishedEvent e, TimelineBuilderContext context)
        {
            Debug.Assert(context.HasOpenBuilds);

            BuildEntry projectEntry = context.OpenProjectEntries.Find(_ => _.Context.Equals(e.Context));

            Debug.Assert(projectEntry != null);

            projectEntry.Parent.AddChild(e);
            projectEntry.CloseWith(e);
            context.OpenProjectEntries.Remove(projectEntry);
        }
Example #5
0
        private void ProcessBuildStartEvent(BuildStartedEvent e, TimelineBuilderContext context)
        {
            Debug.Assert(!context.HasOpenBuilds);
            Debug.Assert(!context.HasOpenProjects);
            Debug.Assert(!context.HasOpenTargets);
            Debug.Assert(!context.HasOpenTasks);
            Debug.Assert(context.RootEntry == null);

            BuildEntry buildEntry = new BuildEntry(e);

            context.OpenBuildEntries.Add(buildEntry);
            context.RootEntry = buildEntry;
        }
Example #6
0
        private void ProcessBuildEndEvent(BuildFinishedEvent e, TimelineBuilderContext context)
        {
            Debug.Assert(context.OpenBuildEntries.Count == 1);
            Debug.Assert(!context.HasOpenProjects);
            Debug.Assert(!context.HasOpenTargets);
            Debug.Assert(!context.HasOpenTasks);

            BuildEntry buildEntry = context.OpenBuildEntries[0];

            Debug.Assert(buildEntry != null);

            buildEntry.CloseWith(e);
            context.OpenBuildEntries.Remove(buildEntry);
        }
        private static string ExtractNameFrom(BuildEntry buildEntry, BuildData buildData)
        {
            Event  e    = buildEntry.StartEvent;
            string name = null;

            if (e is BuildStartedEvent)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append($"{buildData.BuildConfiguration.Target}");
                builder.Append($" - {buildData.BuildConfiguration.Configuration}|{buildData.BuildConfiguration.Platform}");
                builder.Append($" - Max parallel: {buildData.BuildConfiguration.MaxParallelProjects} projects, {buildData.BuildConfiguration.MaxParallelCLTasksPerProject} CL tasks per project");
                builder.Append($" - {buildData.BuildConfiguration.SolutionPath}");

                name = builder.ToString();
            }
            else if (e is ProjectStartedEvent)
            {
                name = (e as ProjectStartedEvent).ProjectFile;

                // find the longest common path between project and solution, then remove it from project file path
                string[] solutionPath = buildData.BuildConfiguration.SolutionPath.Split(Path.DirectorySeparatorChar);
                string[] projectPath  = name.Split(Path.DirectorySeparatorChar);

                int firstDifferenceIndex = -1;
                int minPathSteps         = Math.Min(solutionPath.Length, projectPath.Length);
                for (int i = 0; i < minPathSteps; ++i)
                {
                    if (solutionPath[i] != projectPath[i])
                    {
                        firstDifferenceIndex = i;
                        break;
                    }
                }

                if (firstDifferenceIndex >= 0)
                {
                    name = String.Join(Path.DirectorySeparatorChar.ToString(), projectPath, firstDifferenceIndex, projectPath.Length - firstDifferenceIndex);
                }
            }
            else if (e is TargetStartedEvent)
            {
                name = (e as TargetStartedEvent).TargetName;
            }
            else if (e is TaskStartedEvent)
            {
                name = (e as TaskStartedEvent).TaskName;
            }

            return(name);
        }
Example #8
0
        private void ProcessMessageEvent(MessageEvent e, TimelineBuilderContext context)
        {
            Debug.Assert(context.HasOpenBuilds);

            // a message can be executed as part of any entry: build, project, target or task
            BuildEntry parentEntry = null;

            // part of the build?
            if (e.Context == null)
            {
                parentEntry = context.RootEntry;
            }
            else
            {
                MessageEventContext messageContext = e.Context as MessageEventContext;

                // part of a task?
                if (messageContext.TaskId != null)
                {
                    Debug.Assert(messageContext.ProjectId != null);
                    Debug.Assert(messageContext.TargetId != null);

                    parentEntry = context.OpenTaskEntries.Find(taskEntry =>
                    {
                        TaskEventContext taskContext = taskEntry.Context as TaskEventContext;
                        Debug.Assert(taskContext != null);

                        return(taskContext.NodeId == messageContext.NodeId &&
                               taskContext.ContextId == messageContext.ContextId &&
                               taskContext.ProjectId == messageContext.ProjectId &&
                               taskContext.TargetId == messageContext.TargetId &&
                               taskContext.TaskId == messageContext.TaskId);
                    });
                }
                // part of a target?
                else if (messageContext.TargetId != null)
                {
                    Debug.Assert(messageContext.ProjectId != null);
                    Debug.Assert(messageContext.TaskId == null);

                    parentEntry = context.OpenTargetEntries.Find(targetEntry =>
                    {
                        TargetEventContext targetContext = targetEntry.Context as TargetEventContext;
                        Debug.Assert(targetContext != null);

                        return(targetContext.NodeId == messageContext.NodeId &&
                               targetContext.ContextId == messageContext.ContextId &&
                               targetContext.ProjectId == messageContext.ProjectId &&
                               targetContext.TargetId == messageContext.TargetId);
                    });
                }
                // part of a project?
                else if (messageContext.ProjectId != null)
                {
                    Debug.Assert(messageContext.TargetId == null);
                    Debug.Assert(messageContext.TaskId == null);

                    parentEntry = context.OpenProjectEntries.Find(projectEntry =>
                    {
                        ProjectEventContext projectContext = projectEntry.Context as ProjectEventContext;
                        Debug.Assert(projectContext != null);

                        return(projectContext.NodeId == messageContext.NodeId &&
                               projectContext.ContextId == messageContext.ContextId &&
                               projectContext.ProjectId == messageContext.ProjectId);
                    });
                }
                // part of the build itself?
                else
                {
                    parentEntry = context.RootEntry;
                }
            }

            Debug.Assert(parentEntry != null);
            parentEntry.AddChild(e);
        }
Example #9
0
 public void AddChild(BuildEntry entry)
 {
     ChildEntries.Add(entry);
     entry.Parent = this;
 }