Performance and workflow improvement:

- no need to register the XenObjects events with the ArchiveMaintainer since
what the handler does is not specific to this class; this can be done on the
Performance page where the events are also registered.
- set directly the ArchiveMaintainer's XenObject to the new value without
setting it intermediately to null as this causes a full data download event
if the object has not changed.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-01-31 14:51:40 +00:00 committed by Mihaela Stoica
parent 267035c2c6
commit b4956da8f1
2 changed files with 55 additions and 99 deletions

View File

@ -30,9 +30,7 @@
*/
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Net;
@ -130,40 +128,15 @@ namespace XenAdmin.Controls.CustomDataGraph
/// </summary>
public IXenObject XenObject
{
get { return _xenObject; }
private get { return _xenObject; }
set
{
Program.AssertOnEventThread();
DeregEvents();
string oldref = XenObject == null ? "" : XenObject.opaque_ref;
string oldref = _xenObject == null ? "" : _xenObject.opaque_ref;
_xenObject = value;
string newref = XenObject == null ? "" : XenObject.opaque_ref;
string newref = _xenObject == null ? "" : _xenObject.opaque_ref;
FirstTime = FirstTime || newref != oldref;
if (FirstTime)
{
// Restrict to at most 24 hours data if necessary
if (Helpers.FeatureForbidden(XenObject, XenAPI.Host.RestrictPerformanceGraphs))
{
Archives[ArchiveInterval.OneHour].MaxPoints = 24;
Archives[ArchiveInterval.OneDay].MaxPoints = 0;
}
else
{
Archives[ArchiveInterval.OneHour].MaxPoints = HoursInOneWeek;
Archives[ArchiveInterval.OneDay].MaxPoints = DaysInOneYear;
}
foreach (DataArchive a in Archives.Values)
a.Sets.Clear();
LoadingInitialData = true;
OnArchivesUpdated();
}
RegEvents();
}
}
@ -180,7 +153,7 @@ namespace XenAdmin.Controls.CustomDataGraph
{
get
{
IXenObject m = _xenObject;
IXenObject m = XenObject;
return m == null ? TimeSpan.Zero : m.Connection.ServerTimeOffset;
}
}
@ -193,26 +166,39 @@ namespace XenAdmin.Controls.CustomDataGraph
Archives.Add(ArchiveInterval.OneDay, new DataArchive(DaysInOneYear));
Archives.Add(ArchiveInterval.None, new DataArchive(0));
UpdaterThread = new Thread(new ThreadStart(Update));
UpdaterThread.Name = "Archive Maintainer";
UpdaterThread.IsBackground = true;
UpdaterThread = new Thread(Update) {Name = "Archive Maintainer", IsBackground = true};
}
/// <summary>
/// Call me, async update graph data set
/// UpdaterThread Thread
/// </summary>
public void Update()
private void Update()
{
while (RunThread)
{
IXenObject xenObject = XenObject;
Host Host = GetHost(xenObject);
DateTime ServerWas = ServerNow(); // get time before updating so we dont miss any 5 second updates if getting the past data
DateTime ServerWas = ServerNow(); // get time before updating so we don't miss any 5 second updates if getting the past data
if (FirstTime)
{
// Restrict to at most 24 hours data if necessary
if (Helpers.FeatureForbidden(_xenObject, XenAPI.Host.RestrictPerformanceGraphs))
{
Archives[ArchiveInterval.OneHour].MaxPoints = 24;
Archives[ArchiveInterval.OneDay].MaxPoints = 0;
}
else
{
Archives[ArchiveInterval.OneHour].MaxPoints = HoursInOneWeek;
Archives[ArchiveInterval.OneDay].MaxPoints = DaysInOneYear;
}
foreach (DataArchive a in Archives.Values)
a.Sets.Clear();
LoadingInitialData = true;
OnArchivesUpdated();
Get(ArchiveInterval.None, RrdsUri, RRD_Full_InspectCurrentNode, Host, xenObject);
@ -635,59 +621,5 @@ namespace XenAdmin.Controls.CustomDataGraph
if (ArchivesUpdated != null)
ArchivesUpdated();
}
/// <summary>
/// Gui Thread
/// </summary>
internal void DeregEvents()
{
if (XenObject == null)
return;
Pool pool = Helpers.GetPoolOfOne(XenObject.Connection);
if (pool != null)
pool.PropertyChanged -= pool_PropertyChanged;
}
/// <summary>
/// Gui Thread
/// </summary>
private void RegEvents()
{
if (XenObject == null)
return;
Pool pool = Helpers.GetPoolOfOne(XenObject.Connection);
if (pool != null)
pool.PropertyChanged += pool_PropertyChanged;
}
/// <summary>
/// Random Thread
/// </summary>
void pool_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "gui_config")
{
Dictionary<string, string> gui_config = Helpers.GetGuiConfig((IXenObject)sender);
string uuid = Helpers.GetUuid(XenObject);
foreach (string key in gui_config.Keys)
{
if (!Palette.OtherConfigUUIDRegex.IsMatch(key) || !key.Contains(uuid))
continue;
string value = gui_config[key];
int argb;
if (!Int32.TryParse(value, out argb))
continue;
string[] strs = key.Split('.');
// just set the color, we dont care what it is
Palette.SetCustomColor(Palette.GetUuid(strs[strs.Length - 1], XenObject), Color.FromArgb(argb));
}
OnArchivesUpdated();
}
}
}
}

View File

@ -164,27 +164,28 @@ namespace XenAdmin.TabPages
public IXenObject XenObject
{
get
private get
{
return _xenObject;
}
set
{
ArchiveMaintainer.Pause();
ArchiveMaintainer.XenObject = null;
DataEventList.Clear();
DeregEvents();
_xenObject = value;
RegEvents();
ArchiveMaintainer.XenObject = value;
if (_xenObject != null)
{
GraphList.LoadGraphs(XenObject);
LoadEvents();
ArchiveMaintainer.XenObject = value;
ArchiveMaintainer.Start();
}
RefreshAll();
}
}
@ -259,7 +260,32 @@ namespace XenAdmin.TabPages
private void pool_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "gui_config")
Program.Invoke(this, () => GraphList.LoadGraphs(XenObject));
{
Dictionary<string, string> gui_config = Helpers.GetGuiConfig((IXenObject)sender);
string uuid = Helpers.GetUuid(XenObject);
foreach (string key in gui_config.Keys)
{
if (!Palette.OtherConfigUUIDRegex.IsMatch(key) || !key.Contains(uuid))
continue;
string value = gui_config[key];
int argb;
if (!Int32.TryParse(value, out argb))
continue;
string[] strs = key.Split('.');
// just set the color, we dont care what it is
Palette.SetCustomColor(Palette.GetUuid(strs[strs.Length - 1], XenObject), Color.FromArgb(argb));
}
Program.Invoke(this, () =>
{
GraphList.LoadGraphs(XenObject);
RefreshAll();
});
}
}
private void DeregEvents()
@ -278,13 +304,11 @@ namespace XenAdmin.TabPages
public override void PageHidden()
{
DeregEvents();
if (ArchiveMaintainer != null && XenObject != null)
{
if (ArchiveMaintainer != null)
ArchiveMaintainer.Pause();
ArchiveMaintainer.DeregEvents();
}
}
private void ArchiveMaintainer_ArchivesUpdated()
{
Program.Invoke(this, RefreshAll);