-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathProfilingServices.cs
More file actions
35 lines (26 loc) · 951 Bytes
/
ProfilingServices.cs
File metadata and controls
35 lines (26 loc) · 951 Bytes
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
using Microsoft.ApplicationInsights;
using System;
using System.Diagnostics;
namespace PostSharp.Samples.Profiling
{
public static class ProfilingServices
{
private static readonly Stopwatch stopwatch = Stopwatch.StartNew();
internal static long GetTimestamp() => stopwatch.ElapsedTicks + 1;
public static long StartTimestamp { get; private set; }
public static bool IsEnabled => Publisher != null;
internal static SampleCollector Collector { get; } = new SampleCollector();
internal static MetricPublisher Publisher { get; private set; }
public static void Initialize(TelemetryClient client, TimeSpan publishPeriod)
{
Publisher = new MetricPublisher(Collector, client);
StartTimestamp = GetTimestamp();
Publisher.Start(publishPeriod);
}
public static void Uninitialize()
{
Publisher?.Dispose();
Publisher = null;
}
}
}