Skip to content

Commit 3defd78

Browse files
authored
Minor event pipe profiler improvements (#1381)
1 parent 532f84a commit 3defd78

File tree

9 files changed

+256
-171
lines changed

9 files changed

+256
-171
lines changed

samples/BenchmarkDotNet.Samples/IntroEventPipeProfilerAdvance.cs renamed to samples/BenchmarkDotNet.Samples/IntroEventPipeProfilerAdvanced.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Buffers;
1+
using System.Buffers;
32
using System.Diagnostics.Tracing;
43
using BenchmarkDotNet.Attributes;
54
using BenchmarkDotNet.Configs;
@@ -12,7 +11,7 @@
1211
namespace BenchmarkDotNet.Samples
1312
{
1413
[Config(typeof(CustomConfig))]
15-
public class IntroEventPipeProfilerAdvance
14+
public class IntroEventPipeProfilerAdvanced
1615
{
1716
private class CustomConfig : ManualConfig
1817
{
@@ -22,13 +21,14 @@ public CustomConfig()
2221

2322
var providers = new[]
2423
{
25-
new EventPipeProvider(ClrTraceEventParser.ProviderName, EventLevel.Verbose, (long) (ClrTraceEventParser.Keywords.Exception
26-
| ClrTraceEventParser.Keywords.GC
27-
| ClrTraceEventParser.Keywords.Jit
28-
| ClrTraceEventParser.Keywords.JitTracing // for the inlining events
29-
| ClrTraceEventParser.Keywords.Loader
30-
| ClrTraceEventParser.Keywords.NGen)),
31-
new EventPipeProvider("System.Buffers.ArrayPoolEventSource", EventLevel.Informational, Int64.MaxValue),
24+
new EventPipeProvider(ClrTraceEventParser.ProviderName, EventLevel.Verbose,
25+
(long) (ClrTraceEventParser.Keywords.Exception
26+
| ClrTraceEventParser.Keywords.GC
27+
| ClrTraceEventParser.Keywords.Jit
28+
| ClrTraceEventParser.Keywords.JitTracing // for the inlining events
29+
| ClrTraceEventParser.Keywords.Loader
30+
| ClrTraceEventParser.Keywords.NGen)),
31+
new EventPipeProvider("System.Buffers.ArrayPoolEventSource", EventLevel.Informational, long.MaxValue),
3232
};
3333

3434
AddDiagnoser(new EventPipeProfiler(providers: providers));

src/BenchmarkDotNet.Diagnostics.Windows/Sessions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ protected Session(string sessionName, DiagnoserActionParameters details, EtwProf
103103
{
104104
Details = details;
105105
Config = config;
106-
FilePath = ArtifactFileNameHelper.GetFilePath(details, creationTime, FileExtension);
107-
Path.GetDirectoryName(FilePath).CreateIfNotExists();
106+
FilePath = ArtifactFileNameHelper.GetFilePath(details, creationTime, FileExtension).EnsureFolderExists();
108107
TraceEventSession = new TraceEventSession(sessionName, FilePath)
109108
{
110109
BufferSizeMB = config.BufferSizeInMb,

src/BenchmarkDotNet/Diagnosers/EventPipeProfile.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@
22
{
33
public enum EventPipeProfile
44
{
5+
/// <summary>
6+
/// Useful for tracking CPU usage and general .NET runtime information.
7+
/// This is the default option if no profile or providers are specified.
8+
/// </summary>
59
CpuSampling,
10+
/// <summary>
11+
/// Tracks GC collections and samples object allocations.
12+
/// </summary>
613
GcVerbose,
7-
GcCollect
14+
/// <summary>
15+
/// Tracks GC collections only at very low overhead.
16+
/// </summary>
17+
GcCollect,
18+
/// <summary>
19+
/// Logging when Just in time (JIT) compilation occurs.
20+
/// Logging of the internal workings of the Just In Time compiler. This is fairly verbose.
21+
/// It details decisions about interesting optimization (like inlining and tail call)
22+
/// </summary>
23+
Jit
824
}
925
}

src/BenchmarkDotNet/Diagnosers/EventPipeProfileMapper.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,52 @@
33
using Microsoft.Diagnostics.NETCore.Client;
44
using Microsoft.Diagnostics.Tracing.Parsers;
55

6-
namespace BenchmarkDotNet.Diagnosers
6+
namespace BenchmarkDotNet.Diagnosers
77
{
88
internal sealed class EventPipeProfileMapper
99
{
10-
internal static IReadOnlyDictionary<EventPipeProfile, EventPipeProvider[]> DotNetRuntimeProfiles { get; } = new Dictionary<EventPipeProfile, EventPipeProvider[]>
10+
private const string DotNetRuntimeProviderName = "Microsoft-Windows-DotNETRuntime";
11+
12+
internal static IReadOnlyDictionary<EventPipeProfile, IReadOnlyList<EventPipeProvider>> DotNetRuntimeProfiles { get; } = new Dictionary<EventPipeProfile, IReadOnlyList<EventPipeProvider>>
1113
{
12-
//Useful for tracking CPU usage and general .NET runtime information. This is the default option if no profile or providers are specified.
1314
{ EventPipeProfile.CpuSampling,
1415
new[]
1516
{
1617
new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Informational),
17-
new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, (long) ClrTraceEventParser.Keywords.Default)
18+
new EventPipeProvider(DotNetRuntimeProviderName, EventLevel.Informational, (long) ClrTraceEventParser.Keywords.Default)
1819
}},
19-
//Tracks GC collections and samples object allocations.
20-
{EventPipeProfile.GcVerbose,
20+
{ EventPipeProfile.GcVerbose,
2121
new[]
2222
{
2323
new EventPipeProvider(
24-
name: "Microsoft-Windows-DotNETRuntime",
24+
name: DotNetRuntimeProviderName,
2525
eventLevel: EventLevel.Verbose,
2626
keywords: (long) ClrTraceEventParser.Keywords.GC |
2727
(long) ClrTraceEventParser.Keywords.GCHandle |
2828
(long) ClrTraceEventParser.Keywords.Exception
2929
),
3030
}},
31-
//Tracks GC collections only at very low overhead.
32-
{EventPipeProfile.GcCollect,
31+
{ EventPipeProfile.GcCollect,
3332
new[]
3433
{
3534
new EventPipeProvider(
36-
name: "Microsoft-Windows-DotNETRuntime",
35+
name: DotNetRuntimeProviderName,
3736
eventLevel: EventLevel.Informational,
3837
keywords: (long) ClrTraceEventParser.Keywords.GC |
3938
(long) ClrTraceEventParser.Keywords.Exception
4039
)
4140
}},
41+
{ EventPipeProfile.Jit,
42+
new[]
43+
{
44+
new EventPipeProvider(
45+
name: DotNetRuntimeProviderName,
46+
eventLevel: EventLevel.Verbose,
47+
keywords: (long) ClrTraceEventParser.Keywords.Jit |
48+
(long) ClrTraceEventParser.Keywords.JitTracing |
49+
(long) ClrTraceEventParser.Keywords.Exception
50+
)
51+
}},
4252
};
4353
}
4454
}

0 commit comments

Comments
 (0)