Skip to content

Commit 6c855e3

Browse files
authored
Fix EventPipeProvider to enable listening to events without keyword (#1091)
1 parent ecf0662 commit 6c855e3

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
1212
{
1313
public sealed class EventPipeProvider
1414
{
15-
public EventPipeProvider(string name, EventLevel eventLevel, long keywords = 0, IDictionary<string, string> arguments = null)
15+
public EventPipeProvider(string name, EventLevel eventLevel, long keywords = 0xF00000000000, IDictionary<string, string> arguments = null)
1616
{
1717
Name = name;
1818
EventLevel = eventLevel;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Xunit;
7+
using System.IO;
8+
using System.Runtime.Loader;
9+
using System.Reflection;
10+
using Xunit.Abstractions;
11+
using System.Collections.Generic;
12+
using System.Diagnostics.Tracing;
13+
using EventPipe.UnitTests.Common;
14+
using Microsoft.Diagnostics.NETCore.Client;
15+
using Microsoft.Diagnostics.Tracing;
16+
17+
namespace EventPipe.UnitTests.CustomEventsValidation
18+
{
19+
public class MyEventSource : EventSource
20+
{
21+
public static MyEventSource Log = new MyEventSource();
22+
23+
public void Event1() { WriteEvent(1); }
24+
public void Event2(string fileName) { WriteEvent(2, fileName); }
25+
public void Event3() { WriteEvent(3); }
26+
}
27+
28+
public class CustomEventTests
29+
{
30+
private readonly ITestOutputHelper output;
31+
32+
public CustomEventTests(ITestOutputHelper outputHelper)
33+
{
34+
output = outputHelper;
35+
}
36+
37+
[Fact]
38+
public async void CustomEventProducesEventsWithNoKeywords()
39+
{
40+
await RemoteTestExecutorHelper.RunTestCaseAsync(() =>
41+
{
42+
Dictionary<string, ExpectedEventCount> _expectedEventCounts = new Dictionary<string, ExpectedEventCount>()
43+
{
44+
{ "MyEventSource", -1 },
45+
};
46+
47+
Action _eventGeneratingAction = () =>
48+
{
49+
for (int i = 0; i < 1000; i++)
50+
{
51+
MyEventSource.Log.Event1();
52+
MyEventSource.Log.Event2("anotherFile");
53+
MyEventSource.Log.Event3();
54+
}
55+
};
56+
57+
var providers = new List<EventPipeProvider>()
58+
{
59+
new EventPipeProvider("MyEventSource", EventLevel.Informational)
60+
};
61+
62+
var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, null);
63+
Assert.Equal(100, ret);
64+
}, output);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)