Example #1
0
        void FindMatchingPairs()
        {
            data = new List <BeginEndEvent>();
            Dictionary <PerformanceEventArrivedEventArgsKey, PerformanceEventArrivedEventArgs> open = new Dictionary <PerformanceEventArrivedEventArgsKey, PerformanceEventArrivedEventArgs>();

            start = long.MaxValue;
            end   = 0;
            foreach (PerformanceEventArrivedEventArgs e in rawdata)
            {
                PerformanceEventArrivedEventArgsKey key = new PerformanceEventArrivedEventArgsKey(e);
                if (e.EventId == BeginEvent)
                {
                    open[key] = e;
                }
                else if (e.EventId == EndEvent)
                {
                    PerformanceEventArrivedEventArgs s;
                    if (open.TryGetValue(key, out s))
                    {
                        if (s.Timestamp < start)
                        {
                            start = s.Timestamp;
                        }
                        if (e.Timestamp > end)
                        {
                            end = e.Timestamp;
                        }
                        data.Add(new BeginEndEvent()
                        {
                            Begin = s, End = e
                        });
                    }
                }
            }
        }
Example #2
0
        internal void WriteXml(string filename, List <PerformanceEventArrivedEventArgs> events)
        {
            XmlWriterSettings s = new XmlWriterSettings();

            s.Indent = true;

            using (XmlWriter w = XmlWriter.Create(filename, s))
            {
                long start = 0;
                w.WriteStartElement("PerformanceData");
                if (events.Count > 0)
                {
                    start = events[0].Timestamp;
                    long end = events[events.Count - 1].Timestamp;
                    w.WriteAttributeString("Duration", (end - start).ToString());
                }

                Dictionary <PerformanceEventArrivedEventArgsKey, PerformanceEventArrivedEventArgs> open = new Dictionary <PerformanceEventArrivedEventArgsKey, PerformanceEventArrivedEventArgs>();

                foreach (var e in events)
                {
                    PerformanceEventArrivedEventArgsKey key = new PerformanceEventArrivedEventArgsKey(e);
                    if (e.EventId == BeginEvent)
                    {
                        open[key] = e;
                    }
                    else if (e.EventId == EndEvent)
                    {
                        w.WriteStartElement("Event");
                        WriteEventCategory(w, e);
                        w.WriteAttributeString("Timestamp", (e.Timestamp - start).ToString())
                        ;
                        PerformanceEventArrivedEventArgs begin = null;
                        if (open.TryGetValue(key, out begin))
                        {
                            long eventDuration = e.Timestamp - begin.Timestamp;
                            w.WriteAttributeString("Duration", eventDuration.ToString());
                            w.WriteEndElement();
                        }
                    }
                    else
                    {
                        w.WriteStartElement("Event");
                        WriteEventCategory(w, e);
                        w.WriteAttributeString("Timestamp", (e.Timestamp - start).ToString());
                        w.WriteEndElement();
                    }
                }

                w.WriteEndElement();
            }
        }
Example #3
0
        void PrepareLegend()
        {
            Legend.Clear();
            legendColors = new Dictionary <PerformanceEventArrivedEventArgsKey, Tuple <int, Color> >();

            foreach (BeginEndEvent record in data)
            {
                PerformanceEventArrivedEventArgs begin = record.Begin;
                PerformanceEventArrivedEventArgs e     = record.End;

                Tuple <int, Color> style;
                PerformanceEventArrivedEventArgsKey key = new PerformanceEventArrivedEventArgsKey(begin);
                if (!legendColors.TryGetValue(key, out style))
                {
                    int   i     = legendColors.Count;
                    Color color = GetColor(i);
                    legendColors[key] = style = new Tuple <int, Color>(i, color);
                    Legend.AddItem(color, key.Label);
                }
            }
        }
Example #4
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(Brushes.White, null, new Rect(new Point(0, 0), this.RenderSize));

            gesture.HidePopup();
            if (data == null || data.Count == 0)
            {
                return;
            }

            long span = end - start; // ticks

            double ticksPerLabel = (zoom * frequency);
            double scale         = pixelsPerLabel / ticksPerLabel;

            if (ZoomToFit)
            {
                //double labels = (int)(this.ActualWidth / pixelsPerLabel);
                //while (ticksPerLabel * labels > span)
                //{
                //    zoom = ZoomIn(zoom);
                //    actualZoom = 1 / (zoom * frequency);
                //    ticksPerLabel = (pixelsPerLabel * actualZoom);
                //}
                //while (ticksPerLabel * labels < span)
                //{
                //    zoom = ZoomOut(zoom);
                //    actualZoom = 1 / (zoom * frequency);
                //    ticksPerLabel = (pixelsPerLabel * actualZoom);
                //}
            }

            extent = Rect.Empty;

            double maxy = 0;
            double maxx = 0;

            foreach (BeginEndEvent record in data)
            {
                PerformanceEventArrivedEventArgs begin = record.Begin;
                PerformanceEventArrivedEventArgs e     = record.End;

                Brush color = null;
                PerformanceEventArrivedEventArgsKey key = new PerformanceEventArrivedEventArgsKey(begin);
                Tuple <int, Color> style = legendColors[key];
                color = new SolidColorBrush(style.Item2);

                double y      = 20 + style.Item1 * 22;
                double x      = HorizontalMargin + (double)(begin.Timestamp - start) * (double)scale;
                double w      = (double)(e.Timestamp - begin.Timestamp) * (double)scale;
                Rect   bounds = new Rect(x, y, w, 20);
                maxy = Math.Max(maxy, y + 20);
                maxx = Math.Max(maxx, x + w);
                drawingContext.DrawRectangle(color, new Pen(color, 1), bounds);
                record.Bounds = bounds;
                extent        = Rect.Union(extent, bounds);
            }

            // Draw scale
            Typeface typeface = new Typeface("Segoe UI");

            maxy += 20;
            Pen pen = new Pen(Brushes.Black, 1);

            drawingContext.DrawLine(pen, new Point(HorizontalMargin, maxy - 5), new Point(HorizontalMargin, maxy + 5));
            drawingContext.DrawLine(pen, new Point(maxx, maxy - 5), new Point(maxx, maxy + 5));
            drawingContext.DrawLine(pen, new Point(HorizontalMargin, maxy), new Point(maxx, maxy));

            double unit     = 0;
            double unitStep = zoom; // zoom is inverse .
            string units    = "s";  // seconds;

            if (unitStep.ToString("N").StartsWith("0.0"))
            {
                unitStep *= 1000;
                units     = "ms";
            }
            if (unitStep.ToString("N").StartsWith("0.0"))
            {
                unitStep *= 1000;
                units     = "μs";
            }

            int digits = GetDigits(zoom);

            for (double i = 0; i < span; i += ticksPerLabel)
            {
                double x = HorizontalMargin + (i * scale);
                drawingContext.DrawLine(pen, new Point(x, maxy - 5), new Point(x, maxy + 5));
                string label = Math.Round(unit, digits, MidpointRounding.ToEven).ToString();
                if (i == 0)
                {
                    label = units;
                }
                FormattedText ft = new FormattedText(label,
                                                     CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
                                                     typeface, 10, Brushes.Black);
                drawingContext.DrawText(ft, new Point(x - (ft.Width / 2), maxy + 10));
                unit += unitStep;
            }
        }