refactor: Replace HighPerformanceTimer w/ Stopwatch

This is needed to build DataStreamSuite on Linux.

'Stopwatch' is a platform independent timer class included with the
System.Runtime library in modern dotnet. 'HighPerformanceTimer' is a BTS
class that predates Stopwatch, and is NOT platform independent as it
relies on Windows kernel32.dll QueryPerformanceCounter/Frequency fns.
This commit is contained in:
John Colvin committed 2024-06-03 13:46:51 +00:00
1 parent 7ee6933789
commit 9050318ceb
18 files changed
+110 -184

No files matched your search

@@ -8,6 +8,8 @@ using System.Collections;
using mbts;
using mbts.config;
using mbts.spark;
using System.Diagnostics;
using bts;
namespace BCG
{
@@ -167,18 +169,17 @@ namespace BCG
internal class ChangeDelegateWrapper
{
private HighPerformanceTimer myTimer = new HighPerformanceTimer ();
readonly Stopwatch timer = new();
private DataStream.ChangeDelegate myDel;
internal ChangeDelegateWrapper (DataStream.ChangeDelegate del) {myDel = del;}
internal void wrapperFunction (object o)
{
myTimer.start ();
timer.Restart();
myDel (o);
myTimer.stop ();
string minfo = "Type = " + myDel.Method.DeclaringType.FullName + " , method = " + myDel.Method.Name;
// BlueEventLog.logEvent (minfo + " , time = " + myTimer.lastIntervalTime.ToString (), BlueEventLevel.Performance);
timer.Stop();
Log.Gen.diag($"Type: {myDel.Method.DeclaringType.FullName}, Method = {myDel.Method.Name}");
}
}
}
@@ -1,19 +1,10 @@
using System;
using System.IO;
//using BCG.Utilities;
using mbts;
using mbts.spark;
using bts;
using System;
using System.Collections;
using System.IO;
using BCG.Utilities;
using BCG.Utilities.General;
using System.Collections.Generic;
using System.Threading;
using mbts;
using System.Linq;
using bts;
namespace BCG {
// This class is responsible for mantaining the state fo a table. It gets the
// bytes from the pubsubserver via the handle_updates call (called by VSD), deserializes
@@ -21,7 +12,6 @@ namespace BCG {
public class TableAccumulator2 : ITableAccumulator {
private readonly string _tag;
private readonly ISubscriberCore _subscriber_core;
private HighPerformanceTimer _timer = new HighPerformanceTimer();
IStreamMsgDeserilizer _deser = new StreamIODeserializationController();
private BlueTable _table;
private TableUpdateDelegate _on_update_delegate;
@@ -8,10 +8,9 @@ using System.Collections.Generic;
using System.Threading;
using mbts;
using System.Linq;
using System.Diagnostics;
namespace BCG {
using HighPerformanceTimer = mbts.spark.HighPerformanceTimer;
public class ViewStreamDatabase : IWorker, IDisposable {
internal delegate void TagFireDelegate(string tag);
public delegate void DoWorkDelegate();
@@ -30,9 +29,9 @@ namespace BCG {
private bool myIsDisposed = false;
private bool _is_in_do_work = false;
private static object myTimeInterval;
private HighPerformanceTimer _timer = new HighPerformanceTimer();
private readonly double myLogTimeThreshold = 10000;
private readonly double _dowork_threshold = 500;
readonly Stopwatch _timer = new();
readonly TimeSpan myLogTimeThreshold = TimeSpan.FromSeconds(10);
readonly TimeSpan _dowork_threshold = TimeSpan.FromMilliseconds(500);
private Thread myThreadOwner = null; // ViewStreamDatabase takes a thread affinity when created. If called from a different thread it will assert.
private static readonly object myInstanceLockObject = new object();
@@ -123,16 +122,16 @@ namespace BCG {
bts.Log.Gen.warn("Received callback for tag: {tag}");
continue;
}
_timer.start();
_timer.Restart();
if (onTagFireStart != null)
onTagFireStart(tag);
table_accumulator.handle_updates(tag_updates);
if (onTagFireEnd != null)
onTagFireEnd(tag);
_timer.stop();
if (_timer.lastIntervalTime > myLogTimeThreshold) {
bts.Log.Gen.error($"ViewStreamDatabase.doWork tag: {tag} took {_timer.lastIntervalTime} msecs");
_timer.Stop();
if (_timer.Elapsed > myLogTimeThreshold) {
bts.Log.Gen.error($"ViewStreamDatabase.doWork tag: {tag} took {_timer.Elapsed}");
}
}
}
@@ -142,11 +141,12 @@ namespace BCG {
_is_worker_call_in_progress = true;
_pending_worker_ops.Clear();
foreach (IWorker w in _workers) {
_timer.start();
_timer.Restart();
w.doWork();
_timer.stop();
if (_timer.lastIntervalTime > _dowork_threshold)
bts.Log.Gen.warn($"VSD.dowork on worker {w} took {_timer.lastIntervalTime}");
_timer.Stop();
if (_timer.Elapsed > _dowork_threshold) {
bts.Log.Gen.warn($"VSD.dowork on worker {w} took {_timer.Elapsed}");
}
}
_is_worker_call_in_progress = false;