Browse files

Update system so that TimeSpans are used instead of doubles

  • Loading branch information...
1 parent 0da12bd commit 9629114bc893679b6a67e2ede1172c8e5a1d6673 @avanderhoorn avanderhoorn committed Dec 28, 2012
Showing with 160 additions and 53 deletions.
  1. +3 −3 source/Glimpse.AspNet/Model/RouteModel.cs
  2. +3 −3 source/Glimpse.AspNet/Model/TimelineEventModel.cs
  3. +3 −2 source/Glimpse.AspNet/Model/TimelineModel.cs
  4. +1 −1 source/Glimpse.AspNet/SerializationConverter/ListOfRouteModelConverter.cs
  5. +1 −1 source/Glimpse.AspNet/SerializationConverter/TimelineEventModelConverter.cs
  6. +3 −2 source/Glimpse.AspNet/Tab/Timeline.cs
  7. +11 −11 source/Glimpse.Core/Extensibility/ExecutionTimer.cs
  8. +2 −2 source/Glimpse.Core/Extensibility/IExecutionTimer.cs
  9. +3 −3 source/Glimpse.Core/Extensibility/TimerResult.cs
  10. +1 −0 source/Glimpse.Core/Glimpse.Core.csproj
  11. +2 −2 source/Glimpse.Core/Message/ITimeMessage.cs
  12. +2 −2 source/Glimpse.Core/Message/TimeMessage.cs
  13. +34 −0 source/Glimpse.Core/SerializationConverter/TimeSpanConverter.cs
  14. +5 −3 source/Glimpse.Mvc3/AlternateImplementation/ActionInvokerStateMixin.cs
  15. +1 −1 source/Glimpse.Mvc3/Message/IExecutionMessage.cs
  16. +2 −2 source/Glimpse.Mvc3/Model/ExecutionModel.cs
  17. +1 −1 source/Glimpse.Mvc3/SerializationConverter/ListOfExecutionModelConverter.cs
  18. +2 −2 source/Glimpse.Test.AspNet/Tab/RoutesShould.cs
  19. +7 −7 source/Glimpse.Test.AspNet/Tab/TimelineShould.cs
  20. +2 −2 source/Glimpse.Test.Core/Framework/TimerShould.cs
  21. +1 −0 source/Glimpse.Test.Core/Glimpse.Test.Core.csproj
  22. +66 −0 source/Glimpse.Test.Core/SerializationConverter/TimeStampConverterShould.cs
  23. +1 −1 source/Glimpse.Test.Mvc3/AlternateImplementation/AsyncActionInvokerBeginInvokerActionMethodShould.cs
  24. +3 −2 source/Glimpse.Test.Mvc3/AlternateImplementation/AsyncActionInvokerEndInvokeActionMethodShould.cs
View
6 source/Glimpse.AspNet/Model/RouteModel.cs
@@ -1,5 +1,5 @@
-using System.Collections.Generic;
-using System.Web.Routing;
+using System;
+using System.Collections.Generic;
namespace Glimpse.AspNet.Model
{
@@ -17,6 +17,6 @@ public class RouteModel
public IDictionary<string, object> DataTokens { get; set; }
- public double Duration { get; set; }
+ public TimeSpan Duration { get; set; }
}
}
View
6 source/Glimpse.AspNet/Model/TimelineEventModel.cs
@@ -16,17 +16,17 @@ public TimelineEventModel()
public DateTime StartTime { get; set; }
- public double StartPoint { get; set; }
+ public TimeSpan StartPoint { get; set; }
- public double Duration { get; set; }
+ public TimeSpan Duration { get; set; }
public string Title { get; set; }
public string SubText { get; set; }
public IDictionary<string, object> Details { get; set; }
- public double EndPoint
+ public TimeSpan EndPoint
{
get { return StartPoint + Duration; }
}
View
5 source/Glimpse.AspNet/Model/TimelineModel.cs
@@ -1,12 +1,13 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Glimpse.AspNet.Model
{
public class TimelineModel
{
- public double Duration { get; set; }
+ public TimeSpan Duration { get; set; }
public IDictionary<string, TimelineCategoryModel> Category { get; set; }
View
2 source/Glimpse.AspNet/SerializationConverter/ListOfRouteModelConverter.cs
@@ -14,7 +14,7 @@ public override object Convert(List<RouteModel> routes)
var section = new TabSection("Area", "Url", "Data", "Constraints", "DataTokens", "Duration");
foreach (var item in routes)
{
- section.AddRow().Column(item.Area).Column(item.Url).Column(GetRouteData(item.RouteData)).Column(GetConstraintData(item.Constraints)).Column(GetDataTokens(item.DataTokens)).Column(Math.Round(item.Duration, 2)).SelectedIf(item.IsMatch);
+ section.AddRow().Column(item.Area).Column(item.Url).Column(GetRouteData(item.RouteData)).Column(GetConstraintData(item.Constraints)).Column(GetDataTokens(item.DataTokens)).Column(item.Duration).SelectedIf(item.IsMatch);
}
return section.Build();
View
2 source/Glimpse.AspNet/SerializationConverter/TimelineEventModelConverter.cs
@@ -8,7 +8,7 @@ public class TimelineEventModelConverter : SerializationConverter<TimelineEventM
{
public override object Convert(TimelineEventModel obj)
{
- return new { obj.Title, obj.Category, obj.SubText, obj.StartTime, obj.Details, Duration = Math.Round(obj.Duration, 2), StartPoint = Math.Round(obj.StartPoint, 2) };
+ return new { obj.Title, obj.Category, obj.SubText, obj.StartTime, obj.Details, obj.Duration, obj.StartPoint };
}
}
}
View
5 source/Glimpse.AspNet/Tab/Timeline.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
using Glimpse.AspNet.Extensibility;
using Glimpse.AspNet.Model;
@@ -56,7 +57,7 @@ public override object GetData(ITabContext context)
if (viewRenderMessages != null)
{
- var maxEndPoint = 0.0;
+ var maxEndPoint = TimeSpan.Zero;
var events = new List<TimelineEventModel>();
foreach (var viewRenderMessage in viewRenderMessages.OrderBy(x => x.Offset))
{
View
22 source/Glimpse.Core/Extensibility/ExecutionTimer.cs
@@ -22,8 +22,8 @@ public TimerResult Point()
{
var result = new TimerResult();
result.StartTime = DateTime.Now;
- result.Offset = Stopwatch.ElapsedTicks.ConvertNanosecondsToMilliseconds();
- result.Duration = 0;
+ result.Offset = Stopwatch.Elapsed;
+ result.Duration = TimeSpan.Zero;
return result;
}
@@ -32,9 +32,9 @@ public TimerResult<T> Time<T>(Func<T> func)
{
var result = new TimerResult<T>();
result.StartTime = DateTime.Now;
- result.Offset = Stopwatch.ElapsedTicks.ConvertNanosecondsToMilliseconds();
+ result.Offset = Stopwatch.Elapsed;
result.Result = func();
- result.Duration = Stopwatch.ElapsedTicks.ConvertNanosecondsToMilliseconds() - result.Offset;
+ result.Duration = Stopwatch.Elapsed - result.Offset;
return result;
}
@@ -43,24 +43,24 @@ public TimerResult Time(Action action)
{
var result = new TimerResult();
result.StartTime = DateTime.Now;
- result.Offset = Stopwatch.ElapsedTicks.ConvertNanosecondsToMilliseconds();
+ result.Offset = Stopwatch.Elapsed;
action();
- result.Duration = Stopwatch.ElapsedTicks.ConvertNanosecondsToMilliseconds() - result.Offset;
+ result.Duration = Stopwatch.Elapsed - result.Offset;
return result;
}
- public double Start()
+ public TimeSpan Start()
{
- return Stopwatch.ElapsedMilliseconds.ConvertNanosecondsToMilliseconds();
+ return Stopwatch.Elapsed;
}
- public TimerResult Stop(double offset)
+ public TimerResult Stop(TimeSpan offset)
{
var result = new TimerResult();
- result.StartTime = DateTime.Now.AddMilliseconds(offset * -1);
+ result.StartTime = DateTime.Now - offset;
result.Offset = offset;
- result.Duration = Stopwatch.ElapsedTicks.ConvertNanosecondsToMilliseconds() - result.Offset;
+ result.Duration = Stopwatch.Elapsed - result.Offset;
return result;
}
View
4 source/Glimpse.Core/Extensibility/IExecutionTimer.cs
@@ -10,8 +10,8 @@ public interface IExecutionTimer
TimerResult Time(Action action);
- double Start();
+ TimeSpan Start();
- TimerResult Stop(double offset);
+ TimerResult Stop(TimeSpan offset);
}
}
View
6 source/Glimpse.Core/Extensibility/TimerResult.cs
@@ -4,9 +4,9 @@ namespace Glimpse.Core.Extensibility
{
public class TimerResult
{
- public double Offset { get; set; }
-
- public double Duration { get; set; }
+ public TimeSpan Offset { get; set; }
+
+ public TimeSpan Duration { get; set; }
public DateTime StartTime { get; set; }
}
View
1 source/Glimpse.Core/Glimpse.Core.csproj
@@ -188,6 +188,7 @@
<Compile Include="Message\PointTimelineMessage.cs" />
<Compile Include="Message\TimelineMessage.cs" />
<Compile Include="Message\TimeMessage.cs" />
+ <Compile Include="SerializationConverter\TimeSpanConverter.cs" />
<Compile Include="Tab\Assist\CodeType.cs" />
<Compile Include="Tab\Assist\CodeTypeConverter.cs" />
<Compile Include="Tab\Assist\Formats.cs" />
View
4 source/Glimpse.Core/Message/ITimeMessage.cs
@@ -4,9 +4,9 @@ namespace Glimpse.Core.Message
{
public interface ITimeMessage : IMessage
{
- double Offset { get; }
+ TimeSpan Offset { get; }
- double Duration { get; }
+ TimeSpan Duration { get; }
DateTime StartTime { get; }
}
View
4 source/Glimpse.Core/Message/TimeMessage.cs
@@ -12,12 +12,12 @@ public TimeMessage(TimerResult timerResult, Type executedType, MethodInfo execut
Result = timerResult;
}
- public double Offset
+ public TimeSpan Offset
{
get { return Result.Offset; }
}
- public double Duration
+ public TimeSpan Duration
{
get { return Result.Duration; }
}
View
34 source/Glimpse.Core/SerializationConverter/TimeSpanConverter.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using Glimpse.Core.Extensibility;
+using Glimpse.Core.Extensions;
+
+namespace Glimpse.Core.SerializationConverter
+{
+ public class TimeSpanConverter : ISerializationConverter
+ {
+ public IEnumerable<Type> SupportedTypes
+ {
+ get
+ {
+ yield return typeof(TimeSpan);
+ yield return typeof(TimeSpan?);
+ }
+ }
+
+ public object Convert(object date)
+ {
+ var converted = date as TimeSpan?;
+
+ if (converted.HasValue)
+ {
+ return Math.Round(converted.Value.TotalMilliseconds, 2);
+ }
+
+ return null;
+ }
+ }
+}
View
8 source/Glimpse.Mvc3/AlternateImplementation/ActionInvokerStateMixin.cs
@@ -1,15 +1,17 @@
-namespace Glimpse.Mvc.AlternateImplementation
+using System;
+
+namespace Glimpse.Mvc.AlternateImplementation
{
public interface IActionInvokerStateMixin
{
- double Offset { get; set; }
+ TimeSpan Offset { get; set; }
ActionInvoker.InvokeActionMethod.Arguments Arguments { get; set; }
}
public class ActionInvokerStateMixin : IActionInvokerStateMixin
{
- public double Offset { get; set; }
+ public TimeSpan Offset { get; set; }
public ActionInvoker.InvokeActionMethod.Arguments Arguments { get; set; }
}
View
2 source/Glimpse.Mvc3/Message/IExecutionMessage.cs
@@ -11,6 +11,6 @@ public interface IExecutionMessage
MethodInfo ExecutedMethod { get; }
- double Duration { get; }
+ TimeSpan Duration { get; }
}
}
View
4 source/Glimpse.Mvc3/Model/ExecutionModel.cs
@@ -11,7 +11,7 @@ public ExecutionModel(IExecutionMessage message)
IsChildAction = message.IsChildAction;
ExecutedType = message.ExecutedType;
ExecutedMethod = message.ExecutedMethod;
- MillisecondsDuration = message.Duration;
+ Duration = message.Duration;
var filter = message as IFilterMessage;
if (filter != null)
@@ -26,7 +26,7 @@ public ExecutionModel(IExecutionMessage message)
}
}
- public double MillisecondsDuration { get; set; }
+ public TimeSpan Duration { get; set; }
public MethodInfo ExecutedMethod { get; set; }
View
2 source/Glimpse.Mvc3/SerializationConverter/ListOfExecutionModelConverter.cs
@@ -16,7 +16,7 @@ public override object Convert(List<ExecutionModel> models)
var section = new TabSection("Ordinal", "Is Child", "Category", "Category", "Type", "Method", "Time Elapsed");
foreach (var model in models)
{
- section.AddRow().Column(ordinal++).Column(model.IsChildAction).Column(model.Category.ToStringOrDefault()).Column(model.Bounds.ToStringOrDefault()).Column(model.ExecutedType).Column(model.ExecutedMethod).Column(Math.Round(model.MillisecondsDuration, 2)).SelectedIf(!model.Category.HasValue);
+ section.AddRow().Column(ordinal++).Column(model.IsChildAction).Column(model.Category.ToStringOrDefault()).Column(model.Bounds.ToStringOrDefault()).Column(model.ExecutedType).Column(model.ExecutedMethod).Column(model.Duration).SelectedIf(!model.Category.HasValue);
}
return section.Build();
View
4 source/Glimpse.Test.AspNet/Tab/RoutesShould.cs
@@ -84,8 +84,8 @@ public void MatchConstraintMessageToRoute(Routes tab, ITabContext context, Syste
RouteTable.Routes.Clear();
RouteTable.Routes.Add(route);
- var routeMessage = new RouteBase.GetRouteData.Message(new TimerResult { Duration = 19 }, route.GetType(), null, route.GetHashCode(), new System.Web.Routing.RouteData());
- var constraintMessage = new Route.ProcessConstraint.Message(new Route.ProcessConstraint.Arguments(new object[] { (HttpContextBase)null, constraint, "test", (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest }), new TimerResult { Duration = 25 }, route.GetType(), null, route.GetHashCode(), true);
+ var routeMessage = new RouteBase.GetRouteData.Message(new TimerResult { Duration = TimeSpan.FromMilliseconds(19) }, route.GetType(), null, route.GetHashCode(), new System.Web.Routing.RouteData());
+ var constraintMessage = new Route.ProcessConstraint.Message(new Route.ProcessConstraint.Arguments(new object[] { (HttpContextBase)null, constraint, "test", (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest }), new TimerResult { Duration = TimeSpan.FromMilliseconds(25) }, route.GetType(), null, route.GetHashCode(), true);
context.TabStore.Setup(mb => mb.Contains(typeof(IList<Route.ProcessConstraint.Message>).AssemblyQualifiedName)).Returns(true).Verifiable();
context.TabStore.Setup(mb => mb.Contains(typeof(IList<RouteBase.GetRouteData.Message>).AssemblyQualifiedName)).Returns(true).Verifiable();
View
14 source/Glimpse.Test.AspNet/Tab/TimelineShould.cs
@@ -57,7 +57,7 @@ public void ReturnData(ITabContext context)
var result = timeline.GetData(context) as TimelineModel;
Assert.NotNull(result);
- Assert.Equal(7, result.Duration);
+ Assert.Equal(TimeSpan.FromMilliseconds(7), result.Duration);
Assert.Equal(3, result.Events.Count);
Assert.Equal("TestName1", result.Events[0].Title);
Assert.Equal("TestName3", result.Events[1].Title);
@@ -73,17 +73,17 @@ public void ReturnEmptyWhenNoData(ITabContext context)
var result = timeline.GetData(context) as TimelineModel;
Assert.NotNull(result);
- Assert.Equal(0, result.Duration);
+ Assert.Equal(TimeSpan.FromMilliseconds(0), result.Duration);
Assert.Null(result.Events);
}
private IEnumerable<ITimelineMessage> BuildMessages()
{
return new List<ITimelineMessage>
{
- new TestTimelineMessage { Duration = 1, EventCategory = "Test1", EventName = "TestName1", EventSubText = "TestSub1", Offset = 1, StartTime = DateTime.Now },
- new TestTimelineMessage { Duration = 4, EventCategory = "Test2", EventName = "TestName2", EventSubText = "TestSub2", Offset = 3, StartTime = DateTime.Now },
- new TestTimelineMessage { Duration = 1, EventCategory = "Test3", EventName = "TestName3", EventSubText = "TestSub3", Offset = 2, StartTime = DateTime.Now }
+ new TestTimelineMessage { Duration = TimeSpan.FromMilliseconds(1), EventCategory = "Test1", EventName = "TestName1", EventSubText = "TestSub1", Offset = TimeSpan.FromMilliseconds(1), StartTime = DateTime.Now },
+ new TestTimelineMessage { Duration = TimeSpan.FromMilliseconds(4), EventCategory = "Test2", EventName = "TestName2", EventSubText = "TestSub2", Offset = TimeSpan.FromMilliseconds(3), StartTime = DateTime.Now },
+ new TestTimelineMessage { Duration = TimeSpan.FromMilliseconds(1), EventCategory = "Test3", EventName = "TestName3", EventSubText = "TestSub3", Offset = TimeSpan.FromMilliseconds(2), StartTime = DateTime.Now }
};
}
@@ -101,9 +101,9 @@ public class TestTimelineMessage : ITimelineMessage
public string EventSubText { get; set; }
- public double Offset { get; set; }
+ public TimeSpan Offset { get; set; }
- public double Duration { get; set; }
+ public TimeSpan Duration { get; set; }
public DateTime StartTime { get; set; }
View
4 source/Glimpse.Test.Core/Framework/TimerShould.cs
@@ -19,7 +19,7 @@ public void TimeFunction()
Assert.NotNull(result);
var failureMessage = result.Duration.ToString() + " not greater than " + waitTime.ToString();
Console.Write(failureMessage);
- Assert.True(result.Duration >= waitTime-1, failureMessage); //-1 to handle issues with rounding??
+ Assert.True(new DateTime().AddTicks(result.Duration.Ticks) >= new DateTime().AddTicks(result.Duration.Ticks).AddMilliseconds(waitTime - 1), failureMessage); //-1 to handle issues with rounding??
}
[Fact(Skip = "This test is flaky. Need to find a better way to do this...")]
@@ -35,7 +35,7 @@ public void TimeMethod()
});
Assert.NotNull(result);
- Assert.True(result.Duration >= waitTime);
+ Assert.True(new DateTime().AddTicks(result.Duration.Ticks) >= new DateTime().AddTicks(result.Duration.Ticks).AddMilliseconds(waitTime));
Assert.Equal("STRING", result.Result);
}
View
1 source/Glimpse.Test.Core/Glimpse.Test.Core.csproj
@@ -152,6 +152,7 @@
<Compile Include="Resource\MetadataShould.cs" />
<Compile Include="Resource\PopupResourceShould.cs" />
<Compile Include="Resource\VersionCheckResourceShould.cs" />
+ <Compile Include="SerializationConverter\TimeStampConverterShould.cs" />
<Compile Include="SerializationConverter\DateTimeConverterShould.cs" />
<Compile Include="SerializationConverter\GlimpseMetadataConverterShould.cs" />
<Compile Include="SerializationConverter\GlimpseRequestConverterShould.cs" />
View
66 source/Glimpse.Test.Core/SerializationConverter/TimeStampConverterShould.cs
@@ -0,0 +1,66 @@
+using System;
+using Glimpse.Core.SerializationConverter;
+using Xunit;
+
+namespace Glimpse.Test.Core.SerializationConverter
+{
+ public class TimeSpanConverterShould
+ {
+ [Fact]
+ public void HandleNull()
+ {
+ var converter = new TimeSpanConverter();
+
+ var result = converter.Convert(null);
+
+ Assert.Null(result);
+ }
+
+ [Fact]
+ public void SupportTimeSpans()
+ {
+ var converter = new TimeSpanConverter();
+
+ var result = converter.SupportedTypes;
+
+ Assert.Contains(typeof(TimeSpan), result);
+ Assert.Contains(typeof(TimeSpan?), result);
+ }
+
+ [Fact]
+ public void HandleNullableTimeSpans()
+ {
+ TimeSpan? input = new TimeSpan(12220);
+
+ var converter = new TimeSpanConverter();
+
+ var result = converter.Convert(input);
+
+ Assert.Equal(1.22, result);
+ }
+
+ [Fact]
+ public void HandleTimeSpans()
+ {
+ TimeSpan input = new TimeSpan(12220);
+
+ var converter = new TimeSpanConverter();
+
+ var result = converter.Convert(input);
+
+ Assert.Equal(1.22, result);
+ }
+
+ [Fact]
+ public void HandleNullableTimeSpansWithNoValue()
+ {
+ TimeSpan? input = null;
+
+ var converter = new TimeSpanConverter();
+
+ var result = converter.Convert(input);
+
+ Assert.Null(result);
+ }
+ }
+}
View
2 ...pse.Test.Mvc3/AlternateImplementation/AsyncActionInvokerBeginInvokerActionMethodShould.cs
@@ -49,7 +49,7 @@ public void StartTimingExecution(AsyncActionInvoker.BeginInvokeActionMethod sut,
context.Verify(c => c.Proceed());
context.Verify(c => c.Proxy);
- mixin.VerifySet(m => m.Offset = It.IsAny<double>());
+ mixin.VerifySet(m => m.Offset = It.IsAny<TimeSpan>());
}
}
}
View
5 ...limpse.Test.Mvc3/AlternateImplementation/AsyncActionInvokerEndInvokeActionMethodShould.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Web.Mvc;
using Glimpse.Core;
using Glimpse.Core.Extensibility;
@@ -38,7 +39,7 @@ public void PublishMessageWithRuntimePolicyOn(AsyncActionInvoker.EndInvokeAction
context.Setup(c => c.Proxy).Returns(
new ActionInvokerStateMixin
{
- Offset = 10,
+ Offset = TimeSpan.Zero,
Arguments = new ActionInvoker.InvokeActionMethod.Arguments(new ControllerContext(), actionDescriptor, new Dictionary<string, object>())
});

0 comments on commit 9629114

Please sign in to comment.