public void UmbracoApplicationEndRequest(HttpContext context, RuntimeLevel runtimeLevel) { if (runtimeLevel != RuntimeLevel.Run) { return; } if (ShouldProfile(context.Request)) { Stop(); if (MiniProfilerContext.Value is not null) { // if this is the first request, append the startup profiler var first = Interlocked.Exchange(ref _first, 1) == 0; if (first) { if (_startupProfiler is not null) { AddSubProfiler(_startupProfiler); } _startupProfiler = null; } ICookieManager cookieManager = GetCookieManager(context); var cookieValue = cookieManager.GetCookieValue(WebProfileCookieKey); if (cookieValue is not null) { AddSubProfiler(MiniProfiler.FromJson(cookieValue)); } //If it is a redirect to a relative path (local redirect) if (context.Response.StatusCode == (int)HttpStatusCode.Redirect && context.Response.Headers.TryGetValue(Microsoft.Net.Http.Headers.HeaderNames.Location, out var location) && !location.Contains("://")) { MiniProfilerContext.Value.Root.Name = "Before Redirect"; cookieManager.SetCookieValue(WebProfileCookieKey, MiniProfilerContext.Value.ToJson()); } } } }
public void ParentMapping() { var mp = new MiniProfiler("Test", Options); using (mp.Step("Main")) { using (mp.Step("Sub Step 1")) { using (mp.CustomTiming("cat", "Command 1")) {} using (mp.CustomTiming("cat", "Command 2")) {} using (mp.CustomTiming("cat", "Command 3")) {} } using (mp.Step("Sub Step 2")) { using (mp.CustomTiming("cat", "Command 4")) {} using (mp.CustomTiming("cat", "Command 5")) {} using (mp.CustomTiming("cat", "Command 6")) {} } } mp.Stop(); var json = mp.ToJson(); var deserialized = MiniProfiler.FromJson(json); var root = deserialized.Root; foreach (var t in root.Children) { Assert.Equal(root, t.ParentTiming); Assert.True(root == t.ParentTiming); foreach (var tc in t.Children) { Assert.Equal(t, tc.ParentTiming); Assert.True(t == tc.ParentTiming); } } }
public MiniProfiler ComplexDeserialize() => MiniProfiler.FromJson(_complexProfilerJson);
public MiniProfiler SimpleDeserialize() => MiniProfiler.FromJson(_simpleProfilerJson);