public void WrappedPerformanceCategoryTest_NextValueVerifyInvalidCounterNameCheck() { WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); WrappedPerformanceCategory ourCategory = liason.CacheCountersForCategory(CounterTestUtilities.TestCategoryName, null); ourCategory.NextValue("some non existent counter name"); }
public void WrappedPerformanceCategoryTest_VerifyNextValueEmptyCounterNameCheck() { WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); WrappedPerformanceCategory ourCategory = liason.CacheCountersForCategory(CounterTestUtilities.TestCategoryName, null); ourCategory.NextValue(string.Empty); }
public void WindowsPerformanceLiasonTest_VerifyWeCanSeeWellKnownCategory() { WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); WrappedPerformanceCategory returnedCategory = liason.CacheCountersForCategory("cache"); Assert.IsNotNull(returnedCategory); //// on windows 8 there are 29 cache counters Assert.AreEqual(29, returnedCategory.GetCounters().Count); }
public void WindowsPerformanceLiasonThreadTest_VerifyThreadSafe() { //// assume 4 cores int numthreads = 2; int sleeptime = 10000; string categoryname = CounterTestUtilities.TestCategoryName; //// string countername = CounterTestUtilities.TestCounterNumberOfItems64Name; string countername = CounterTestUtilities.TestCounterRateOfCountPerSecond64Name; WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); //// this warms up the counter table. otherwise every thread pays the price liason.CacheCounters(categoryname); liason.SetRawValue(categoryname, countername, 0); bool[] stopflag = { false }; Thread[] threads = new Thread[numthreads]; ThreadExecutor[] allexecutorsForValidation = new ThreadExecutor[numthreads]; for (int i = 0; i < numthreads; i++) { ThreadExecutor oneExecutor = new ThreadExecutor(liason, categoryname, countername, stopflag); threads[i] = new Thread(new ThreadStart(oneExecutor.CreateEvents)); allexecutorsForValidation[i] = oneExecutor; } foreach (Thread thread in threads) { thread.Start(); } Thread.Sleep(sleeptime); stopflag[0] = true; foreach (Thread thread in threads) { thread.Join(); } int expected = 0; foreach (ThreadExecutor oneExec in allexecutorsForValidation) { expected += oneExec.ExecutionCount; } WrappedPerformanceCategory ourCat = liason.CacheCountersForCategory(categoryname); //// Sometimes we are off by 1 or two if we run 10 seconds. how can this be? Thread.Sleep(2); //// try waiting for everything to flow through float realNextValue = ourCat.NextValue(countername); int result = (int)ourCat.NextValue(countername); long rawResult = ourCat.GetRawValue(countername); //// sometimes you don't a cooked value of 0 , some glitch in reporting Debug.WriteLine("Threads reported {0}, Counter reported {1} updates ({2} raw) with {3} threads in {4} seconds.", expected, result, rawResult, numthreads, sleeptime); Assert.AreEqual(expected, (int)rawResult, "raw result didn't match"); //// these should be exact but I've had a couple failures, not sure how that can be //// Assert.AreEqual(expected, result); Assert.AreEqual(expected, result, 2, "cooked result didn't match but raw did"); //// this should be about 2million per thread per second on quad core macbook pro Assert.IsTrue(result > 20000, "expected > 20,000 but got " + result); }
public void WrappedPerformanceCategoryTest_VerifyCanWrapOurInstances() { WrappedPerformanceCategory testCategory = new WrappedPerformanceCategory(CounterTestUtilities.TestCategoryName, null); Assert.IsNotNull(testCategory); //// there are a bunch of proc 0 counters. We just want to make sure we got some IDictionary <string, WrappedPerformanceCounter> allCounters = testCategory.GetCounters(); Assert.IsFalse(allCounters[CounterTestUtilities.TestCounterNumberOfItems64Name].CounterIsReadOnly()); Assert.IsFalse(allCounters[CounterTestUtilities.TestCounterNumberOfItems64Name].CounterHasAssociatedBase()); Assert.IsTrue(allCounters[CounterTestUtilities.TestAverageTimer32Name].CounterHasAssociatedBase()); }
public void WrappedPerformanceCategorySpecificNamesTest_VerifyPagingFileCounters() { WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); WrappedPerformanceCategory ourCategory = liason.CacheCountersForCategory( "Paging File", "_Total"); IDictionary <string, WrappedPerformanceCounter> allCounters = ourCategory.GetCounters(); WrappedPerformanceCounter ourTargetCounter = allCounters["% Usage"]; Assert.IsNotNull(ourTargetCounter); Assert.IsTrue(ourTargetCounter.CounterIsReadOnly()); Assert.IsFalse(ourTargetCounter.CounterHasAssociatedBase()); Assert.IsNotNull(ourCategory.NextValue("% Usage")); }
public void WrappedPerformanceCategoryTest_VerifyCanWrapSystemInstances() { WrappedPerformanceCategory procInfo = new WrappedPerformanceCategory("Processor", "0"); Assert.IsNotNull(procInfo); //// there are a bunch of proc 0 counters. We just want to make sure we got some IDictionary <string, WrappedPerformanceCounter> allCounters = procInfo.GetCounters(); Assert.IsTrue(allCounters.Count > 2); Assert.IsTrue(allCounters["% User Time"].CounterIsReadOnly()); //// this counter has a base but we don't see it since it is a system counter Assert.IsFalse(allCounters["% User Time"].CounterHasAssociatedBase()); }
public void WindowsPerformanceLiasonTest_VerifyFailsNonExistentCategoryName() { WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); WrappedPerformanceCategory returnedCategory = liason.CacheCountersForCategory("dogfood"); }
public void WindowsPerformanceLiasonTest_VerifyFailsNoCategoryName() { WindowsPerformanceLiason liason = new WindowsPerformanceLiason(); WrappedPerformanceCategory returnedCategory = liason.CacheCountersForCategory(string.Empty); }