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,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;