/// <summary>
        /// Add a new performance event
        /// </summary>
        /// <param name="name">The name of the performance event.</param>
        /// <param name="start">Specifies whether or not to start the event immediately.</param>
        /// <returns>The newly added event.</returns>
        public PerformanceEvent AddEvent(string name, bool start)
        {
            if(name == null) {
                throw new ArgumentNullException("name");
            }

            PerformanceEvent e = new PerformanceEvent();
            e.Name = name;
            e.Manager = this;
            _events.Add(name, e);

            if(start) {
                e.Start();
            }

            return e;
        }
示例#2
0
        private void UpdateEventInfoPanel(PerformanceEvent perfEvent)
        {
            if(perfEvent == null) {
                return;
            }

            NameLabel.Text = (perfEvent.Name == null || perfEvent.Name == string.Empty) ?
                             "Untitled" : perfEvent.Name;
            IterationLabel.Text = perfEvent.IterationCount.ToString();

            // average duration
            TimeSpan? avgDuration = perfEvent.AverageDuration;

            if(avgDuration.HasValue) {
                AvgDurationLabel.Text = FormatTimeSpan(avgDuration.Value);
            }
            else {
                AvgDurationLabel.Text = "None";
            }

            // maximum duration
            if(perfEvent.IterationCount > 0) {
                TimeSpan maxDuration = TimeSpan.MinValue;

                for(int i = 0; i < perfEvent.IterationCount; i++) {
                    if(perfEvent.Iterations[i].Duration > maxDuration) {
                        maxDuration = perfEvent.Iterations[i].Duration;
                    }
                }

                MaxDurationLabel.Text = FormatTimeSpan(maxDuration);
            }
            else {
                MaxDurationLabel.Text = "None";
            }
        }
示例#3
0
        private bool IsMinDuration(int index, PerformanceEvent perfEvent)
        {
            if(perfEvent == null || index < 0) {
                return false;
            }

            for(int i = 0; i < eventGraph.Count; i++) {
                if(eventGraph[i].IterationCount > index) {
                    if(eventGraph[i].Iterations[index].Duration < perfEvent.Iterations[index].Duration) {
                        return false;
                    }
                }
            }

            return true;
        }
示例#4
0
        private Color GetDrawingColor(PerformanceEvent perfEvent)
        {
            Color drawingColor;

            if(eventGraphColors.ContainsKey(perfEvent)) {
                drawingColor = eventGraphColors[perfEvent];
            }
            else {
                // set default
                drawingColor = DefaultGraphColor;
            }
            return drawingColor;
        }
示例#5
0
        private int DrawEventInfo(Graphics g, int maxHeight, int lastInfoDrawn, PerformanceEvent perfEvent, 
            int currentX, int currentY, int iterationIndex)
        {
            if(iterationIndex > lastInfoDrawn) {
                string info = iterationIndex.ToString();
                SizeF infoSize = g.MeasureString(info, this.Font);
                float infoX = currentX - infoSize.Width / 2;
                float infoY = maxHeight + InfoZoneHeight / 2 - infoSize.Height / 2 + 2;

                // draw string
                g.DrawString(info, this.Font, Brushes.Black, infoX, infoY);

                // prevent redrawing the same info again4
                lastInfoDrawn = iterationIndex;
            }

            if(IsMinDuration(iterationIndex, perfEvent)) {
                Pen p = new Pen(Brushes.LightGray);
                p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                g.DrawLine(p, currentX, currentY, currentX, maxHeight);
            }
            return lastInfoDrawn;
        }
示例#6
0
        private Color DrawAverageBar(Graphics g, int bulletSize, int maxHeight, 
            PerformanceEvent perfEvent, Color drawingColor)
        {
            // disable antialiasing while drawing the average line
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

            Pen linePen = new Pen(drawingColor, 1.0f);
            int lineY = maxHeight - (int)Math.Ceiling((perfEvent.AverageDuration.Value.TotalMilliseconds / graphMaxDuration) *
                       (double)(maxHeight - bulletSize / 2));

            linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
            g.DrawLine(linePen, 0, lineY, GraphHost.Width, lineY);

            // reenable antialiasing
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            return drawingColor;
        }