Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement