Skip to content

Commit

Permalink
Parse unit "percent" (used by pvsaccelerator_space_utilization). Mino…
Browse files Browse the repository at this point in the history
…r tidy.

Signed-off-by: Konstantina Chremmou <[email protected]>
  • Loading branch information
kc284 committed Sep 7, 2023
1 parent bba9f43 commit 982e4e7
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions XenAdmin/Controls/CustomDataGraph/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DataSet : IComparable<DataSet>
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

private const int NegativeValue = -1;
private const int NEGATIVE_VALUE = -1;

/// <summary>
/// Things can only be added to the beginning or end of this list; it should
Expand All @@ -50,12 +50,12 @@ public class DataSet : IComparable<DataSet>
public List<DataPoint> Points = new List<DataPoint>();
public bool Selected;
public List<DataPoint> CurrentlyDisplayed = new List<DataPoint>();
public IXenObject XenObject;
public readonly IXenObject XenObject;
public readonly string Id = "";
public string DataSourceName;
public readonly string DataSourceName;
public string FriendlyName { get; }
private int MultiplyingFactor = 1;
public DataRange CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto);
private readonly int _multiplyingFactor = 1;
public readonly DataRange CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto);
public bool Hide { get; }

public DataSet(IXenObject xo, bool hide, string datasourceName, List<Data_source> datasources)
Expand Down Expand Up @@ -87,10 +87,13 @@ public DataSet(IXenObject xo, bool hide, string datasourceName, List<Data_source
case "tasks":
case "file descriptors":
break;
case "percent":
CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto);
break;
case "(fraction)":
//CP-34000: use Auto instead of Fixed scale
CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto);
MultiplyingFactor = 100;
_multiplyingFactor = 100;
break;
case "MHz":
CustomYRange = new DataRange(1, 0, 1, Unit.MegaHertz, RangeScaleMode.Auto);
Expand All @@ -108,28 +111,28 @@ public DataSet(IXenObject xo, bool hide, string datasourceName, List<Data_source
break;
case "s":
CustomYRange = new DataRange(1, 0, 1, Unit.NanoSeconds, RangeScaleMode.Auto);
MultiplyingFactor = (int)Util.DEC_GIGA;
_multiplyingFactor = (int)Util.DEC_GIGA;
break;
case "ms":
CustomYRange = new DataRange(1, 0, 1, Unit.NanoSeconds, RangeScaleMode.Auto);
MultiplyingFactor = (int)Util.DEC_MEGA;
_multiplyingFactor = (int)Util.DEC_MEGA;
break;
case "μs":
CustomYRange = new DataRange(1, 0, 1, Unit.NanoSeconds, RangeScaleMode.Auto);
MultiplyingFactor = (int)Util.DEC_KILO;
_multiplyingFactor = (int)Util.DEC_KILO;
break;
case "B":
CustomYRange = new DataRange(1, 0, 1, Unit.Bytes, RangeScaleMode.Auto);
break;
case "KiB":
CustomYRange = new DataRange(1, 0, 1, Unit.Bytes, RangeScaleMode.Auto);
MultiplyingFactor = (int)Util.BINARY_KILO;
_multiplyingFactor = (int)Util.BINARY_KILO;
break;
case "B/s":
CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto);
break;
case "MiB/s":
MultiplyingFactor = (int)Util.BINARY_MEGA;
_multiplyingFactor = (int)Util.BINARY_MEGA;
CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto);
break;
case "mW":
Expand Down Expand Up @@ -346,7 +349,7 @@ public void AddPoint(string str, long currentTime, List<DataSet> setsAdded, List
{
double value = Helpers.StringToDouble(str);
bool isNanOrInfinity = double.IsNaN(value) || double.IsInfinity(value);
double yValue = isNanOrInfinity ? NegativeValue : value * MultiplyingFactor;
double yValue = isNanOrInfinity ? NEGATIVE_VALUE : value * _multiplyingFactor;

#region cpu

Expand All @@ -370,7 +373,7 @@ public void AddPoint(string str, long currentTime, List<DataSet> setsAdded, List
}

if (isNanOrInfinity || pt.Y < 0)
pt.Y = NegativeValue;
pt.Y = NEGATIVE_VALUE;
else
{
double cpu_vals_added = 0d;
Expand All @@ -395,8 +398,8 @@ public void AddPoint(string str, long currentTime, List<DataSet> setsAdded, List
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;
? NEGATIVE_VALUE
: value * _multiplyingFactor - other.Points[other.Points.Count - 1].Y;
other.Points[other.Points.Count - 1].Y = yValue;
}
}
Expand All @@ -406,8 +409,8 @@ public void AddPoint(string str, long currentTime, List<DataSet> setsAdded, List
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);
? NEGATIVE_VALUE
: other.Points[other.Points.Count - 1].Y - value * _multiplyingFactor;
}
}
else if (DataSourceName == "memory")
Expand All @@ -416,8 +419,8 @@ public void AddPoint(string str, long currentTime, List<DataSet> setsAdded, List
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;
? NEGATIVE_VALUE
: value * _multiplyingFactor - other.Points[other.Points.Count - 1].Y;
other.Points[other.Points.Count - 1].Y = yValue;
}
}
Expand All @@ -427,8 +430,8 @@ public void AddPoint(string str, long currentTime, List<DataSet> setsAdded, List
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);
? NEGATIVE_VALUE
: other.Points[other.Points.Count - 1].Y - value * _multiplyingFactor;
}
}

Expand Down

0 comments on commit 982e4e7

Please sign in to comment.