Created
February 5, 2020 18:38
-
-
Save CarlosLanderas/16b8aeb483f915f076a8aee8a70271b3 to your computer and use it in GitHub Desktop.
Dotnet Counters with DiagnosticClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Diagnostics.NETCore.Client; | |
using Microsoft.Diagnostics.Tracing; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics.Tracing; | |
using System.Threading.Tasks; | |
namespace DotnetDiagnostics | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var client = new DiagnosticsClient(int.Parse(args[0])); | |
var providers = new List<EventPipeProvider> | |
{ | |
new EventPipeProvider(args[1], EventLevel.Verbose, 0xFFFFFFFF, new Dictionary<string,string> { ["EventCounterIntervalSec"] = "1" }) | |
}; | |
using var session = client.StartEventPipeSession(providers); | |
var source = new EventPipeEventSource(session.EventStream); | |
source.Dynamic.All += Dynamic_All; ; | |
source.Process(); | |
} | |
private static void Dynamic_All(TraceEvent obj) | |
{ | |
var payload = (IDictionary<string, object>)obj.PayloadValue(0); | |
var payloadValues = (IDictionary<string, object>)payload["Payload"]; | |
var display = payloadValues["DisplayName"]; | |
var value = payloadValues["Mean"]; | |
Console.WriteLine($"Counter {display} : {value}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment