Files
lmxopcua/scripts/validation/opcua-lifecycle-memory/EventPipeCapture.cs
T

16 lines
913 B
C#

// Read-only temporary diagnostic attachment. Requires Microsoft.Diagnostics.NETCore.Client from dotnet-trace.
using System.Diagnostics.Tracing;
using Microsoft.Diagnostics.NETCore.Client;
var seconds = int.Parse(args[1]);
if (seconds < 1 || seconds > 300) throw new ArgumentOutOfRangeException(nameof(seconds), "Use a bounded 1..300 second diagnostic attachment");
var client = new DiagnosticsClient(int.Parse(args[0]));
var providers = new[] { new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0x18) };
// Match the recorded experiment's API default (256 MiB capacity, not measured resident allocation).
using var session = client.StartEventPipeSession(providers, requestRundown: false, circularBufferMB: 256);
await using var file = File.Create(args[2]);
var copy = session.EventStream.CopyToAsync(file);
await Task.Delay(TimeSpan.FromSeconds(seconds));
session.Stop();
await copy;