public void OnActionExecuted(ActionExecutedContext filterContext) { _watch.Stop(); TimingSensor timingSensor = new TimingSensor(GetReadingName(filterContext.Controller, filterContext.ActionDescriptor.ActionName)); timingSensor.Add(_watch.ElapsedMilliseconds); }
public void Add_CreatesAvgReading() { var sensor = new TimingSensor("test"); sensor.Add(10.5); Assert.That(ReadingPublisher.Readings.Count, Is.EqualTo(1)); Reading reading = null; ReadingPublisher.Readings.TryDequeue(out reading); Assert.That(reading.Data, Is.InstanceOf <AvgReadingData>()); }
public void Add_CreatesAvgReadingWithCorrectName() { string sensorName = "test"; var sensor = new TimingSensor(sensorName); sensor.Add(10.5); Assert.That(ReadingPublisher.Readings.Count, Is.EqualTo(1)); Reading reading = null; ReadingPublisher.Readings.TryDequeue(out reading); Assert.That(reading.Data.Name, Is.EqualTo(sensorName + " - Avg ms")); }
// Record time spent executing the method public override void OnInvoke(MethodInterceptionArgs eventArgs) { string metricName = GetMetricName( eventArgs.Method.DeclaringType, eventArgs.Method.Name, eventArgs.Method.IsGenericMethod, eventArgs.Method.GetGenericArguments()); var sensor = new TimingSensor(metricName) { FeatureName = _featureName, FeatureGroup = _featureGroup }; var stopwatch = new Stopwatch(); stopwatch.Start(); // continue with method invocation eventArgs.Proceed(); stopwatch.Stop(); sensor.Add(stopwatch.ElapsedMilliseconds); }