Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Diagnostics.Tracing;
  5. using Microsoft.Diagnostics.Tools.RuntimeClient;
  6. using Microsoft.Diagnostics.Tracing;
  7.  
  8. namespace Repro
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var processId = Process.GetCurrentProcess().Id;
  15. ulong eventPipeSessionId = 0;
  16. try
  17. {
  18. var providerList = new List<Provider>()
  19. {
  20. new Provider(
  21. name: "System.Runtime",
  22. keywords: uint.MaxValue,
  23. eventLevel: EventLevel.Warning,
  24. filterData: "EventCounterIntervalSec=1")
  25. };
  26.  
  27. var configuration = new SessionConfiguration(
  28. circularBufferSizeMB: 1000,
  29. format: EventPipeSerializationFormat.NetPerf,
  30. providers: providerList);
  31.  
  32. var binaryReader = EventPipeClient.CollectTracing(processId, configuration, out eventPipeSessionId);
  33. var source = new EventPipeEventSource(binaryReader);
  34. source.Dynamic.All += (eventData) =>
  35. {
  36. Console.WriteLine($"Provider = {eventData.ProviderName} ID = {eventData.ID} Name = {eventData.EventName}");
  37. };
  38. Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
  39. {
  40. EventPipeClient.StopTracing(processId, eventPipeSessionId);
  41. e.Cancel = true;
  42. };
  43. source.Process();
  44. }
  45. catch (Exception ex)
  46. {
  47. Console.WriteLine($"[ERROR] {ex.ToString()}");
  48. }
  49. finally
  50. {
  51. EventPipeClient.StopTracing(processId, eventPipeSessionId);
  52. }
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement