forked from microsoft/perfview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerfViewLogger.cs
More file actions
114 lines (108 loc) · 4.7 KB
/
PerfViewLogger.cs
File metadata and controls
114 lines (108 loc) · 4.7 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Microsoft.Diagnostics.Tracing.Parsers;
using System;
using System.Diagnostics.Tracing;
[EventSource(Name = "PerfView")]
internal class PerfViewLogger : System.Diagnostics.Tracing.EventSource
{
[Event(1)]
public void Mark(string message) { WriteEvent(1, message); }
[Event(2, Opcode = EventOpcode.Start, Task = Tasks.Tracing)]
public void StartTracing() { WriteEvent(2); }
[Event(3, Opcode = EventOpcode.Stop, Task = Tasks.Tracing)]
public void StopTracing() { WriteEvent(3); }
[Event(4, Opcode = EventOpcode.Start, Task = Tasks.Rundown)]
public void StartRundown() { WriteEvent(4); }
[Event(5, Opcode = EventOpcode.Stop, Task = Tasks.Rundown)]
public void StopRundown() { WriteEvent(5); }
[Event(6)]
public void WaitForIdle() { WriteEvent(6); }
[Event(10)]
public void CommandLineParameters(string commandLine, string currentDirectory, string version)
{
WriteEvent(10, commandLine, currentDirectory, version);
}
[Event(11)]
public void SessionParameters(string sessionName, string sessionFileName, int bufferSizeMB, int circularBuffSizeMB)
{
WriteEvent(11, sessionName, sessionFileName, bufferSizeMB, circularBuffSizeMB);
}
[Event(12)]
public void KernelEnableParameters(KernelTraceEventParser.Keywords keywords, KernelTraceEventParser.Keywords stacks)
{
WriteEvent(12, (int)keywords, (int)stacks);
}
[Event(13)]
public void ClrEnableParameters(ulong keywords, Microsoft.Diagnostics.Tracing.TraceEventLevel level)
{
WriteEvent(13, (long)keywords, (int)level);
}
[Event(14)]
public void ProviderEnableParameters(string providerName, Guid providerGuid, Microsoft.Diagnostics.Tracing.TraceEventLevel level, ulong keywords, int stacks, string values)
{
WriteEvent(14, providerName, providerGuid, (int)level, keywords, stacks, values);
}
[Event(15)]
private void StartAndStopTimes(int startTimeRelativeMSec, int stopTimeRelativeMSec)
{
WriteEvent(15, startTimeRelativeMSec, stopTimeRelativeMSec);
}
[Event(16)]
public void DebugMessage(string message)
{
WriteEvent(16, message);
}
/// <summary>
/// Logs the time (relative to this event firing) when the trace was started and stopped.
/// This is useful for circular buffer situations where that may not be known.
/// </summary>
[NonEvent]
public void StartAndStopTimes()
{
var now = DateTime.UtcNow;
int startTimeRelativeMSec = 0;
if (StartTime.Ticks != 0)
{
startTimeRelativeMSec = (int)(now - StartTime).TotalMilliseconds;
}
int stopTimeRelativeMSec = 0;
if (StopTime.Ticks != 0)
{
stopTimeRelativeMSec = (int)(now - StopTime).TotalMilliseconds;
}
StartAndStopTimes(startTimeRelativeMSec, stopTimeRelativeMSec);
}
[Event(17)]
public void CpuCounterIntervalSetting(string profileSourceName, int profileSourceCount, int profileSourceID) { WriteEvent(17, profileSourceName, profileSourceCount, profileSourceID); }
/// <summary>
/// Logged at consistent intervals so we can see where circular buffering starts.
/// </summary>
[Event(18)]
public void Tick(string message) { WriteEvent(18, message); }
[Event(19)]
public void StopReason(string message) { WriteEvent(19, message); }
[Event(20)]
public void Unused1() { WriteEvent(20); }
[Event(21)]
public void Unused2() { WriteEvent(21); }
[Event(22)]
public void PerfViewLog(string message) { WriteEvent(22, message); }
[Event(23)]
public void TriggerHeapSnapshot(string outputFile, string inputArg, string qualifiers) { WriteEvent(23, outputFile, inputArg, qualifiers); }
[Event(24)]
public void PerformanceCounterUpdate(string counterSpec, double value) { WriteEvent(24, counterSpec, value); }
[Event(25)]
public void EventStopTrigger(DateTime eventTime, int processID, int threadID, string processName, string eventName, double durationMSec)
{ WriteEvent(25, eventTime, processID, threadID, processName, eventName, durationMSec); }
[Event(26)]
public void StopTriggerDebugMessage(DateTime eventTime, string message) { WriteEvent(26, eventTime, message); }
public class Tasks
{
public const EventTask Tracing = (EventTask)1;
public const EventTask Rundown = (EventTask)2;
};
public static PerfViewLogger Log = new PerfViewLogger();
// Remember the real time where we started and stopped the trace so they are there event
// If the Start and Stop events get lost (because of circular buffering)
public static DateTime StartTime = DateTime.Now;
public static DateTime StopTime = DateTime.MaxValue;
}