diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs index dcc20d6bf..ee8933bcd 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,7 +24,6 @@ namespace mbts.spark { private readonly ITag _in_vs_standard_time_tag; private readonly ITag _out_bb_computed_vol_tag; private readonly ThreadedBlackboard _bb; - private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 100); private readonly string _log_id; @@ -55,18 +55,18 @@ namespace mbts.spark { VolSurfaceNonVolData vs_nonvol_data = _bb.read_state(_in_bb_nonvol_data_tag); VolSurfaceStandardTime vs_standard_time = _bb.read_state(_in_vs_standard_time_tag); if (vs_input != null && vs_nonvol_data != null && vs_standard_time != null) { - _timer.start(); + var timer = Stopwatch.StartNew(); IDictionary aux_data_map = VolSurfaceUtilityFunctions.compute_aux_data(vs_input, vs_nonvol_data.input, vs_nonvol_data.driver_price_map, vs_standard_time); VolSurfaceOutput vs_output = GeneralVolSurfaceCalculator.compute( vs_input, vs_nonvol_data.contracts, aux_data_map); - _timer.stop(); + timer.Stop(); var tag_str = tag == null ? "Null" : tag.ToString(); // bts.Log.Gen.info($"SingleVolSurfaceCommittedOutputRetriever._recompute_and_publish " + // $"vs_id: {_vs_id} time:{_timer.lastIntervalTime} ms tag:{tag_str} " + // $"tid:{_tid()}"); //output: {vs_output.log_string()}*/"); - _logger.log(_log_id, _log_id, _timer.lastIntervalTime); + _logger.log(_log_id, _log_id, timer.Elapsed.TotalMilliseconds); _bb.post(_out_bb_computed_vol_tag, vs_output); } } @@ -75,4 +75,4 @@ namespace mbts.spark { public void Dispose() { _bb.data_callback -= _on_bb_data; } #endregion } -} \ No newline at end of file +} diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs index 0c6b3123c..8a89af63c 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs @@ -11,6 +11,7 @@ using System; using System.Collections; using System.Collections.Generic; + using System.Diagnostics; using System.Linq; using System.Reactive.Linq; using System.Threading; @@ -25,7 +26,6 @@ private readonly ThreadedBlackboard _bb; private readonly ITag _in_bb_committ_tag; private readonly AnalyticsService _analytics_service; - private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private readonly List _disposables = new List(); private IDictionary _snp_shot_map = new Dictionary(); @@ -93,7 +93,7 @@ private void _on_bb_data(object tag, object data) { if (_in_bb_committ_tag.Equals(tag)) { try { - _timer.start(); + var timer = Stopwatch.StartNew(); VolSurfaceInput vs_input = data as VolSurfaceInput; var user_tup = _bb.read_state(SparkTags.CurrentUser); string current_user = user_tup.name; @@ -107,17 +107,17 @@ _sanitize_input(ref vs_input); vs_input = VolSurfaceDataFunctions.unset_driver_overrides(vs_input); VolSurfaceUtilityFunctions.save_volsurface(vs_input, _analytics_service, current_user); - _timer.stop(); + timer.Stop(); Log.Gen.info(String.Format( "SingleVolSurfaceGateway._on_bb_data Time to commit volsurface {0} {1} msecs", - _volsurface_id, _timer.lastIntervalTime)); + _volsurface_id, timer.Elapsed.TotalMilliseconds)); var archived_theos = _get_theos(); if (archived_theos != null) { - _timer.start(); + timer.Restart(); _analytics_service.archive_theos(archived_theos); - _timer.stop(); + timer.Stop(); Log.Gen.info($"SingleVolSurfaceGateway._on_bb_data archiving theos vs_id: {_volsurface_id} size: " + - $"{archived_theos.SecTheo.Count} time: {_timer.lastIntervalTime} msecs"); + $"{archived_theos.SecTheo.Count} time: {timer.Elapsed.TotalMilliseconds} msecs"); } } catch (Exception ex) { Log.Gen.warn(ex.ToString()); diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs index ec6f76a34..6a8fac462 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; + using System.Diagnostics; using System.Linq; using System.Collections; @@ -64,7 +65,6 @@ private readonly ITag _in_bb_ignore_market_implied_vol_source_settings_tag; private CachedExpMD _cached_exp_md = new CachedExpMD(); private readonly ThreadedBlackboard _bb; - private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 50); private TimeSpan _compute_period = TimeSpan.FromMilliseconds(333); private bool _is_dirty = true; @@ -137,7 +137,7 @@ symbol = sel_exp.Item1.symbol, expiration = sel_exp.Item1.expiration }; - _timer.start(); + var timer = Stopwatch.StartNew(); VolSurfaceExpiration md_exp; VolCurveMarketImpliedVolData exp_impl_vol_map = VolSurfaceCoreFunctions.compute_implied_vols( @@ -147,10 +147,11 @@ impliedvol_side, _ignore_market_implied_vol_source_settings(_bb, _vs_id), out md_exp); - _timer.stop(); - _logger.log("SingleVolSurfaceMarketImpliedVolSource", - "SingleVolSurfaceMarketImpliedVolSource", - _timer.lastIntervalTime); + timer.Stop(); + _logger.log( + "SingleVolSurfaceMarketImpliedVolSource", + "SingleVolSurfaceMarketImpliedVolSource", + timer.Elapsed.TotalMilliseconds); if (exp_impl_vol_map is null) { return; } diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs index 5c86e6ae2..509c0f69e 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -32,7 +33,6 @@ namespace mbts.spark { private readonly ITag _in_bb_vs_standard_time_tag; private readonly ITag _in_bb_market_impliedvol_side_tag; private readonly ITag _in_bb_dirty_tag; - private HighPerformanceTimer _timer = new HighPerformanceTimer(); /// data private VolSurfaceOutput _last_output; @@ -83,7 +83,7 @@ namespace mbts.spark { VolSurfaceNonVolData nonvol_data = _bb.read_state(_in_bb_nonvol_data_tag); VolSurfaceStandardTime vs_standard_time = _bb.read_state(_in_bb_vs_standard_time_tag); if (is_dirty && nonvol_data != null) { - _timer.start(); + var timer = Stopwatch.StartNew(); VolSurfaceCalculationRequest curr_req = _bb.read_state(_in_bb_request_tag), effective_req = null; if (is_new_request) @@ -108,9 +108,9 @@ namespace mbts.spark { null, effective_req.cascade_up, effective_req.cascade_down); - _timer.stop(); + timer.Stop(); bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator._recompute_and_publish vs_id: {_vs_id} " + - $"time: {_timer.lastIntervalTime}"); + $"time: {timer.Elapsed.TotalMilliseconds}"); _bb.post(SparkTags.VolSurfaceCalculationResponseTag(_vs_id), new VolSurfaceCalculationResponse(_last_output, effective_req.request_id)); } @@ -127,7 +127,7 @@ namespace mbts.spark { if (is_dirty || nonvol_data == null || vs_standard_time == null || auto_req == null) { return; } - _timer.start(); + var timer = Stopwatch.StartNew(); IDictionary aux_data_map = VolSurfaceUtilityFunctions.compute_aux_data(auto_req.volsurface_input, nonvol_data.input, @@ -142,9 +142,9 @@ namespace mbts.spark { null, auto_req.cascade_up, auto_req.cascade_down); - _timer.stop(); + timer.Stop(); bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator._serve_auto_request vs_id: {_vs_id} " + - $"time: {_timer.lastIntervalTime}"); + $"time: {timer.Elapsed.TotalMilliseconds}"); _bb.post(SparkTags.VolSurfaceAutoCalculationResponseTag(_vs_id), new VolSurfaceCalculationResponse(vs_output, auto_req.request_id)); } @@ -219,4 +219,4 @@ namespace mbts.spark { } #endregion } -} \ No newline at end of file +} diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs index 86fadc311..d745228ab 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -27,7 +28,6 @@ namespace mbts.spark { private readonly ITag _in_candidate_vol_output_tag; private readonly ITag _in_input_dirty_tag; private readonly ITag _in_window_state_tag; - private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private bool _is_dirty = true; private static readonly IDictionary> _empty_theos = new Dictionary>(); @@ -113,23 +113,23 @@ namespace mbts.spark { VolSurfaceOutput vs_output, IDictionary> exp_strikes) { if (vs_output != null) { - _timer.start(); + var timer = Stopwatch.StartNew(); var exp_volmat_map = VolSurfaceVolMatrixCalculator.generate_volmatrix( vs_output.volsurface_input, exp_strikes.ToDictionary(kv => kv.Key, kv => kv.Value as IEnumerable), vs_output.aux_data_map, new double[] { 0.0 }, false, true, false, false, false); - _timer.stop(); + timer.Stop(); _n_comps++; Log.Gen.info($"SingleVolSurfaceTheoSource._compute_theos vs_id:{_vs_id} " + - $"vol time:{ _timer.lastIntervalTime} msecs n_comps: {_n_comps}"); - _timer.start(); + $"vol time:{ timer.Elapsed.TotalMilliseconds} msecs n_comps: {_n_comps}"); + timer.Start(); var theo_map = VolSurfaceTheoCalculator.compute_standard_greeks( vs_output.volsurface_input.surface_settings, exp_volmat_map, true); - _timer.stop(); + timer.Stop(); Log.Gen.info($"SingleVolSurfaceTheoSource._compute_theos vs_id:{_vs_id} " + - $"theo time:{ _timer.lastIntervalTime} msecs n_comps: {_n_comps}"); + $"theo time:{timer.Elapsed.TotalMilliseconds} msecs n_comps: {_n_comps}"); return theo_map; } return new Dictionary>(); diff --git a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs index 4dcfdf5fe..ad8c512ba 100644 --- a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs +++ b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -82,7 +83,6 @@ namespace mbts.spark new Queue(); private bts.api.IBus _bus; private List _subs = new List(); - private HighPerformanceTimer _timer = new HighPerformanceTimer(); public VolSurfaceBusManager(bts.api.IBus bus, bts.api.analytics.AnalyticsService analytics_service, @@ -188,8 +188,7 @@ namespace mbts.spark return new Dictionary(0); } - HighPerformanceTimer timer = new HighPerformanceTimer(); - timer.start(); + var timer = Stopwatch.StartNew(); Dictionary rv = new Dictionary(); foreach (var kv in theos) { @@ -220,9 +219,9 @@ namespace mbts.spark } } } - timer.stop(); + timer.Stop(); Log.Gen.info($"VolSurfaceBusManager keyed theos count: {rv.Count} " + - $"time: {timer.lastIntervalTime}"); + $"time: {timer.Elapsed.TotalMilliseconds}"); return rv; } @@ -327,10 +326,10 @@ namespace mbts.spark } bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval id: {client_req.id} save_time: {ret.SaveTime} " + $"sec_tup: {ret.SecTup.Venue}_{ret.SecTup.Type}_{ret.SecTup.Symbol}"); - _timer.start(); + var timer = Stopwatch.StartNew(); ArchivedTheoList arch_theos = _analytics_service.get_archived_theos(ret); - _timer.stop(); - bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval time: {_timer.lastIntervalTime} " + + timer.Stop(); + bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval time: {timer.Elapsed.TotalMilliseconds}ms " + $"n_entries: {arch_theos.SecTheo.Count}"); _bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(client_req, arch_theos)); } @@ -366,9 +365,9 @@ namespace mbts.spark } bts.Log.Gen.info(String.Format("VSBusManager, successfully obtained new vs_id:{0}", reply.NewId)); vs_input.surface_settings.core_settings.vol_surface_id = reply.NewId; - _timer.start(); + var timer = Stopwatch.StartNew(); ResultMessage res = VolSurfaceUtilityFunctions.save_volsurface(vs_input, _analytics_service); - _timer.stop(); + timer.Stop(); if (!res.Success) { report_err(res.ErrorMessage); @@ -376,7 +375,7 @@ namespace mbts.spark } Log.Gen.info(String.Format("VSBusManager, successfully created vol surface, vs_id:{0} ts:{1} msecs", vs_input.surface_settings.core_settings.vol_surface_id, - _timer.lastIntervalTime.ToString())); + timer.Elapsed.TotalMilliseconds)); _bb.post(SparkTags.VolSurfaceActivationTag(reply.NewId), true, false); } diff --git a/src/client/spark/AW2/InterpTheosServerPublisher.cs b/src/client/spark/AW2/InterpTheosServerPublisher.cs index a29452e57..969d13d42 100644 --- a/src/client/spark/AW2/InterpTheosServerPublisher.cs +++ b/src/client/spark/AW2/InterpTheosServerPublisher.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using mbts.analytics; using bts.api; using bts.collections; @@ -14,7 +15,6 @@ namespace mbts.spark { public class InterpTheosServerPublisher : IDisposable { private readonly ThreadedBlackboard _bb; private readonly bts.api.orderman.OrderService _order_service; - private HighPerformanceTimer _timer = new HighPerformanceTimer(); public InterpTheosServerPublisher(ThreadedBlackboard bb, bts.api.orderman.OrderService order_service) { @@ -87,7 +87,7 @@ namespace mbts.spark { _bb.read_state(SparkTags.AllOptionDriverBBOTag, null); if (sc_data == null || all_theos == null || all_drivers == null) return; - _timer.start(); + var timer = Stopwatch.StartNew(); all_theos = _filter_for_publish(all_theos); if (all_theos.Count == 0) { bts.Log.Gen.info($"InterpTheosServerPublisher._publish_data all_theos.Count == 0"); @@ -120,12 +120,12 @@ namespace mbts.spark { } bts.api.orderman.PrecomputedTheos server_theos = new PrecomputedTheos(); server_theos.Theos.AddRange(ptp_list); - _timer.stop(); - var comp_time = _timer.lastIntervalTime; - _timer.start(); + timer.Stop(); + var comp_time = timer.Elapsed.TotalMilliseconds; + timer.Start(); _order_service.set_precomputed_theos(server_theos); - _timer.stop(); - var pub_time = _timer.lastIntervalTime; + timer.Stop(); + var pub_time = timer.Elapsed.TotalMilliseconds; bts.Log.Gen.info($"InterpTheosServerPublisher._publish_data symbols: {all_theos.Count} " + $"size: {server_theos.Theos.Count} comp_time: {comp_time} msecs " + $"pub_time: {pub_time}"); diff --git a/src/client/spark/AW2/LiveTheoPublisher.cs b/src/client/spark/AW2/LiveTheoPublisher.cs index 5d97b5f0f..7adbe64f1 100644 --- a/src/client/spark/AW2/LiveTheoPublisher.cs +++ b/src/client/spark/AW2/LiveTheoPublisher.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using mbts.analytics; using bts.api; using mbts.ui; @@ -16,7 +17,6 @@ namespace mbts.spark { _greeks_tag = SparkTags.AllInterpGreeks; private readonly ITag> _drivers_tag = SparkTags.AllOptionDriverBBOTag; - private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 100); private readonly string _log_id = "LiveTheoPublisher"; private DateTime _last_future_theos_published = DateTime.MinValue; @@ -120,7 +120,7 @@ namespace mbts.spark { private void _interp_and_publish() { - _timer.start(); + var timer = Stopwatch.StartNew(); var res = new Dictionary(); IReadOnlyDictionary driver_map = _bb.read_state(_drivers_tag); @@ -165,8 +165,8 @@ namespace mbts.spark { IReadOnlyDictionary res_ro = res; bts.Log.Gen.info($"LiveTheoPublisher._interp_and_publish posting " + $"count: {res_ro.Count}"); - _timer.stop(); - _logger.log(_log_id, _log_id, _timer.lastIntervalTime); + timer.Stop(); + _logger.log(_log_id, _log_id, timer.Elapsed.TotalMilliseconds); _bb.post(SparkTags.Greeks, res_ro); // oh and those TC2 theos for comptability _publish_tc2_theos(k_theos); diff --git a/src/client/spark/AW2/Misc/PerfStatsLogger.cs b/src/client/spark/AW2/Misc/PerfStatsLogger.cs index 13a3ad198..97269127f 100644 --- a/src/client/spark/AW2/Misc/PerfStatsLogger.cs +++ b/src/client/spark/AW2/Misc/PerfStatsLogger.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing.Text; using System.Linq; using System.Text; @@ -18,7 +19,7 @@ namespace mbts.spark { private readonly int _log_period_updates, _max_size; private DateTime _last_write_time = DateTime.Now; private readonly string _default_id = String.Empty; - private readonly HighPerformanceTimer _defaut_timer = new HighPerformanceTimer(); + private readonly Stopwatch _defaut_timer = new(); public PerfStatsLogger() : this(100, 200) { } @@ -36,14 +37,14 @@ namespace mbts.spark { } public void start_default_timer() { - _defaut_timer.start(); + _defaut_timer.Start(); } public void stop_default_timer() { if (String.IsNullOrEmpty(_default_id)) return; - _defaut_timer.stop(); - log(_default_id, _default_id, _defaut_timer.lastIntervalTime); + _defaut_timer.Stop(); + log(_default_id, _default_id, _defaut_timer.Elapsed.TotalMilliseconds); } public void log_default(double time) { diff --git a/src/client/spark/NMSheets/DataProviders/NMSheetAllTaskingDataSource.cs b/src/client/spark/NMSheets/DataProviders/NMSheetAllTaskingDataSource.cs index eac79043d..4813e3315 100644 --- a/src/client/spark/NMSheets/DataProviders/NMSheetAllTaskingDataSource.cs +++ b/src/client/spark/NMSheets/DataProviders/NMSheetAllTaskingDataSource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,7 +19,6 @@ using bts.api.orderman; namespace mbts.ui { internal class NMSheetAllTaskingDataSource { private IBus _bus; - HighPerformanceTimer _timer = new HighPerformanceTimer(); private Nullable get_tasking_order( OrderDefinitionImmutable def) { @@ -66,7 +66,7 @@ namespace mbts.ui { bts.Log.Gen.info("NMSheetAllTaskingDataSource constructed"); _bus = bus; orders_model.on_orders.Subscribe(ords => { - _timer.start(); + var timer = Stopwatch.StartNew(); NMSheetAllTaskingData t_data = new NMSheetAllTaskingData(); bts.Log.Gen.info($"NMSheetAllTaskingDataSource on_orders n_orders: {ords.state.Values.Count()}"); foreach (var k in ords.state.Values) { @@ -78,11 +78,11 @@ namespace mbts.ui { add_task_secs(ref t_data, order.Def.Side, t_dyn.Value); } } - _timer.stop(); + timer.Stop(); bts.Log.Gen.info($"NMSheetAllTaskingDataSource n_bids: {t_data.bids.Count()} " + - $"n_asks: {t_data.asks.Count()} t_msecs: {_timer.lastIntervalTime}"); + $"n_asks: {t_data.asks.Count()} t_msecs: {timer.Elapsed.TotalMilliseconds}ms"); bus.post(SparkTags.TC2Tags.TaskData, t_data); }); } } -} \ No newline at end of file +} diff --git a/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs b/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs index 2df3fa99b..6b63c41f6 100644 --- a/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs +++ b/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using mbts.ui; using mbts.spark; @@ -102,8 +103,7 @@ namespace BCG { private void _compute_and_fire() { if (_is_main_sheet_active()) { - HighPerformanceTimer timer = new HighPerformanceTimer(); - timer.start(); + var timer = Stopwatch.StartNew(); NMSheetDataRequest data_request = _threaded_bb.read_state(_in_bb_main_sheet_request_tag) ?? new NMSheetDataRequest(new List>()); data_request = NMSheetDataRequest.restrict_for_symbol(data_request, _nmsheet_symbol); OptionDriverPriceMap live_driver_map = _threaded_bb.read_state(_in_bb_live_driver_bbo_tag); @@ -130,9 +130,9 @@ namespace BCG { null, _threaded_bb.read_state(_in_bb_secmap_tag), sheet_settings); - timer.stop(); + timer.Stop(); _cb(new Pair(_nmsheet_symbol, theo_data)); - _logger.log(_log_msg_id, _log_msg_id, timer.lastIntervalTime); + _logger.log(_log_msg_id, _log_msg_id, timer.Elapsed.TotalMilliseconds); } } } diff --git a/src/client/spark/NMSheets/NMSheetDataCoalescer.cs b/src/client/spark/NMSheets/NMSheetDataCoalescer.cs index d85a2e697..6612da2aa 100644 --- a/src/client/spark/NMSheets/NMSheetDataCoalescer.cs +++ b/src/client/spark/NMSheets/NMSheetDataCoalescer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,7 +23,6 @@ namespace BCG { private bool _is_dirty = true; private PerfStatsLogger _stats_logger = new PerfStatsLogger(); - private HighPerformanceTimer _timer = new HighPerformanceTimer(); public NMSheetDataCoalescer(ThreadedBlackboard threaded_bb, object req_id, List nmsheet_symbol_list, NMSheetSettings settings) { _threaded_bb = threaded_bb; @@ -44,13 +44,13 @@ namespace BCG { public NMSheetData get_data() { if (_is_dirty) { _is_dirty = false; - _timer.start(); + var timer = Stopwatch.StartNew(); NMSheetAllTaskingData d = _threaded_bb.read_state( SparkTags.TC2Tags.TaskData, new NMSheetAllTaskingData()); NMSheetData rv = new NMSheetData(_main_data_source.get_data(), _bbo_data_source.get_all_data(), _ticker_data_source.get_data(), d); rv = _filter_data(rv, _threaded_bb.read_state(_in_bb_settings_tag)); - _timer.stop(); - _stats_logger.log(String.Format("NMSheetDataCoalescer_{0}", _req_id), "NMSheetData.cons", _timer.lastIntervalTime); + timer.Stop(); + _stats_logger.log(String.Format("NMSheetDataCoalescer_{0}", _req_id), "NMSheetData.cons", timer.Elapsed.TotalMilliseconds); return rv; } else { return null; @@ -78,4 +78,4 @@ namespace BCG { } #endregion } -} \ No newline at end of file +} diff --git a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs index fc888cd4d..27a9fc1ec 100644 --- a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs +++ b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Data; using System.Text; @@ -30,7 +31,6 @@ namespace BCG { private ThreadedBlackboard _threaded_bb; private Action _scroll_to_atm_cb; private IDictionary _header_data; - private HighPerformanceTimer _timer = new HighPerformanceTimer(); private NMSheetExpirationHeaderControlStrip() { InitializeComponent(); } private PerfStatsLogger _logger = new PerfStatsLogger(); private readonly string _log_id; @@ -63,7 +63,7 @@ namespace BCG { } public void set_header_data(IDictionary header_data) { - _timer.start(); + var timer = Stopwatch.StartNew(); _header_data = header_data; NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); bool control_list_modified = false; @@ -95,8 +95,8 @@ namespace BCG { _reallign_controls(this, _vol_controls.Values, _threaded_bb.read_state(_in_bb_nmsheet_viewable_area_tag)); _publish_vol_shift_data(); } - _timer.stop(); - _logger.log(_log_id, "NMSheetExpirationHeaderControlStrip.set_header_data", _timer.lastIntervalTime); + timer.Stop(); + _logger.log(_log_id, "NMSheetExpirationHeaderControlStrip.set_header_data", timer.Elapsed.TotalMilliseconds); } private void _scroll_to_atm_event(NMSheetExpiration nmsheet_exp) { _scroll_to_atm_cb(nmsheet_exp); } diff --git a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs index 853219239..56270aed2 100644 --- a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs +++ b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Data; using System.Text; @@ -35,7 +36,6 @@ namespace BCG { // HighDPI - multiplying Taha's magic number by the _dpi_ratio // fixes the up/down arrows overlaping the driver price private static readonly int _single_driver_control_width = (105).MultipliedByDPIRatio(); - private HighPerformanceTimer _timer = new HighPerformanceTimer(); private ThreadedBlackboard _threaded_bb; private readonly ITag _in_bb_nmsheet_settings_tag; @@ -124,7 +124,7 @@ namespace BCG { /// dictated whats being painted on the grid, this keeps this control /// in sync with the grid in terms of expiration. private void _handle_sheet_theo_data(NMSheetData nmsheet_data) { - _timer.start(); + var timer = Stopwatch.StartNew(); bool control_list_modified = false; NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); if (nmsheet_data != null) { @@ -159,8 +159,8 @@ namespace BCG { if (control_list_modified) { _reallign_controls(_price_controls, _threaded_bb.read_state(_in_bb_nmsheet_viewable_area_tag)); } - _timer.stop(); - _logger.log(_log_id, "NMSheetDriverControlStrip._handle_sheet_data", _timer.lastIntervalTime); + timer.Stop(); + _logger.log(_log_id, "NMSheetDriverControlStrip._handle_sheet_data", timer.Elapsed.TotalMilliseconds); } #region Price control events @@ -247,4 +247,4 @@ namespace BCG { } #endregion } -} \ No newline at end of file +} diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs index fde1aba34..ee05b84e1 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Data; using System.Linq; @@ -876,22 +877,20 @@ namespace BCG { out NMSheetFormattedTheos formatted_theos, out NMSheetGeometricLayout geo_lo_info, PerfStatsLogger recorder) { - HighPerformanceTimer timer = new HighPerformanceTimer(); - - timer.start(); + var timer = Stopwatch.StartNew(); visual_lo_info = new NMSheetVisualLayout(nmsheet_settings); - timer.stop(); - double visual_layout_time = timer.lastIntervalTime; + timer.Stop(); + double visual_layout_time = timer.Elapsed.TotalMilliseconds; - timer.start(); + timer.Start(); formatted_theos = new NMSheetFormattedTheos(sheet_data, visual_lo_info.visible_cols, formatter); - timer.stop(); - double format_theo_time = timer.lastIntervalTime; + timer.Stop(); + double format_theo_time = timer.Elapsed.TotalMilliseconds; - timer.start(); + timer.Start(); geo_lo_info = new NMSheetGeometricLayout(graphics, nmsheet_settings, visual_lo_info, formatted_theos, prev_geo_lo_info, false); - timer.stop(); - double geometric_layout_time = timer.lastIntervalTime; + timer.Stop(); + double geometric_layout_time = timer.Elapsed.TotalMilliseconds; recorder.log("NMSheetTheoControl.VisualLayout", "NMSheetTheoControl.VisualLayout", visual_layout_time); recorder.log("NMSheetTheoControl.Formatting", "NMSheetTheoControl.Formatting", format_theo_time); diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs index 8e0a253ee..69732308c 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Data; using System.Windows.Forms; @@ -24,7 +25,6 @@ namespace BCG { private readonly bool _is_remoted = mbts.config.Configuration.get().IsRemoteApp; private readonly PerfStatsLogger _recorder = new PerfStatsLogger(); - private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private System.ComponentModel.Container components = null; private NMSheetFormattedTheos _formatted_theos; @@ -74,16 +74,16 @@ namespace BCG { _formatted_theos = formatted_theos; _geo_layout_info = geometric_lo_info; - _timer.start(); + var timer = Stopwatch.StartNew(); /// if the cache is invalidated, the selection is cleared if (new MyCacheInvalidationHelperData(_formatted_theos, _geo_layout_info, _settings).is_cache_invalidated(_cache_invalidation_data)) _selected_items_map = NMSheetTheoGridSelectionMap.get_empty_map(); _scroller.reset_settings(_settings); double hit_ratio = _draw_on_bitmap(); Invalidate(); - _timer.stop(); + timer.Stop(); _recorder.log("NMSheetTheoGridDraw.HitRatio", "NMSheetTheoGridDraw.HitRatio", hit_ratio); - _recorder.log("NMSheetTheoGridDraw.DrawTime", "NMSheetTheoGridDraw.DrawTime", _timer.lastIntervalTime); + _recorder.log("NMSheetTheoGridDraw.DrawTime", "NMSheetTheoGridDraw.DrawTime", timer.Elapsed.TotalMilliseconds); } } diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridBitmapDrawing.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridBitmapDrawing.cs index 1cd278301..ee860dd43 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridBitmapDrawing.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridBitmapDrawing.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Data; using System.Windows.Forms; @@ -94,7 +95,7 @@ namespace BCG { } private void _draw_header(IGraphicsWrapper w) { - double start_ms = _timer.runningMilliseconds(), stop_ms; + var timer = Stopwatch.StartNew(); w.selectPen(w.createPen(_settings.setting_grid_internal.row_seperator_line_color /*cfg.lineColor*/)); w.selectFont(_settings.setting_expiration_header.expiration_font /*cfg.HeaderFont*/); w.set_text_align(_convert_horizontal_alignment_setting_to_mask(NMSheetSettingGridInternal.NMSheetGridHorizontalTextAlignment.Left)); @@ -117,12 +118,12 @@ namespace BCG { w.drawString(_formatted_theos.sorted_formatted_expirations[i], x + adjx, 0 + adjy); } - stop_ms = _timer.runningMilliseconds(); - _recorder.log("Header draw time", "Header draw time", stop_ms - start_ms); + timer.Stop(); + _recorder.log("Header draw time", "Header draw time", timer.Elapsed.TotalMilliseconds); } private void _paint_seperate_areas(IGraphicsWrapper w) { - double start_ms = _timer.runningMilliseconds(); + var timer = Stopwatch.StartNew(); foreach (NMSheetColumnName col in _visual_layout_info.visible_cols) { int element_width = (int)_geo_layout_info.get_item_cell_size(col).Width, element_offset = _geo_layout_info.get_item_x_in_exp(_visual_layout_info, col); @@ -134,8 +135,8 @@ namespace BCG { _geo_layout_info.cell_size.Height * _formatted_theos.sorted_formatted_strikes.Length); } } - double stop_ms = _timer.runningMilliseconds(); - _recorder.log("NMSheetTheosGrid._paint_seperate_areas", "NMSheetTheosGrid._paint_seperate_areas", stop_ms - start_ms); + timer.Stop(); + _recorder.log("NMSheetTheosGrid._paint_seperate_areas", "NMSheetTheosGrid._paint_seperate_areas", timer.Elapsed.TotalMilliseconds); w.selectPen(w.createPen(Color.Black)); } @@ -275,4 +276,4 @@ namespace BCG { return new Point((int)(cell_size.Width / 2.0), 0); } } -} \ No newline at end of file +} diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridScrolling.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridScrolling.cs index 3913c5a22..06a1bc00d 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridScrolling.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridScrolling.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Windows.Forms; @@ -94,13 +95,13 @@ namespace BCG if (Math.Abs(dp.Width - _move_since_dragging_start.Width) >= _selection_drag_move_threshold.Width || Math.Abs(dp.Height - _move_since_dragging_start.Height) >= _selection_drag_move_threshold.Height) { _move_since_dragging_start = dp; - _timer.start(); + var timer = Stopwatch.StartNew(); Rectangle selected_rectangle = _get_selected_rectangle(dp); _selected_items_map = new NMSheetTheoGridSelectionMap(_formatted_theos, _visual_layout_info, _geo_layout_info, _settings, selected_rectangle, _data_at_drag_start); Invalidate(); - _timer.stop(); + timer.Stop(); System.Diagnostics.Trace.WriteLine(String.Format("{0}:{1}:{2}:{3} , Time {4} msecs , Rect {5} dp {6}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, - DateTime.Now.Millisecond, _timer.lastIntervalTime, selected_rectangle, dp)); + DateTime.Now.Millisecond, timer.Elapsed.TotalMilliseconds, selected_rectangle, dp)); } } } @@ -132,4 +133,4 @@ namespace BCG return bm_rect; } } -} \ No newline at end of file +} diff --git a/src/client/spark/Risk/PNL/PNLReportCalculator.cs b/src/client/spark/Risk/PNL/PNLReportCalculator.cs index 160ef9c67..fdea45ae9 100644 --- a/src/client/spark/Risk/PNL/PNLReportCalculator.cs +++ b/src/client/spark/Risk/PNL/PNLReportCalculator.cs @@ -1,6 +1,7 @@ using mbts.utils; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using mbts.spark; using bts.api; @@ -102,7 +103,7 @@ namespace mbts.analytics { public PNLReportCalculator(bts.api.IBus bus) { Log.Ui.info("PNLReportCalculator init'ed"); _bus = bus; - HighPerformanceTimer timer = new HighPerformanceTimer(); + var timer = new Stopwatch(); _dispose = bus.subscribe(SparkTags.TradeLogTag) .CombineLatest( @@ -112,16 +113,16 @@ namespace mbts.analytics { (trades, opt_theos, fut_theos, secs) => (trades, opt_theos, fut_theos, secs)) .BufferLatest(TimeSpan.FromSeconds(2)) .Subscribe(tup => { - timer.start(); + timer.Start(); var opt_theos_cleaned = tup.opt_theos.ToDictionary( kv => kv.Key, kv => kv.Value == null ? new ExpStrikeKeyedData() : kv.Value); var fut_theos_cleaned = tup.fut_theos.ToDictionary( kv => kv.Key, kv => kv.Value == null ? FutureTheoStructure.get_empty(kv.Key.expiration) : kv.Value); var pnl_trades = _create_pnl_rows(tup.trades, opt_theos_cleaned, fut_theos_cleaned, tup.secs); var output = _create_output(pnl_trades); - timer.stop(); + timer.Stop(); Log.Ui.info($"PNLReportCalculator n_pos: {output.position_data.Count()} " + - $"n_day_trades: {output.day_trades.Count()} time(msecs): {timer.lastIntervalTime}"); + $"n_day_trades: {output.day_trades.Count()} time(msecs): {timer.Elapsed.TotalMilliseconds}"); //_log_before_posting(output.position_data); _bus.post(SparkTags.ReportBlackboardTags.PNL.PNLData, output); }); diff --git a/src/client/spark/Risk/Slide/SlideReportCalculator.cs b/src/client/spark/Risk/Slide/SlideReportCalculator.cs index 081c7d27c..0c52a7ccb 100644 --- a/src/client/spark/Risk/Slide/SlideReportCalculator.cs +++ b/src/client/spark/Risk/Slide/SlideReportCalculator.cs @@ -3,6 +3,7 @@ using mbts.analytics; using mbts.utils; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using mbts.spark; using bts.api; @@ -40,7 +41,6 @@ namespace mbts.analytics { private SlideModelUIOverrides _ui_override = null; private VolSurfaceStandardTime _vs_standard_time = null; // Support Data - private HighPerformanceTimer _timer = new HighPerformanceTimer(); private bool _compute_dirty = false; private HashSet _sec_tups; @@ -205,7 +205,7 @@ namespace mbts.analytics { private bool _compute_and_fire() { if (_is_data_ready) { - _timer.start(); + var timer = Stopwatch.StartNew(); VolSurfaceInput vs_input = _vs_effective_input; // aux: var aux_data_map = VolSurfaceUtilityFunctions.compute_aux_data(vs_input, @@ -228,9 +228,9 @@ namespace mbts.analytics { account_option_pos_map.ToDictionary(kv => kv.Key, kv => new HashSet(kv.Value.Keys)), _report.Handles); VolSurfaceSlideCalculator.change_vol_dervs_to_percentages(ref option_theo_map); - _timer.stop(); - bts.Log.Gen.info(String.Format("Slide Theo Comp time {0}", _timer.lastIntervalTime)); - _timer.start(); + timer.Stop(); + bts.Log.Gen.info(String.Format("Slide Theo Comp time {0}ms", timer.Elapsed.TotalMilliseconds)); + timer.Start(); var cpp_map = _vs_nonvol_data.get_cpp_map(); // future theos: var fut_theo_map = VolSurfaceUtilityFunctions.compute_future_theos( @@ -254,8 +254,8 @@ namespace mbts.analytics { new HashSet(_vs_nonvol_data.get_associated_non_options().Select( e => new VolSurfaceExpiration(e))), _ui_override); - _timer.stop(); - bts.Log.Gen.info(String.Format("Slide Theo*Pos time {0}", _timer.lastIntervalTime)); + timer.Stop(); + bts.Log.Gen.info(String.Format("Slide Theo*Pos time {0}ms", timer.Elapsed.TotalMilliseconds)); Log.Gen.info($"SlideReportCalculator publishing calculated slide: {full_data.log_string()}"); // not supporting overrides (5/5/22) Log.assert(full_data.ui_override == null); diff --git a/src/client/spark/SpreadBox/Calculators/SpreadCalculationSynchronizer.cs b/src/client/spark/SpreadBox/Calculators/SpreadCalculationSynchronizer.cs index 3ad8a3e68..ebdf9b840 100644 --- a/src/client/spark/SpreadBox/Calculators/SpreadCalculationSynchronizer.cs +++ b/src/client/spark/SpreadBox/Calculators/SpreadCalculationSynchronizer.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using bts.api; @@ -53,8 +54,7 @@ namespace BCG { try { _last_fire_time = DateTime.Now; _compute_all_dirty = false; - HighPerformanceTimer perf_timer = new HighPerformanceTimer(); - perf_timer.start(); + var perf_timer = Stopwatch.StartNew(); IEnumerable spread_ids = _bb.read_state(_all_ids_tag); if (spread_ids == null || spread_ids.Count() == 0) return; @@ -66,10 +66,10 @@ namespace BCG { _compute_and_publish_single_spread(id, ss); } } - perf_timer.stop(); + perf_timer.Stop(); bts.Log.Ui.info( $"SpreadCalculationSynchronizer calculation compute_all {count} spreads " - + $"{perf_timer.lastIntervalTime} msecs"); + + $"{perf_timer.Elapsed.TotalMilliseconds} msecs"); } catch (Exception ex) { bts.Log.Ui.error(ex.Message); bts.Log.assert(false);