Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add to Glimpse Timeline
using (Timeline.Capture("FormulaEvaluator.Evalauate"))
{
// Code to time
}
public static class Timeline
{
public static IDisposable Capture(string eventName)
{
#pragma warning disable 618
var timer = GlimpseConfiguration.GetConfiguredTimerStrategy()();
if (timer == null)
return null;
var broker = GlimpseConfiguration.GetConfiguredMessageBroker();
if (broker == null)
return null;
#pragma warning restore 618
return new TimelineCapture(timer, broker, eventName);
}
}
public class TimelineCapture : IDisposable
{
private readonly string _eventName;
private readonly IExecutionTimer _timer;
private readonly IMessageBroker _broker;
private readonly TimeSpan _startOffset;
public TimelineCapture(IExecutionTimer timer, IMessageBroker broker, string eventName)
{
_timer = timer;
_broker = broker;
_eventName = eventName;
_startOffset = _timer.Start();
}
public void Dispose()
{
_broker.Publish(new TimelineMessage(_eventName, _timer.Stop(_startOffset)));
}
}
public class TimelineMessage : ITimelineMessage
{
private static readonly TimelineCategoryItem DefaultCategory = new TimelineCategoryItem("MyApp", "green", "blue");
public TimelineMessage(string eventName, TimerResult result)
{
Id = Guid.NewGuid();
EventName = eventName;
EventCategory = DefaultCategory;
Offset = result.Offset;
StartTime = result.StartTime;
Duration = result.Duration;
}
public Guid Id { get; private set; }
public TimeSpan Offset { get; set; }
public TimeSpan Duration { get; set; }
public DateTime StartTime { get; set; }
public string EventName { get; set; }
public TimelineCategoryItem EventCategory { get; set; }
public string EventSubText { get; set; }
}
@avanderhoorn

This comment has been minimized.

Copy link

commented Jan 21, 2014

Great gist! We will be pointing people to this in mean time till we get this support out of the box.

@tssutha

This comment has been minimized.

Copy link

commented Dec 22, 2015

Great Gist, saved my day :)
Had hard time configuring MiniProfiler with WebForms.. this works similar way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.