Exemplo n.º 1
0
        public void AddPoint(string str, long currentTime, List <DataSet> setsAdded)
        {
            double value           = Helpers.StringToDouble(str);
            bool   isNanOrInfinity = double.IsNaN(value) || double.IsInfinity(value);
            double yValue          = isNanOrInfinity ? NegativeValue : value * MultiplyingFactor;

            #region cpu

            var matchDelegate = new Func <string, bool>(s => Helpers.CpuRegex.IsMatch(s) &&
                                                        !Helpers.CpuStateRegex.IsMatch(s));

            if (matchDelegate(TypeString))
            {
                DataSet other = setsAdded.FirstOrDefault(s => s.TypeString == "avg_cpu");
                if (other == null)
                {
                    other = Create(Palette.GetUuid("avg_cpu", XenObject), XenObject, true, "avg_cpu");
                    setsAdded.Add(other);
                }

                DataPoint pt = other.GetPointAt(currentTime);
                if (pt == null)
                {
                    pt = new DataPoint(currentTime, 0);
                    other.AddPoint(pt);
                }

                if (isNanOrInfinity || pt.Y < 0)
                {
                    pt.Y = NegativeValue;
                }
                else
                {
                    double cpu_vals_added = 0d;

                    foreach (DataSet s in setsAdded)
                    {
                        if (matchDelegate(s.TypeString) && s.GetPointAt(currentTime) != null && s != this)
                        {
                            cpu_vals_added++;
                        }
                    }

                    pt.Y = (((pt.Y * cpu_vals_added) + (value * 100d)) / (cpu_vals_added + 1d)); // update average in the usual way
                }
            }

            #endregion

            #region memory

            if (TypeString == "memory_total_kib")
            {
                DataSet other = setsAdded.FirstOrDefault(s => s.TypeString == "memory_free_kib");
                if (other != null && other.Points.Count - 1 == Points.Count)
                {
                    yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0
                                 ? NegativeValue
                                 : (value * MultiplyingFactor) - other.Points[other.Points.Count - 1].Y;
                    other.Points[other.Points.Count - 1].Y = yValue;
                }
            }
            else if (TypeString == "memory_free_kib")
            {
                DataSet other = setsAdded.FirstOrDefault(s => s.TypeString == "memory_total_kib");
                if (other != null && other.Points.Count - 1 == Points.Count)
                {
                    yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0
                                 ? NegativeValue
                                 : other.Points[other.Points.Count - 1].Y - (value * MultiplyingFactor);
                }
            }
            else if (TypeString == "memory")
            {
                DataSet other = setsAdded.FirstOrDefault(s => s.TypeString == "memory_internal_free");
                if (other != null && other.Points.Count - 1 == Points.Count)
                {
                    yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0
                                 ? NegativeValue
                                 : (value * MultiplyingFactor) - other.Points[other.Points.Count - 1].Y;
                    other.Points[other.Points.Count - 1].Y = yValue;
                }
            }
            else if (TypeString == "memory_internal_free")
            {
                DataSet other = setsAdded.FirstOrDefault(s => s.TypeString == "memory");
                if (other != null && other.Points.Count - 1 == Points.Count)
                {
                    yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0
                                 ? NegativeValue
                                 : other.Points[other.Points.Count - 1].Y - (value * MultiplyingFactor);
                }
            }

            #endregion

            AddPoint(new DataPoint(currentTime, yValue));
        }
Exemplo n.º 2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (GraphRectangle().Contains(e.Location))
            {
                Cursor = Cursors.SizeAll;
            }
            else
            {
                Cursor = Cursors.Default;
            }

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            if (e.Button == MouseButtons.None)
            {
                if (DataPlotNav == null || DataKey == null || ArchiveMaintainer == null)
                {
                    return;
                }
                if (SelectedPoint != null)
                {
                    SelectedPoint.Show = false;
                }
                if (DataKey.SelectedSet == null || !DataKey.SelectedSet.Sets.ContainsKey(DataPlotNav.GetCurrentLeftArchiveInterval()))
                {
                    return;
                }
                DataPoint found = DataKey.SelectedSet.Sets[DataPlotNav.GetCurrentLeftArchiveInterval()].OnMouseMove(new MouseActionArgs(e.Location, GraphRectangle(), DataPlotNav != null ? DataPlotNav.XRange : DataTimeRange.MaxRange, SelectedYRange));
                if (found == null)
                {
                    return;
                }
                found.Show = true;
                if (found != SelectedPoint)
                {
                    SelectedPoint = found;
                    RefreshBuffer();
                }
            }
            else if (e.Button == MouseButtons.Left && ScrollStart.X != Int16.MinValue && ScrollStart.Y != Int16.MinValue)
            {
                HaveMoved = true;
                long vdelta = DataTimeRange.DeTranslateDelta(e.Location.X - ScrollStart.X, DataPlotNav.GraphWidth.Ticks, GraphRectangle().Width);

                if (DataPlotNav.GraphOffset.Ticks + vdelta <= 0)
                {
                    if (DataPlotNav.GraphOffset == TimeSpan.Zero && DataPlotNav.ScrollViewOffset == TimeSpan.Zero)
                    {
                        return;
                    }
                    DataPlotNav.ScrollViewOffset = TimeSpan.Zero;
                    DataPlotNav.GraphOffset      = TimeSpan.Zero;
                }
                else
                {
                    if (DataPlotNav.ScrollViewOffset.Ticks + DataPlotNav.ScrollViewWidth.Ticks < DataPlotNav.GraphOffset.Ticks + DataPlotNav.GraphWidth.Ticks + vdelta)
                    {
                        DataPlotNav.ScrollViewOffset = TimeSpan.FromTicks(DataPlotNav.GraphOffset.Ticks + DataPlotNav.GraphWidth.Ticks + vdelta - DataPlotNav.ScrollViewWidth.Ticks);
                    }
                    else if (DataPlotNav.ScrollViewOffset.Ticks > DataPlotNav.GraphOffset.Ticks + vdelta)
                    {
                        DataPlotNav.ScrollViewOffset = TimeSpan.FromTicks(DataPlotNav.GraphOffset.Ticks + vdelta);
                    }

                    DataPlotNav.GraphOffset += TimeSpan.FromTicks(vdelta);
                }

                ScrollStart = e.Location;
                DataPlotNav.RefreshXRange(false);
            }
        }