Ejemplo n.º 1
0
        void InitThreadList(FrameGroup group)
        {
            List <ThreadRow> rows = new List <ThreadRow>();

            if (group != null)
            {
                rows.Add(new HeaderThreadRow(group)
                {
                    GradientTop    = (ThreadViewControl.OptickAlternativeBackground as SolidColorBrush).Color,
                    GradientBottom = (ThreadViewControl.OptickBackground as SolidColorBrush).Color,
                    TextColor      = Colors.Gray,
                    Header         = new ThreadFilterView(),
                });

                ChartRow cpuCoreChart = GenerateCoreChart(group);
                if (cpuCoreChart != null)
                {
                    cpuCoreChart.IsExpanded     = false;
                    cpuCoreChart.ExpandChanged += CpuCoreChart_ExpandChanged;
                    cpuCoreChart.ChartHover    += Row_ChartHover;
                    rows.Add(cpuCoreChart);
                }

                List <EventsThreadRow> threadRows = GenerateThreadRows(group);
                foreach (EventsThreadRow row in threadRows)
                {
                    if (row.Description.Origin == ThreadDescription.Source.Core)
                    {
                        row.IsVisible = false;
                        coreRows.Add(row);
                    }
                }
                rows.AddRange(threadRows);
            }

            ThreadViewControl.InitRows(rows, group != null ? group.Board.TimeSlice : null);

            List <ITick> frames = null;

            if (Group != null && Group.Frames != null && Group.Frames[FrameList.Type.CPU] != null)
            {
                FrameList list = Group.Frames[FrameList.Type.CPU];
                frames = list.Events.ConvertAll(frame => frame as ITick);
            }
            else if (Group != null)
            {
                frames = new List <ITick>();
                long step = Durable.MsToTick(1000.0);
                for (long timestamp = Group.Board.TimeSlice.Start; timestamp < Group.Board.TimeSlice.Finish; timestamp += step)
                {
                    frames.Add(new Tick()
                    {
                        Start = timestamp
                    });
                }
            }

            ThreadViewControl.InitForegroundLines(frames);
        }
Ejemplo n.º 2
0
        public static ChartRow GenerateCoreChart(FrameGroup group)
        {
            if (group.Synchronization == null || group.Synchronization.Events.Count == 0)
            {
                return(null);
            }

            group.Synchronization.Events.Sort();

            int eventsCount = group.Synchronization.Events.Count;

            List <Tick> timestamps = new List <Tick>(eventsCount);

            ChartRow.Entry currProcess = new ChartRow.Entry(eventsCount)
            {
                Fill = Colors.LimeGreen, Name = "Current Process"
            };
            ChartRow.Entry otherProcess = new ChartRow.Entry(eventsCount)
            {
                Fill = Colors.Tomato, Name = "Other Process"
            };

            List <bool> isCoreInUse = new List <bool>(group.Board.CPUCoreCount);

            int currCores  = 0;
            int otherCores = 0;

            foreach (SyncEvent ev in group.Synchronization.Events)
            {
                ProcessGroup prevGroup = GetProcessGroup(group, ev.OldThreadID);
                ProcessGroup currGroup = GetProcessGroup(group, ev.NewThreadID);

                while (isCoreInUse.Count <= ev.CPUID)
                {
                    isCoreInUse.Add(false);
                }

                if ((prevGroup != currGroup) || !isCoreInUse[ev.CPUID])
                {
                    timestamps.Add(ev.Timestamp);

                    if (isCoreInUse[ev.CPUID])
                    {
                        switch (prevGroup)
                        {
                        case ProcessGroup.CurrentProcess:
                            --currCores;
                            break;

                        case ProcessGroup.OtherProcess:
                            --otherCores;
                            break;
                        }
                    }

                    isCoreInUse[ev.CPUID] = true;
                    switch (currGroup)
                    {
                    case ProcessGroup.CurrentProcess:
                        ++currCores;
                        break;

                    case ProcessGroup.OtherProcess:
                        ++otherCores;
                        break;
                    }

                    currProcess.Values.Add((double)currCores);
                    otherProcess.Values.Add((double)otherCores);
                }
            }

            ChartRow chart = new ChartRow("CPU", timestamps, new List <ChartRow.Entry>()
            {
                currProcess, otherProcess
            }, isCoreInUse.Count);

            return(chart);
        }