/// <summary> /// Stop the real time thread /// </summary> public void Exit() { _timeMonitor.DisposeSafely(); _timeMonitor = null; _realTimeThread.StopSafely(TimeSpan.FromMinutes(5), _cancellationTokenSource); _realTimeThread = null; }
public void StartStopImmediately() { TimeMonitor timer = new TimeMonitor(); timer.Start(); timer.Stop(); Assert.LowerEqualThan(0, timer.Duration); }
public void EnumSpecifyLoopDescriptionTest() { string description = null; TimeMonitor.WatchLoop("获取枚举描述", 100, () => { description = EnumExtension.GetDescription(GenderType.Male); }, str => output.WriteLine(str) ); output.WriteLine($"{GenderType.Male}:{description}"); }
public override void Run(object fixture) { TimeMonitor monitor = new TimeMonitor(); monitor.Start(); this.TestCase.Run(fixture); monitor.Stop(); Assert.IsLowerEqual(monitor.Duration, this.Attribute.MaxDuration); }
public void agendarCorte(Agendamento corteAgendado) { Action cortarGrama = cortador.Cortar; Action <float> setAlturaLamina = cortador.setAlturaLamina; TimeMonitor t = new TimeMonitor(cortarGrama, setAlturaLamina, corteAgendado); Thread thr = new Thread(new ThreadStart(t.loop)); thr.Start(); Console.WriteLine("iniciou thread para realizar o corte no horario agendado"); }
public void TestGetInfluxDBNames() { using (InfluxDBClient client = new InfluxDBClient(influxUrl, dbUName, dbpwd)) { TimeMonitor.Watch(nameof(TestGetInfluxDBNames), () => { var dbNames = client.GetInfluxDBNamesAsync().Result; var temp = dbNames; }, output.WriteLine); } }
public void DeleteInfluxDatabaseTest() { using (InfluxDBClient client = new InfluxDBClient(influxUrl, dbUName, dbpwd)) { TimeMonitor.Watch(nameof(TestGetInfluxDBNames), () => { client.CreateDatabaseAsync(dbName); var dbNames = client.GetInfluxDBNamesAsync().Result; var temp = dbNames; }, output.WriteLine); } }
public void StartStopShowValues() { TimeMonitor timer = new TimeMonitor(); timer.Start(); Random rnd = new Random(); for (int i = 0; i < 10000; ++i) { rnd.NextDouble(); } timer.Stop(); TypeHelper.ShowPropertyValues(timer); }
/// <summary> /// Convenience method for invoking a scheduled event's Scan method inside the <see cref="IsolatorLimitResultProvider"/> /// </summary> public static void Consume( this IIsolatorLimitResultProvider isolatorLimitProvider, ScheduledEvent scheduledEvent, DateTime scanTimeUtc, TimeMonitor timeMonitor ) { // perform initial filtering to prevent starting a task when not necessary if (scheduledEvent.NextEventUtcTime > scanTimeUtc) { return; } var timeProvider = RealTimeProvider.Instance; isolatorLimitProvider.Consume(timeProvider, () => scheduledEvent.Scan(scanTimeUtc), timeMonitor); }
/// <summary> /// Executes the provided code block and while the code block is running, continually consume from /// the limit result provided one token each minute. This function allows the code to run for the /// first full minute without requesting additional time from the provider. Following that, every /// minute an additional one minute will be requested from the provider. /// </summary> /// <remarks> /// This method exists to support scheduled events, and as such, intercepts any errors raised via the /// provided code and wraps them in a <see cref="ScheduledEventException"/>. If in the future this is /// usable elsewhere, consider refactoring to handle the errors in a different fashion. /// </remarks> public static void Consume( this IIsolatorLimitResultProvider isolatorLimitProvider, ITimeProvider timeProvider, Action code, TimeMonitor timeMonitor ) { var consumer = new TimeConsumer { IsolatorLimitProvider = isolatorLimitProvider, TimeProvider = timeProvider }; timeMonitor.Add(consumer); code(); consumer.Finished = true; }
public static void TestAnimal(int iterations) { var tm = new TimeMonitor(); // Run iterations for (var i = 0; i < iterations; i++) { var cm = new OrganismEmulator(); tm.Start(); cm.EmulateOrganism(); lastQuanta = tm.EndGetMicroseconds(); allQuanta.Add(lastQuanta); } // Sort by speed allQuanta.Sort(); // Pick the middle 80% of all iterations for (var i = (int)(iterations * 0.15); i < (int)(iterations * 0.85); i++) { samples++; lastQuanta = (long)allQuanta[i]; if (worstQuanta == 0 && bestQuanta == 0) { worstQuanta = lastQuanta; bestQuanta = lastQuanta; } else { if (lastQuanta > worstQuanta) { worstQuanta = lastQuanta; } if (lastQuanta < bestQuanta) { bestQuanta = lastQuanta; } } totalQuanta += lastQuanta; } }
/// <summary> /// We are finished with progress /// </summary> /// <param name="delay">Delay time in Milli Seconds</param> public void Finalise(int delay = 0) { if (Progress != null) { Message += "... Finished"; ProgressBarValue = 100; Progress((int)ProgressBarValue, Message); //add delay to allow progress indicter to catch up if (delay > 0) { var delayNo = TimeMonitor.ElapsedMilliseconds + delay; while (TimeMonitor.ElapsedMilliseconds < delayNo && TimeMonitor.IsRunning) { } } TimeMonitor.Stop(); } }
/// <summary> /// Initializes the real time handler for the specified algorithm and job /// </summary> public void Setup(IAlgorithm algorithm, AlgorithmNodePacket job, IResultHandler resultHandler, IApi api, IIsolatorLimitResultProvider isolatorLimitProvider) { //Initialize: Algorithm = algorithm; ResultHandler = resultHandler; _isolatorLimitProvider = isolatorLimitProvider; _cancellationTokenSource = new CancellationTokenSource(); _marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); var todayInAlgorithmTimeZone = DateTime.UtcNow.ConvertFromUtc(Algorithm.TimeZone).Date; // refresh the market hours for today explicitly, and then set up an event to refresh them each day at midnight RefreshMarketHoursToday(todayInAlgorithmTimeZone); // every day at midnight from tomorrow until the end of time var times = from date in Time.EachDay(todayInAlgorithmTimeZone.AddDays(1), Time.EndOfTime) select date.ConvertToUtc(Algorithm.TimeZone); Add(new ScheduledEvent("RefreshMarketHours", times, (name, triggerTime) => { // refresh market hours from api every day RefreshMarketHoursToday(triggerTime.ConvertFromUtc(Algorithm.TimeZone).Date); })); base.Setup(todayInAlgorithmTimeZone, Time.EndOfTime, job.Language, DateTime.UtcNow); foreach (var scheduledEvent in ScheduledEvents) { // zoom past old events scheduledEvent.Key.SkipEventsUntil(algorithm.UtcTime); // set logging accordingly scheduledEvent.Key.IsLoggingEnabled = Log.DebuggingEnabled; } _timeMonitor = new TimeMonitor(); _realTimeThread = new Thread(Run) { IsBackground = true, Name = "RealTime Thread" }; _realTimeThread.Start(); // RealTime scan time for time based events }
/// <summary> /// Initializes the real time handler for the specified algorithm and job /// </summary> public void Setup(IAlgorithm algorithm, AlgorithmNodePacket job, IResultHandler resultHandler, IApi api, IIsolatorLimitResultProvider isolatorLimitProvider) { //Initialize: Algorithm = algorithm; ResultHandler = resultHandler; _isolatorLimitProvider = isolatorLimitProvider; // create events for algorithm's end of tradeable dates // set up the events for each security to fire every tradeable date before market close base.Setup(Algorithm.StartDate, Algorithm.EndDate, job.Language); foreach (var scheduledEvent in GetScheduledEventsSortedByTime()) { // zoom past old events scheduledEvent.SkipEventsUntil(algorithm.UtcTime); // set logging accordingly scheduledEvent.IsLoggingEnabled = Log.DebuggingEnabled; } // after skipping events we should re order _sortingScheduledEventsRequired = true; _timeMonitor = new TimeMonitor(); }
private List <TrapperItem> GetTimeMonitors() { List <TrapperItem> result = new List <TrapperItem>(); List <string> names = TimeMonitorRepository.GetTimeMonitorNames(); foreach (string name in names) { TimeMonitor tm = TimeMonitorRepository.GetTimeMonitor(name); double totalCall1 = tm.GetTotalCall1(); double totalTime1 = tm.GetTotalTime1(); result.Add(new TimeMonitorTrapperItem(name + "_call1", FormatDouble(totalCall1))); result.Add(new TimeMonitorTrapperItem(name + "_time1", FormatDouble(totalTime1))); result.Add(new TimeMonitorTrapperItem(name + "_timeCall1", FormatDouble(0D == totalCall1 ? 0D : totalTime1 / totalCall1))); } return(result); }
/// <summary> /// Stop the real time thread /// </summary> public void Exit() { _timeMonitor.DisposeSafely(); _timeMonitor = null; if (_realTimeThread != null) { _cancellationTokenSource.Cancel(); try { if (!_realTimeThread.Join(TimeSpan.FromMinutes(5))) { Log.Error("LiveTradingRealTimeHandler.Exit(): Timeout waiting for update thread to stop"); _realTimeThread.Abort(); } } catch (Exception exception) { // just in case catch any exceptions thrown Log.Error(exception); } _realTimeThread = null; } }
/// <summary> /// Start the progress from zero /// </summary> /// <param name="totalRecords">Number of records we are going to progress through</param> /// <param name="percentageOfBar">% of progress we are to fill on first stage</param> /// <param name="message">Message to display</param> public void Reset(int totalRecords = 0, double percentageOfBar = 100, string message = null) { ProgressBarValue = 0; //at start of the progress bar TimeMonitor.Start(); NextStage(totalRecords, percentageOfBar, message); }
public void StopBeforeStart() { TimeMonitor timer = new TimeMonitor(); timer.Stop(); }
/// <summary> /// Stop the real time thread /// </summary> public void Exit() { _timeMonitor.DisposeSafely(); _timeMonitor = null; }
public void ShowValuesBeforeStartStop() { TimeMonitor timer = new TimeMonitor(); TypeHelper.ShowPropertyValues(timer); }
public void Constructor() { TimeMonitor timer = new TimeMonitor(); }
public void Setup() { _timeMonitor = new TimeMonitor(monitorIntervalMs: 3); }
/// <summary> /// Initializes a new instance of the <see cref="CountDownTimer"/> and starts it. /// </summary> /// <param name="maxDuration">The maximum duration for the timer</param> public CountDownTimer(double maxDuration) { this.maxDuration = maxDuration; this.timer = new TimeMonitor(); timer.Start(); }