forked from MiniProfiler/dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultProfilerProvider.cs
More file actions
67 lines (60 loc) · 1.89 KB
/
DefaultProfilerProvider.cs
File metadata and controls
67 lines (60 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#if NET45
using System;
using System.Runtime.Remoting.Messaging;
using System.Web;
using StackExchange.Profiling.Helpers.Net45;
#else
using System.Threading;
#endif
namespace StackExchange.Profiling
{
/// <summary>
/// Default profile provider, gracefully handles async transitions.
/// </summary>
public class DefaultProfilerProvider : BaseProfilerProvider
{
private readonly AsyncLocal<MiniProfiler> _profiler = new AsyncLocal<MiniProfiler>();
private readonly AsyncLocal<Timing> _currentTiming = new AsyncLocal<Timing>();
private MiniProfiler Profiler
{
get { return _profiler.Value; }
set { _profiler.Value = value; }
}
/// <summary>
/// Current head timing.
/// </summary>
public override Timing CurrentHead
{
get { return _currentTiming.Value; }
set { _currentTiming.Value = value; }
}
/// <summary>
/// The name says it all.
/// </summary>
public override MiniProfiler GetCurrentProfiler() => Profiler;
/// <summary>
/// Starts a new profiling session.
/// </summary>
public override MiniProfiler Start(string sessionName = null)
{
#if NET45
Profiler = new MiniProfiler(sessionName ?? AppDomain.CurrentDomain.FriendlyName) { IsActive = true };
#else // TODO: Revisit with .NET Standard 2.0
Profiler = new MiniProfiler(sessionName ?? "MiniProfiler") { IsActive = true };
#endif
SetProfilerActive(Profiler);
return Profiler;
}
/// <summary>
/// Stops the current profiling session.
/// </summary>
public override void Stop(bool discardResults)
{
Profiler?.StopImpl();
if (discardResults)
{
Profiler = null;
}
}
}
}