Skip to content

Instantly share code, notes, and snippets.

@shirhatti
Created August 7, 2019 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirhatti/20fd0dac4a5a66852e7a2fa6d8918f2a to your computer and use it in GitHub Desktop.
Save shirhatti/20fd0dac4a5a66852e7a2fa6d8918f2a to your computer and use it in GitHub Desktop.
Repro
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tools.RuntimeClient;
using Microsoft.Diagnostics.Tracing;
namespace Repro
{
class Program
{
static void Main(string[] args)
{
var processId = Process.GetCurrentProcess().Id;
ulong eventPipeSessionId = 0;
try
{
var providerList = new List<Provider>()
{
new Provider(
name: "System.Runtime",
keywords: uint.MaxValue,
eventLevel: EventLevel.Warning,
filterData: "EventCounterIntervalSec=1")
};
var configuration = new SessionConfiguration(
circularBufferSizeMB: 1000,
format: EventPipeSerializationFormat.NetPerf,
providers: providerList);
var binaryReader = EventPipeClient.CollectTracing(processId, configuration, out eventPipeSessionId);
var source = new EventPipeEventSource(binaryReader);
source.Dynamic.All += (eventData) =>
{
Console.WriteLine($"Provider = {eventData.ProviderName} ID = {eventData.ID} Name = {eventData.EventName}");
};
Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
{
EventPipeClient.StopTracing(processId, eventPipeSessionId);
e.Cancel = true;
};
source.Process();
}
catch (Exception ex)
{
Console.WriteLine($"[ERROR] {ex.ToString()}");
}
finally
{
EventPipeClient.StopTracing(processId, eventPipeSessionId);
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RestoreSources>
$(RestoreSources);
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
https://api.nuget.org/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.42" />
<PackageReference Include="Microsoft.Diagnostics.Tools.RuntimeClient" Version="3.0.0-preview7.19365.2" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment