Exemplo n.º 1
0
        //handle new ProfileLog opened message
        public void Handle(ProfileLog newProfileLog)
        {
            PLog = newProfileLog;

            Ranges.ClearRanges();
            Model.Annotations.Clear();
            Ranges.ReinstallAnnotations();

            List <DataPoint> frames;

            if (PLog.Frames.Count != 0)
            {
                long start = PLog.StartTime;
                frames = PLog.Frames.Select(f => new DataPoint(f.EndTimeMS, f.Time)).ToList();

                var markedFrames = PLog.Frames.
                                   Where(f => f.Markers.Length != 0).
                                   Select(f => f.Markers.FirstOrDefault(m => m.Kind == MarkerKind.LUA_TRACESFLUSHED) ?? f.Markers.First()).
                                   ToList();

                var flushFrames = new HashSet <ProfileFrame>();

                foreach (var marker in markedFrames)
                {
                    flushFrames.Add(marker.Frame);

                    var text = $"{marker.Kind}";

                    if (marker.Kind == MarkerKind.LUA_TRACESFLUSHED)
                    {
                        text = $"Trace Flush {marker.Label} Thread: {marker.Frame.Threads[marker.ThreadId].Name}";
                    }
                    else if (marker.Kind == MarkerKind.FOCUS_LOST || marker.Kind == MarkerKind.FOCUS_GAINED)
                    {
                        text = $"{marker.Label}";
                    }
                    else if (marker.UserValue != 0)
                    {
                        text = $"{marker.Label} {marker.UserValue} Thread: {marker.Frame.Threads[marker.ThreadId].Name}";
                    }

                    var annotation = new LineAnnotation()
                    {
                        X       = marker.Frame.EndTimeMS,
                        Text    = text,
                        Tag     = marker,
                        ToolTip = "",
                        Type    = LineAnnotationType.Vertical,
                    };
                    Model.Annotations.Add(annotation);
                }

                var lj = PLog.GetMatchingNodes("lj");

                if (lj.Count != 0)
                {
                    foreach (var item in PLog.GetNodeFrameStats(lj.First().Id))
                    {
                        if (flushFrames.Contains(item.Frame))
                        {
                            continue;
                        }

                        var annotation = new LineAnnotation()
                        {
                            X    = item.Frame.EndTimeMS,
                            Text = $"Trace Flush",
                            Tag  = item,
                            Type = LineAnnotationType.Vertical,
                        };
                        Model.Annotations.Add(annotation);
                    }
                }
            }
            else
            {
                frames = new List <DataPoint>();
            }

            FrametimePoints = frames;

            LeftAxis.Zoom(0, 60);
            BottomAxis.Zoom(0, 1000 * 60);
            Model.InvalidatePlot(true);
        }