From a07a15a7c74f4b82a66b2b2a2a70151696c57bfe Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 11 Dec 2015 11:56:51 -0800 Subject: [PATCH] Adding in a new performance test structure. --- ApplicationView/MainApplicationWidget.cs | 69 +-------------- MatterControl.csproj | 1 + Utilities/PerformanceTests.cs | 105 +++++++++++++++++++++++ 3 files changed, 108 insertions(+), 67 deletions(-) create mode 100644 Utilities/PerformanceTests.cs diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 5f4af6671..6e7119794 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -67,56 +67,17 @@ namespace MatterHackers.MatterControl private bool topIsHidden = false; - #region automation test -#if true - StatisticsTracker testTracker = new StatisticsTracker("ApplicationViewFrameRate"); - bool item = true; bool firstDraw = true; - AutomationRunner clickPreview; - Stopwatch timeSinceLastClick = Stopwatch.StartNew(); - Stopwatch totalDrawTime = Stopwatch.StartNew(); - int drawCount = 0; public override void OnDraw(Graphics2D graphics2D) { if (firstDraw) { - clickPreview = new AutomationRunner(); - Task.Run(() => - { - while (true) - { - if (clickPreview != null && timeSinceLastClick.Elapsed.TotalSeconds > 5) - { - if (item) - { - clickPreview.ClickByName("Library Tab"); - } - else - { - clickPreview.ClickByName("Controls Tab"); - } - item = !item; - timeSinceLastClick.Restart(); - } - } - }); + PerformanceTests.SwitchBetweenWidgets(this, "Library Tab", "Controls Tab", .1); firstDraw = false; } - totalDrawTime.Restart(); base.OnDraw(graphics2D); - totalDrawTime.Stop(); - if (drawCount++ > 30 && testTracker.Count < 100) - { - testTracker.AddValue(totalDrawTime.ElapsedMilliseconds); - if (testTracker.Count == 100) - { - Trace.WriteLine("StatisticsTrackerReport: " + Newtonsoft.Json.JsonConvert.SerializeObject(testTracker)); - } - } } -#endif - #endregion public override void HideTopContainer() { @@ -238,43 +199,17 @@ namespace MatterHackers.MatterControl { } - #region automation test -#if false - bool item = true; bool firstDraw = true; - AutomationRunner clickPreview; - Stopwatch timeSinceLastClick = Stopwatch.StartNew(); public override void OnDraw(Graphics2D graphics2D) { if (firstDraw) { - clickPreview = new AutomationRunner(); - Task.Run(() => - { - while(true) - { - if (clickPreview != null && timeSinceLastClick.Elapsed.TotalSeconds > 5) - { - if (item) - { - clickPreview.ClickByName("Library Tab"); - } - else - { - clickPreview.ClickByName("History Tab"); - } - item = !item; - timeSinceLastClick.Restart(); - } - } - }); + PerformanceTests.SwitchBetweenWidgets(this, "Library Tab", "History Tab", .1); firstDraw = false; } base.OnDraw(graphics2D); } -#endif -#endregion public override void AddElements() { diff --git a/MatterControl.csproj b/MatterControl.csproj index 682f40afa..ea32e7db9 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -305,6 +305,7 @@ + diff --git a/Utilities/PerformanceTests.cs b/Utilities/PerformanceTests.cs new file mode 100644 index 000000000..8c781af65 --- /dev/null +++ b/Utilities/PerformanceTests.cs @@ -0,0 +1,105 @@ +/* +Copyright (c) 2014, Lars Brubaker +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.GuiAutomation; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading.Tasks; + +namespace MatterHackers.MatterControl +{ + public static class PerformanceTests + { + public static void SwitchBetweenWidgets(GuiWidget systemWindow, string firstWidgetName, string secondWidgetName, double switchTimeSeconds) + { + StatisticsTracker testTracker = new StatisticsTracker("SwitchBetweenTabs"); + bool item = true; + bool done = false; + bool firstDraw = true; + AutomationRunner clickPreview; + Stopwatch timeSinceLastClick = Stopwatch.StartNew(); + Stopwatch totalDrawTime = Stopwatch.StartNew(); + int drawCount = 0; + + DrawEventHandler beforeDraw = (sender, e) => + { + if (firstDraw) + { + clickPreview = new AutomationRunner(); + Task.Run(() => + { + while (!done) + { + if (clickPreview != null && timeSinceLastClick.Elapsed.TotalSeconds > switchTimeSeconds) + { + if (item) + { + clickPreview.ClickByName(firstWidgetName); + } + else + { + clickPreview.ClickByName(secondWidgetName); + } + item = !item; + timeSinceLastClick.Restart(); + } + } + }); + firstDraw = false; + } + + totalDrawTime.Restart(); + }; + + systemWindow.DrawBefore += beforeDraw; + + DrawEventHandler afterDraw = null; + afterDraw = (sender, e) => + { + totalDrawTime.Stop(); + if (drawCount++ > 30 && testTracker.Count < 100) + { + testTracker.AddValue(totalDrawTime.ElapsedMilliseconds); + if (testTracker.Count == 100) + { + Trace.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(testTracker)); + systemWindow.DrawBefore -= beforeDraw; + systemWindow.DrawBefore -= afterDraw; + done = true; + } + } + }; + + systemWindow.DrawAfter += afterDraw; + } + } +} \ No newline at end of file