[chronojump] New class ChronoDebug to help timely debug processes



commit fe6532629f353016e76b3723c380ee3f6aa449a4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 8 17:28:29 2021 +0200

    New class ChronoDebug to help timely debug processes

 src/Makefile.am    |  1 +
 src/chronoDebug.cs | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c33e9bb6..ab85275f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -190,6 +190,7 @@ SOURCES = \
        buildInfo.cs\
        chronojump.cs\
        config.cs\
+       chronoDebug.cs\
        encoder.cs\
        encoderCapture.cs\
        encoderCaptureInertialBG.cs\
diff --git a/src/chronoDebug.cs b/src/chronoDebug.cs
new file mode 100644
index 00000000..121c620b
--- /dev/null
+++ b/src/chronoDebug.cs
@@ -0,0 +1,91 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump 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 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump 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, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  Copyright (C) 2021   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.Data;
+using System.Collections.Generic; //List<T>
+using System.Diagnostics;  //Stopwatch
+
+//to debug time needed for some processes
+//Sw: Stopwatch
+public class ChronoDebugAction
+{
+       private string action;
+       private int elapsedMs;
+
+       //constructor
+       public ChronoDebugAction (string action, int elapsedMs)
+       {
+               this.action = action;
+               this.elapsedMs = elapsedMs;
+       }
+
+       public override string ToString()
+       {
+               return string.Format("action: {0}, ms: {1}", action, elapsedMs);
+       }
+}
+
+public class ChronoDebug
+{
+       private string name;
+       private List<ChronoDebugAction> list;
+       private Stopwatch sw;
+
+       public ChronoDebug (string name)
+       {
+               list = new List<ChronoDebugAction>();
+               sw = new Stopwatch();
+       }
+
+       public void Add (string action)
+       {
+               list.Add(new ChronoDebugAction(
+                                       action,
+                                       Convert.ToInt32(sw.Elapsed.TotalMilliseconds)
+                                       ));
+       }
+
+       public void Start ()
+       {
+               sw.Start();
+               Add("Start");
+       }
+
+       public void StopAndPrint ()
+       {
+               Stop();
+               PrintResults();
+       }
+
+       public void Stop ()
+       {
+               sw.Stop();
+               Add("Stop");
+       }
+
+       public void PrintResults()
+       {
+               LogB.Information("ChronoDebug for " + name);
+               foreach(ChronoDebugAction action in list)
+                       LogB.Information(action.ToString());
+       }
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]