Skip to content

Instantly share code, notes, and snippets.

@droyad
Created January 7, 2014 00:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save droyad/8292852 to your computer and use it in GitHub Desktop.
Save droyad/8292852 to your computer and use it in GitHub Desktop.
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
Copy link

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

@tssutha
Copy link

tssutha 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