public static PerformanceCounter CreateCounterWithCategory(string name, bool readOnly, PerformanceCounterCategoryType categoryType) { var category = Helpers.CreateCategory(name, categoryType); PerformanceCounter counterSample = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter(category, name, readOnly)); return(counterSample); }
public static void PerformanceCounterCategory_ReadCategory() { PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); InstanceDataCollectionCollection idColCol = pcc.ReadCategory(); Assert.NotNull(idColCol); }
public static void PerformanceCounter_CreateCounter_ProcessorCounter() { using (PerformanceCounter counterSample = new PerformanceCounter("Processor", "Interrupts/sec", "0", ".")) { Assert.Equal(0, Helpers.RetryOnAllPlatforms(() => counterSample.NextValue())); Assert.True(counterSample.RawValue > 0); } }
public static void PerformanceCounter_NextValue_ProcessorCounter() { using (PerformanceCounter counterSample = new PerformanceCounter("Processor", "Interrupts/sec", "0", ".")) { Helpers.RetryOnAllPlatforms(() => counterSample.NextValue()); System.Threading.Thread.Sleep(30); Assert.True(Helpers.RetryOnAllPlatforms(() => counterSample.NextValue()) > 0); } }
public static PerformanceCounter CreateCounterWithCategory(string categoryName, bool readOnly, PerformanceCounterCategoryType categoryType) { Helpers.CreateCategory(categoryName, categoryType); string counterName = categoryName.Replace("_Category", "_Counter"); PerformanceCounter counterSample = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter(categoryName, counterName, readOnly)); return(counterSample); }
public static void PerformanceCounterCategory_CategoryType_MultiInstance() { string categoryName = nameof(PerformanceCounterCategory_CategoryType_MultiInstance) + "_Category"; Helpers.CreateCategory(categoryName, PerformanceCounterCategoryType.MultiInstance); PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory(categoryName)); Assert.Equal(PerformanceCounterCategoryType.MultiInstance, Helpers.RetryOnAllPlatforms(() => pcc.CategoryType)); PerformanceCounterCategory.Delete(categoryName); }
public static InstanceDataCollectionCollection GetInstanceDataCollectionCollection() { PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); return(Helpers.RetryOnAllPlatforms(() => { var idcc = pcc.ReadCategory(); Assert.InRange(idcc.Values.Count, 1, int.MaxValue); return idcc; })); }
public static void PerformanceCounterCategory_CategoryType_SingleInstance() { var name = nameof(PerformanceCounterCategory_CategoryType_SingleInstance) + "_Counter"; var category = Helpers.CreateCategory(name, PerformanceCounterCategoryType.SingleInstance); PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory(category)); Assert.Equal(PerformanceCounterCategoryType.SingleInstance, Helpers.RetryOnAllPlatforms(() => pcc.CategoryType)); PerformanceCounterCategory.Delete(category); }
public static void PerformanceCounterCategory_InstanceExists_Static() { PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); string[] instances = pcc.GetInstanceNames(); Assert.True(instances.Length > 0); foreach (string instance in instances) { Assert.True(PerformanceCounterCategory.InstanceExists(instance, "Processor")); } }
public static void PerformanceCounterCategory_GetCounters() { var name = nameof(PerformanceCounterCategory_GetCounters) + "_Counter"; var category = Helpers.CreateCategory(name, PerformanceCounterCategoryType.SingleInstance); PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory(category)); PerformanceCounter[] counters = pcc.GetCounters(); Assert.True(counters.Length > 0); PerformanceCounterCategory.Delete(category); }
public static void PerformanceCounter_IncrementBy_IncrementBy2() { var name = nameof(PerformanceCounter_IncrementBy_IncrementBy2) + "_Counter"; using (PerformanceCounter counterSample = CreateCounterWithCategory(name, false, PerformanceCounterCategoryType.SingleInstance)) { counterSample.RawValue = 10; Helpers.RetryOnAllPlatforms(() => counterSample.IncrementBy(2)); Assert.Equal(12, counterSample.RawValue); Helpers.DeleteCategory(name); } }
public static void PerformanceCounter_IncrementBy_IncrementBy2() { string categoryName = nameof(PerformanceCounter_IncrementBy_IncrementBy2) + "_Category"; using (PerformanceCounter counterSample = CreateCounterWithCategory(categoryName, readOnly: false, PerformanceCounterCategoryType.SingleInstance)) { counterSample.RawValue = 10; Helpers.RetryOnAllPlatforms(() => counterSample.IncrementBy(2)); Assert.Equal(12, Helpers.RetryOnAllPlatforms(() => counterSample.NextSample().RawValue)); } Helpers.DeleteCategory(categoryName); }
public static void PerformanceCounter_CreateCounter_SetReadOnly() { var name = nameof(PerformanceCounter_CreateCounter_SetReadOnly) + "_Counter"; var category = Helpers.CreateCategory(name, PerformanceCounterCategoryType.SingleInstance); using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter(category, name))) { counterSample.ReadOnly = false; Assert.False(counterSample.ReadOnly); } Helpers.DeleteCategory(name); }
public static void PerformanceCounter_NextSample_MultiInstance() { var name = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Counter"; var instance = name + "_Instance"; var category = Helpers.CreateCategory(name, PerformanceCounterCategoryType.MultiInstance); using (PerformanceCounter counterSample = new PerformanceCounter(category, name, instance, false)) { counterSample.RawValue = 10; Helpers.RetryOnAllPlatforms(() => counterSample.Decrement()); Assert.Equal(9, counterSample.RawValue); Helpers.DeleteCategory(name); } }
public static void PerformanceCounter_CreateCounter_MultiInstanceReadOnly() { var name = nameof(PerformanceCounter_CreateCounter_MultiInstanceReadOnly) + "_Counter"; var instance = name + "_Instance"; var category = Helpers.CreateCategory(name, PerformanceCounterCategoryType.MultiInstance); using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter(category, name, instance))) { Assert.Equal(name, counterSample.CounterName); Assert.Equal(category, counterSample.CategoryName); Assert.Equal(instance, counterSample.InstanceName); Assert.Equal("counter description", Helpers.RetryOnAllPlatforms(() => counterSample.CounterHelp)); Assert.True(counterSample.ReadOnly); Helpers.DeleteCategory(name); } }
public static void PerformanceCounter_NextSample_MultiInstance() { string categoryName = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Category"; string counterName = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Counter"; string instanceName = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Instance"; Helpers.CreateCategory(categoryName, PerformanceCounterCategoryType.MultiInstance); using (PerformanceCounter counterSample = new PerformanceCounter(categoryName, counterName, instanceName, readOnly: false)) { counterSample.RawValue = 10; Helpers.RetryOnAllPlatforms(() => counterSample.Decrement()); Assert.Equal(9, counterSample.RawValue); } Helpers.DeleteCategory(categoryName); }
public static void CounterSampleCalculator_ElapsedTime() { string categoryName = nameof(CounterSampleCalculator_ElapsedTime) + "_Category"; PerformanceCounter counterSample = CreateCounter(categoryName, PerformanceCounterType.ElapsedTime); counterSample.RawValue = Stopwatch.GetTimestamp(); DateTime Start = DateTime.Now; Helpers.RetryOnAllPlatforms(() => counterSample.NextValue()); System.Threading.Thread.Sleep(500); var counterVal = Helpers.RetryOnAllPlatforms(() => counterSample.NextValue()); var dateTimeVal = DateTime.Now.Subtract(Start).TotalSeconds; Helpers.DeleteCategory(categoryName); Assert.True(Math.Abs(dateTimeVal - counterVal) < .3); }
public static void PerformanceCounter_NextValue_ProcessorCounter() { using (PerformanceCounter counterSample = new PerformanceCounter("Processor", "Interrupts/sec", "_Total", ".")) { float val; int counter = 0; do { // Ensure we don't always return zero for a counter we know is not always zero val = Helpers.RetryOnAllPlatforms(() => counterSample.NextValue()); if (val > 0f) { break; } counter++; Thread.Sleep(100); }while (counter < 20); Assert.True(val > 0f); } }
public void PerformanceCounter_PerformanceData() { // We run test in isolated process to avoid interferences on internal performance counter shared state with other tests. // These interferences could lead to fail also after retries RemoteExecutor.Invoke((string providerId, string typingCounterSetId) => { // Create the 'Typing' counter set. using (CounterSet typingCounterSet = new CounterSet(Guid.Parse(providerId), Guid.Parse(typingCounterSetId), CounterSetInstanceType.Single)) { // Add the counters to the counter set definition. typingCounterSet.AddCounter(1, CounterType.RawData32, "Total Words Typed"); typingCounterSet.AddCounter(2, CounterType.Delta32, "Words Typed In Interval"); typingCounterSet.AddCounter(3, CounterType.RawData32, "Letter A Pressed"); typingCounterSet.AddCounter(4, CounterType.RawData32, "Words Containing A"); typingCounterSet.AddCounter(5, CounterType.SampleFraction, "Percent of Words Containing A"); typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base"); typingCounterSet.AddCounter(7, CounterType.SampleBase); // Create an instance of the counter set (contains the counter data). using (CounterSetInstance typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance")) { typingCsInstance.Counters[1].Value = 0; typingCsInstance.Counters[2].Value = 0; typingCsInstance.Counters[3].Value = 0; typingCsInstance.Counters[4].Value = 0; typingCsInstance.Counters[5].Value = 0; typingCsInstance.Counters[6].Value = 0; // Instance counters readers using (PerformanceCounter totalWordsTyped = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Total Words Typed")), wordsTypedInInterval = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Words Typed In Interval")), aKeyPressed = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Letter A Pressed")), wordsContainingA = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Words Containing A")), percentofWordsContaingA = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Percent of Words Containing A"))) { typingCsInstance.Counters[1].Increment(); Assert.Equal(1, typingCsInstance.Counters[1].Value); Assert.Equal(1, typingCsInstance.Counters[1].RawValue); Assert.Equal(1, typingCsInstance.Counters["Total Words Typed"].RawValue); Assert.Equal(1, totalWordsTyped.RawValue); typingCsInstance.Counters[1].Increment(); Assert.Equal(2, typingCsInstance.Counters[1].Value); Assert.Equal(2, typingCsInstance.Counters[1].RawValue); Assert.Equal(2, typingCsInstance.Counters["Total Words Typed"].RawValue); Assert.Equal(2, totalWordsTyped.RawValue); typingCsInstance.Counters[2].IncrementBy(3); Assert.Equal(3, typingCsInstance.Counters[2].Value); Assert.Equal(3, typingCsInstance.Counters[2].RawValue); Assert.Equal(3, typingCsInstance.Counters["Words Typed In Interval"].RawValue); Assert.Equal(3, wordsTypedInInterval.RawValue); typingCsInstance.Counters[3].RawValue = 4; Assert.Equal(4, typingCsInstance.Counters[3].Value); Assert.Equal(4, typingCsInstance.Counters[3].RawValue); Assert.Equal(4, typingCsInstance.Counters["Letter A Pressed"].RawValue); Assert.Equal(4, aKeyPressed.RawValue); typingCsInstance.Counters[4].Value = 5; Assert.Equal(5, typingCsInstance.Counters[4].Value); Assert.Equal(5, typingCsInstance.Counters[4].RawValue); Assert.Equal(5, typingCsInstance.Counters["Words Containing A"].RawValue); Assert.Equal(5, wordsContainingA.RawValue); typingCsInstance.Counters[4].Decrement(); Assert.Equal(4, typingCsInstance.Counters[4].Value); Assert.Equal(4, typingCsInstance.Counters[4].RawValue); Assert.Equal(4, typingCsInstance.Counters["Words Containing A"].RawValue); Assert.Equal(4, wordsContainingA.RawValue); } } } }, _fixture._providerId.ToString(), _fixture._typingCounterSetId.ToString()).Dispose(); }
public static InstanceDataCollectionCollection GetInstanceDataCollectionCollection() { PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); return(Helpers.RetryOnAllPlatforms(() => pcc.ReadCategory())); }
public static void PerformanceCounterCategory_CounterExists_InterruptsPerSec() { PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); Assert.True(pcc.CounterExists("Interrupts/sec")); }