Glimpse中的自定义时间轴项目

Reu*_*ben 1 profiling asp.net-mvc-3 glimpse

我刚刚开始寻找MVC3应用程序的分析.

我首先找到了MiniProfiler,然后找到了使用Glimpse的建议.两者看起来都很棒,而且我宁愿使用Glimpse,但我想在特定操作的时间轴上添加条目.

MiniProfiler有一个很好的功能,你可以抓住当前的MiniProfiler上下文并使用using()命令添加一个步骤.Glimpse有类似的东西吗?

我确实找到了一个条目,有人解释了如何做到这一点很长的路,但是想知道从那以后是否可能有更短的方法来做到这一点.

Tim*_*wis 5

由于这个stackoverflow问题,我发现了一个要点GlimpseTimeline Glimpse v1 的Glimpse v2 .

从您的代码调用:

using (Timeline.Capture("FormulaEvaluator.Evalauate"))
{
    // Code to time
}
Run Code Online (Sandbox Code Playgroud)

这是Timeline.Capture的实现:

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; }
}
Run Code Online (Sandbox Code Playgroud)