public void Start() { if (_counterMonitor != null) { return; } _counterMonitor = new CounterMonitor(_pid, GetProviders()); _counterMonitor.CounterUpdate += OnCounterUpdate; Task monitorTask = new Task(() => { try { _counterMonitor.Start(); } catch (Exception x) { SessionLog.Error("DotNet Counter failure"); SessionLog.Exception(x); // Environment.FailFast("Error while listening to counters", x); } }); monitorTask.Start(); }
public void GenerateCounterListTestSingleProviderWithFilter() { CounterMonitor monitor = new CounterMonitor(); List <string> counterList = monitor.GenerateCounterList("MySource[counter1,counter2,counter3]"); Assert.Single(counterList); Assert.Equal("MySource[counter1,counter2,counter3]", counterList[0]); }
public void ParseErrorMultipleCounterLists() { CounterMonitor monitor = new CounterMonitor(); string countersOptionText = "System.Runtime[cpu-usage][working-set],MyEventSource"; var e = Assert.Throws <CommandLineErrorException>(() => monitor.ConfigureCounters(countersOptionText, null)); Assert.Equal("Error parsing --counters argument: Expected at most one '[' in counter_provider", e.Message); }
public void ParseErrorEmptyProvider() { CounterMonitor monitor = new CounterMonitor(); string countersOptionText = ",MyEventSource"; var e = Assert.Throws <CommandLineErrorException>(() => monitor.ConfigureCounters(countersOptionText, null)); Assert.Equal("Error parsing --counters argument: Expected non-empty counter_provider", e.Message); }
public void ParseErrorTrailingTextInCountersArg() { CounterMonitor monitor = new CounterMonitor(); string countersOptionText = "System.Runtime[cpu-usage]hello,MyEventSource"; var e = Assert.Throws <CommandLineErrorException>(() => monitor.ConfigureCounters(countersOptionText, null)); Assert.Equal("Error parsing --counters argument: Unexpected characters after closing ']' in counter_provider", e.Message); }
public void ParseErrorUnbalancedBracketsInCountersArg() { CounterMonitor monitor = new CounterMonitor(); string countersOptionText = "System.Runtime[cpu-usage,MyEventSource"; var e = Assert.Throws <CommandLineErrorException>(() => monitor.ConfigureCounters(countersOptionText, null)); Assert.Equal("Error parsing --counters argument: Expected to find closing ']' in counter_provider", e.Message); }
public void GenerateCounterListTestSingleProvider() { CounterMonitor monitor = new CounterMonitor(); CounterSet counters = monitor.ParseProviderList("MySource"); Assert.Single(counters.Providers); Assert.Equal("MySource", counters.Providers.First()); Assert.True(counters.IncludesAllCounters("MySource")); }
public void GenerateCounterListTestManyProvidersWithFilter() { CounterMonitor monitor = new CounterMonitor(); List <string> counterList = monitor.GenerateCounterList("MySource1[mycounter1,mycounter2], MySource2[mycounter1], System.Runtime[cpu-usage,working-set]"); Assert.Equal(3, counterList.Count); Assert.Equal("MySource1[mycounter1,mycounter2]", counterList[0]); Assert.Equal("MySource2[mycounter1]", counterList[1]); Assert.Equal("System.Runtime[cpu-usage,working-set]", counterList[2]); }
public void GenerateCounterListTestManyProviders() { CounterMonitor monitor = new CounterMonitor(); List <string> counterList = monitor.GenerateCounterList("MySource1,MySource2,System.Runtime"); Assert.Equal(3, counterList.Count); Assert.Equal("MySource1", counterList[0]); Assert.Equal("MySource2", counterList[1]); Assert.Equal("System.Runtime", counterList[2]); }
public void GenerateCounterListTestManyProviders() { CounterMonitor monitor = new CounterMonitor(); CounterSet counters = monitor.ParseProviderList("MySource1,MySource2,System.Runtime"); Assert.Equal(3, counters.Providers.Count()); Assert.Equal("MySource1", counters.Providers.ElementAt(0)); Assert.Equal("MySource2", counters.Providers.ElementAt(1)); Assert.Equal("System.Runtime", counters.Providers.ElementAt(2)); }
public void GenerateCounterListTestSingleProviderWithFilter() { CounterMonitor monitor = new CounterMonitor(); CounterSet counters = monitor.ParseProviderList("MySource[counter1,counter2,counter3]"); Assert.Single(counters.Providers); Assert.Equal("MySource", counters.Providers.First()); Assert.False(counters.IncludesAllCounters("MySource")); Assert.True(Enumerable.SequenceEqual(counters.GetCounters("MySource"), new string[] { "counter1", "counter2", "counter3" })); }
public void Stop() { if (_counterMonitor != null) { _counterMonitor.Stop(); _counterMonitor = null; } _counterValues?.Clear(); }
public void ParseErrorUnbalancedBracketsInCounterList() { CounterMonitor monitor = new CounterMonitor(); string countersOptionText = "System.Runtime,MyEventSource"; List <string> commandLineProviderArgs = new List <string>() { "System.Runtime[cpu-usage", "MyEventSource" }; var e = Assert.Throws <CommandLineErrorException>(() => monitor.ConfigureCounters(countersOptionText, commandLineProviderArgs)); Assert.Equal("Error parsing counter_list: Expected to find closing ']' in counter_provider", e.Message); }
public void GenerateCounterListWithOptionAndArgumentsTestWithDupEntries() { CounterMonitor monitor = new CounterMonitor(); List <string> counters = new List <string>() { "System.Runtime", "MyEventSource" }; monitor.GenerateCounterList("System.Runtime,MyEventSource", counters); Assert.Equal(2, counters.Count); Assert.Contains("MyEventSource", counters); Assert.Contains("System.Runtime", counters); }
public void GenerateCounterListWithOptionAndArgumentsTestWithDupEntries() { CounterMonitor monitor = new CounterMonitor(); List <string> commandLineProviderArgs = new List <string>() { "System.Runtime", "MyEventSource" }; string countersOptionText = "System.Runtime,MyEventSource"; CounterSet counters = monitor.ConfigureCounters(countersOptionText, commandLineProviderArgs); Assert.Equal(2, counters.Providers.Count()); Assert.Contains("MyEventSource", counters.Providers); Assert.Contains("System.Runtime", counters.Providers); }
public void GenerateCounterListTestManyProvidersWithFilter() { CounterMonitor monitor = new CounterMonitor(); CounterSet counters = monitor.ParseProviderList("MySource1[mycounter1,mycounter2], MySource2[mycounter1], System.Runtime[cpu-usage,working-set]"); Assert.Equal(3, counters.Providers.Count()); Assert.Equal("MySource1", counters.Providers.ElementAt(0)); Assert.False(counters.IncludesAllCounters("MySource1")); Assert.True(Enumerable.SequenceEqual(counters.GetCounters("MySource1"), new string[] { "mycounter1", "mycounter2" })); Assert.Equal("MySource2", counters.Providers.ElementAt(1)); Assert.False(counters.IncludesAllCounters("MySource2")); Assert.True(Enumerable.SequenceEqual(counters.GetCounters("MySource2"), new string[] { "mycounter1" })); Assert.Equal("System.Runtime", counters.Providers.ElementAt(2)); Assert.False(counters.IncludesAllCounters("System.Runtime")); Assert.True(Enumerable.SequenceEqual(counters.GetCounters("System.Runtime"), new string[] { "cpu-usage", "working-set" })); }