public Choke(DataRate targetRate, IStopwatch?stopwatch = null) { Helpers.Argument.ValidateRange(targetRate.BytesPerSecond, nameof(targetRate.BytesPerSecond), min: 1); RateLimit = targetRate; _stopwatch = stopwatch ?? new RealStopwatch(); BucketSizeBytes = (long)(targetRate.BytesPerSecond * BucketSize.TotalSeconds); _availableCapacity = BucketSizeBytes; _lastRefillTime = _stopwatch.GetTimestamp(); // How many ticks does it take to increase budget by one refill step? // Rounds down - safer is to send less often. var refillStepsPerSecond = targetRate.BytesPerSecond / RefillStepSizeBytes; if (refillStepsPerSecond == 0) { throw new ArgumentException("Target rate is too low for meaningful operation.", nameof(targetRate)); } _ticksPerRefillStep = _stopwatch.Frequency / refillStepsPerSecond; // Rounds up - safer is to send less often (pay more ticks per refill step). if (_stopwatch.Frequency % refillStepsPerSecond != 0) { _ticksPerRefillStep++; } }
public void Run(TimeInterval <TSource> parent) { _watch = parent._scheduler.StartStopwatch(); _last = TimeSpan.Zero; SetUpstream(parent._source.Subscribe(this)); }
/// <summary> /// Initializes a new instance of the <see cref="ResponseScope"/> class. /// </summary> /// <param name="statusCode">The status response code.</param> /// <param name="stopwatch">The elapsed time stopwatch.</param> public ResponseScope(int?statusCode, IStopwatch?stopwatch) : base(3) { Add("EventName", "HttpResponse"); Add("StatusCode", statusCode !); Add("Elapsed", Math.Round(stopwatch?.Elapsed.TotalMilliseconds ?? 0d)); }
public void Run(TParent parent) { _watch = _scheduler.StartStopwatch(); RunCore(parent); base.Run(parent._source); }
/// <inheritdoc cref="IContextLogger" /> public void LogError(Exception exception, IStopwatch?stopwatch) { _statusCode = 500; var request = RequestDetails.From(_context.Request); var response = ResponseDetails.From(_context.Response, stopwatch, _statusCode); _httpLogger.LogError(exception, request, response); }
/// <summary> /// Handles the event when the algorithm completes execution. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">The<see cref="EventArgs"/> associated with the event.</param> private void Algorithm_AlgorithmCompleted(object?sender, EventArgs e) { this.Dispatcher.Invoke(() => { this.RefreshChart(true); }); this.stopwatch = null; }
public IDisposable Start() { RegisterHostLifecycleEventHandlers(); _stopwatch = _stopwatchProvider.StartStopwatch(); _nextDue = _period; _runState = Running; _task.Disposable = _scheduler.Schedule(this, _nextDue, static (@this, a) => @this.Tick(a)); return(this); }
/// <summary> /// Initializes the stopwatch if it's not yet set. /// </summary> /// <returns>True if the stopwatch was initialized; otherwise, false.</returns> private bool TryInitializeStopwatch() { if (this.stopwatch == null) { this.stopwatch = this.stopwatchFactory.Create(); this.stopwatch.Start(); return(true); } return(false); }
private ResponseDetails(HttpResponseMessage?response, IStopwatch?stopwatch, int?statusCode) : this(stopwatch) { if (response is null) { return; } StatusCode = (HttpStatusCode)(statusCode ?? (int)response.StatusCode); ContentType = response.Content?.Headers.ContentType?.ToString(); Headers = ToDictionary(response.Headers); Content = Read(response.Content); }
private ResponseDetails(HttpResponse?response, IStopwatch?stopwatch, int?statusCode) : this(stopwatch) { if (response is null) { return; } StatusCode = (HttpStatusCode)(statusCode ?? response.StatusCode); ContentType = response.ContentType; Headers = response.Headers; Content = response.Body; }
private TimeMeasurable(IServiceProvider services, IStopwatch stopwatch) { _services = services; _stopwatch = stopwatch; _stopwatch.Start(); }
public void Run(IObservable <TSource> source, IScheduler scheduler) { _watch = scheduler.StartStopwatch(); Run(source); }
private ResponseDetails(IStopwatch?stopwatch) { Stopwatch = stopwatch; Time = stopwatch?.Time() ?? string.Empty; }
public void Run(Time parent) { _watch = parent._scheduler.StartStopwatch(); SetUpstream(parent._source.SubscribeSafe(this)); }