]> O.S.I.I.S - jp/crow.git/commitdiff
new PerformanceMeasure class
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 4 Jan 2017 12:42:52 +0000 (13:42 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 4 Jan 2017 12:45:07 +0000 (13:45 +0100)
Crow.csproj
Tests/BasicTests.cs
Tests/Interfaces/Divers/perfMeasures.crow [new file with mode: 0755]
Tests/Interfaces/perfMsr.crow [new file with mode: 0755]
Tests/OpenTKGameWindow.cs
Tests/Tests.csproj
src/Interface.cs
src/PerformanceMeasure.cs [new file with mode: 0644]

index 9d6743741db152cf3d1d73ee34c1611c1f89b647..a2a99eb280729248f86fa6ae6f9911080079af1e 100644 (file)
     <Compile Include="src\GraphicObjects\HueSelector.cs" />
     <Compile Include="src\GraphicObjects\SaturationValueSelector.cs" />
     <Compile Include="src\IML\EventBinding.cs" />
+    <Compile Include="src\PerformanceMeasure.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
index 0533729dff8847529de6be145d1bae5dff191bec..271a3499ea4e447c2fbc3a0d17eea9dd7f155646 100644 (file)
@@ -129,10 +129,6 @@ namespace Tests
                        //testFiles = new string [] { @"Interfaces/Unsorted/testFileDialog.crow" };
                        //testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
                        testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
-                       //testFiles = new string [] { @"Interfaces/TemplatedContainer/test_Listbox.crow" };
-                       //testFiles = new string [] { @"Interfaces/TemplatedControl/testItemTemplateTag.crow" };
-                       //testFiles = new string [] { @"Interfaces/Divers/test2WayBinding.crow" };
-                       //testFiles = new string [] { @"Interfaces/Divers/testPropLess.crow" };
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
@@ -169,6 +165,10 @@ namespace Tests
                                GraphicObject w = CrowInterface.LoadInterface ("Interfaces/Divers/0.crow");
                                w.DataSource = this;
                                return;
+                       }else if (e.Key == OpenTK.Input.Key.F7) {
+                               GraphicObject w = CrowInterface.LoadInterface ("Interfaces/Divers/perfMeasures.crow");
+                               w.DataSource = this;
+                               return;
                        } else if (e.Key == OpenTK.Input.Key.F2)
                                idx--;
                        else if (e.Key == OpenTK.Input.Key.F3)
diff --git a/Tests/Interfaces/Divers/perfMeasures.crow b/Tests/Interfaces/Divers/perfMeasures.crow
new file mode 100755 (executable)
index 0000000..3a0cb57
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<Window Focusable="true" Title="Measures" Width="30%" Height="Fit" MinimumSize="100,100">
+       <ListBox Data="{PerfMeasures}"
+               ItemTemplate="#Tests.Interfaces.perfMsr.crow"/>
+</Window>
diff --git a/Tests/Interfaces/perfMsr.crow b/Tests/Interfaces/perfMsr.crow
new file mode 100755 (executable)
index 0000000..f9fa38a
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<GroupBox CornerRadius="0" Margin="0" Caption="{Name}" Height="Fit" Width="160">
+       <VerticalStack>
+               <HorizontalStack>
+                       <Label Text="Current:" Style="FpsLabel"/>
+                       <Label Text="{current}" Style="FpsDisp"/>
+               </HorizontalStack>
+               <HorizontalStack>
+                       <Label Text="Minimum:" Style="FpsLabel"/>
+                       <Label Text="{minimum}" Style="FpsDisp"/>
+               </HorizontalStack>
+               <HorizontalStack>
+                       <Label Text="Mean:" Style="FpsLabel"/>
+                       <Label Text="{mean}" Style="FpsDisp"/>
+               </HorizontalStack>
+               <HorizontalStack>
+                       <Label Text="Maximum:" Style="FpsLabel"/>
+                       <Label Text="{maximum}" Style="FpsDisp"/>
+               </HorizontalStack>
+<!--           <HorizontalStack>
+                       <Label Text="Total:" Style="FpsLabel"/>
+                       <Label Text="{total}" Style="FpsDisp"/>
+               </HorizontalStack>
+               <HorizontalStack>
+                       <Label Text="Cpt:" Style="FpsLabel"/>
+                       <Label Text="{cptMeasures}" Style="FpsDisp"/>
+               </HorizontalStack>-->
+               <Button Caption="Reset" MouseClick="onResetClick"/>
+       </VerticalStack>
+</GroupBox>
index f5e69671571e7c1bd73d0d19bacf84f747c9b98f..f4d13874b5b4b4e0b09c504f8f6cb32bd1360309 100644 (file)
@@ -22,6 +22,7 @@ using System;
 using System.Threading;
 using OpenTK;
 using OpenTK.Graphics.OpenGL;
+using System.Collections.Generic;
 
 namespace Crow
 {
@@ -60,14 +61,8 @@ namespace Crow
                                if (frameCpt % 3 == 0)
                                        ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps));
                                #if MEASURE_TIME
-                               ValueChanged.Raise (this, new ValueChangeEventArgs ("update",
-                                       this.CrowInterface.updateTime.ElapsedTicks.ToString () + " ticks"));
-                               ValueChanged.Raise (this, new ValueChangeEventArgs ("layouting",
-                                       this.CrowInterface.layoutTime.ElapsedTicks.ToString () + " ticks"));
-                               ValueChanged.Raise (this, new ValueChangeEventArgs ("drawing",
-                                       this.CrowInterface.drawingTime.ElapsedTicks.ToString () + " ticks"));
-                               ValueChanged.Raise (this, new ValueChangeEventArgs ("clipping",
-                                       this.CrowInterface.clippingTime.ElapsedTicks.ToString () + " ticks"));
+                               foreach (PerformanceMeasure m in PerfMeasures)
+                                       m.NotifyChanges();
                                #endif
                        }
                }
@@ -101,6 +96,17 @@ namespace Crow
                {
                        CrowInterface = new Interface ();
 
+                       #if MEASURE_TIME
+                       PerfMeasures = new List<PerformanceMeasure> (
+                               new PerformanceMeasure[] {
+                                       this.CrowInterface.updateMeasure,
+                                       this.CrowInterface.layoutingMeasure,
+                                       this.CrowInterface.clippingMeasure,
+                                       this.CrowInterface.drawingMeasure
+                               }
+                       );
+                       #endif
+
                        Thread t = new Thread (interfaceThread);
                        t.IsBackground = true;
                        t.Start ();
@@ -108,6 +114,10 @@ namespace Crow
 
                #endregion
 
+               #if MEASURE_TIME
+               public List<PerformanceMeasure> PerfMeasures;
+               #endif
+
                void interfaceThread()
                {
                        CrowInterface.Quit += Quit;
index b6b81de38968cef03e41425c2fb7e2d88b0bd1f5..a95a034a60c92b8d77cc7ef2be9f1cb1af679bb6 100644 (file)
     <None Include="Interfaces\Unsorted\testFileDialog.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\Divers\perfMeasures.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
     <EmbeddedResource Include="test.style" />
     <EmbeddedResource Include="Interfaces\treeList.crow" />
     <EmbeddedResource Include="Interfaces\CheckBox2.imlt" />
+    <EmbeddedResource Include="Interfaces\perfMsr.crow" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Crow.csproj">
index ddd5bfcfc25e0d9ddd831f03c003332100d4aecb..cb541fb05bf13cf9b9c219e91df37c9e00b75d4e 100644 (file)
@@ -234,10 +234,10 @@ namespace Crow
                #endregion
 
                #if MEASURE_TIME
-               public Stopwatch clippingTime = new Stopwatch ();
-               public Stopwatch layoutTime = new Stopwatch ();
-               public Stopwatch updateTime = new Stopwatch ();
-               public Stopwatch drawingTime = new Stopwatch ();
+               public PerformanceMeasure clippingMeasure = new PerformanceMeasure("Clipping", 100);
+               public PerformanceMeasure layoutingMeasure = new PerformanceMeasure("Layouting", 100);
+               public PerformanceMeasure updateMeasure = new PerformanceMeasure("Update", 100);
+               public PerformanceMeasure drawingMeasure = new PerformanceMeasure("Drawing", 100);
                #endif
 
                public List<GraphicObject> GraphicTree = new List<GraphicObject>();
@@ -345,7 +345,7 @@ namespace Crow
                                return;
 
                        #if MEASURE_TIME
-                       updateTime.Restart();
+                       updateMeasure.StartCycle();
                        #endif
 
                        processLayouting ();
@@ -364,14 +364,14 @@ namespace Crow
                        processDrawing ();
 
                        #if MEASURE_TIME
-                       updateTime.Stop ();
+                       updateMeasure.StopCycle();
                        #endif
 
                        Monitor.Exit (UpdateMutex);
                }
                void processLayouting(){
                        #if MEASURE_TIME
-                       layoutTime.Restart();
+                       layoutingMeasure.StartCycle();
                        #endif
                        DiscardQueue = new Queue<LayoutingQueueItem> ();
                        lock (LayoutMutex) {
@@ -390,12 +390,12 @@ namespace Crow
                        DiscardQueue = null;
 
                        #if MEASURE_TIME
-                       layoutTime.Stop ();
+                       layoutingMeasure.StopCycle();
                        #endif
                }
                void clippingRegistration(){
                        #if MEASURE_TIME
-                       clippingTime.Restart ();
+                       clippingMeasure.StartCycle();
                        #endif
                        GraphicObject g = null;
                        while (DrawingQueue.Count > 0) {
@@ -407,12 +407,12 @@ namespace Crow
                        }
 
                        #if MEASURE_TIME
-                       clippingTime.Stop ();
+                       clippingMeasure.StopCycle();
                        #endif
                }
                void processDrawing(){
                        #if MEASURE_TIME
-                       drawingTime.Restart();
+                       drawingMeasure.StartCycle();
                        #endif
                        using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
                                using (ctx = new Context (surf)){
@@ -466,7 +466,7 @@ namespace Crow
                                }
                        }
                        #if MEASURE_TIME
-                       drawingTime.Stop ();
+                       drawingMeasure.StopCycle();
                        #endif
                }
 
diff --git a/src/PerformanceMeasure.cs b/src/PerformanceMeasure.cs
new file mode 100644 (file)
index 0000000..8fc0e53
--- /dev/null
@@ -0,0 +1,86 @@
+//
+//  PerformanceMeasure.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2017 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Diagnostics;
+
+namespace Crow
+{
+       public class PerformanceMeasure : IValueChange {
+               #region IValueChange implementation
+               public event EventHandler<ValueChangeEventArgs> ValueChanged;
+               public virtual void NotifyValueChanged(string MemberName, object _value)
+               {
+                       if (ValueChanged != null)                               
+                               ValueChanged.Invoke(this, new ValueChangeEventArgs(MemberName, _value));
+               }
+               #endregion
+
+               public Stopwatch timer = new Stopwatch ();
+               public string Name;
+               public long current, minimum, maximum, total, cptMeasures;
+               public long cancelLimit;
+
+               public PerformanceMeasure(string name = "unamed", long _cancelLimit = 0){
+                       Name = name;
+                       cancelLimit = _cancelLimit;
+                       ResetStats ();
+               }
+
+               public void StartCycle(){
+                       timer.Restart();
+               }
+               public void StopCycle(){
+                       timer.Stop();
+                       computeStats ();
+               }
+               public void NotifyChanges(){
+                       if (cptMeasures == 0)
+                               return;
+                       NotifyValueChanged("minimum", minimum);
+                       NotifyValueChanged("maximum", maximum);
+                       NotifyValueChanged("current", current);
+                       //                      NotifyValueChanged("total", total);
+                       //                      NotifyValueChanged("cptMeasures", cptMeasures);
+                       NotifyValueChanged("mean", total / cptMeasures);
+               }
+
+               void computeStats(){                    
+                       current = timer.ElapsedTicks;
+                       if (current < cancelLimit)
+                               return;
+                       cptMeasures++;
+                       total += timer.ElapsedTicks;
+                       if (timer.ElapsedTicks < minimum)
+                               minimum = timer.ElapsedTicks;
+                       if (timer.ElapsedTicks > maximum)
+                               maximum = timer.ElapsedTicks;                   
+               }
+               void ResetStats(){
+                       Debug.WriteLine("reset measure cpt:{0}",cptMeasures);
+                       cptMeasures = total = current = maximum = 0;
+                       minimum = long.MaxValue;
+               }
+               void onResetClick(object sender, MouseButtonEventArgs e){
+                       ResetStats();
+               }
+       }
+}
+