public void WrappedPerformanceCategoryTest_VerifyNextValueEmptyCounterNameCheck()
        {
            WindowsPerformanceLiason   liason      = new WindowsPerformanceLiason();
            WrappedPerformanceCategory ourCategory = liason.CacheCountersForCategory(CounterTestUtilities.TestCategoryName, null);

            ourCategory.NextValue(string.Empty);
        }
        public void WrappedPerformanceCategoryTest_NextValueVerifyInvalidCounterNameCheck()
        {
            WindowsPerformanceLiason   liason      = new WindowsPerformanceLiason();
            WrappedPerformanceCategory ourCategory = liason.CacheCountersForCategory(CounterTestUtilities.TestCategoryName, null);

            ourCategory.NextValue("some non existent counter name");
        }
        public void WindowsPerformanceLiasonTest_VerifyIncrementByWithBaseAverageTimer32()
        {
            //// The spans need to be ever increasing number like if you used a global stopwatch
            long span1 = 1000;
            long span2 = 2000;

            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();
            //// average (time) of all measurements performed.  lets assume it was clear before we ran the test
            //// this value is probably 0 because we haven't run any in the past
            float initialValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);

            //// increment the base counters by something other than the default
            underTest.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name, span1, 4);
            underTest.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name, span2, 4);
            //// average (time) of all measurements performed.
            float finalValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            //// ((N1 - N0) / F) / (B1 - B0)
            //// how fast is our clock
            float freq        = Stopwatch.Frequency;
            float numerator   = ((float)(span2 - span1)) / freq;
            float denominator = 8 - 4;

            Assert.AreEqual(numerator / denominator, finalValue, .002, "Freq: " + freq);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// constructor that configures the thread executor
 /// </summary>
 /// <param name="liason">counter interface</param>
 /// <param name="categoryName">category name</param>
 /// <param name="counterName">counter name</param>
 /// <param name="stopflag">boolean we check to know when we are done</param>
 internal ThreadExecutor(WindowsPerformanceLiason liason, string categoryName, string counterName, bool[] stopflag)
 {
     this.liason       = liason;
     this.categoryName = categoryName;
     this.counterName  = counterName;
     this.stopflag     = stopflag;
 }
Ejemplo n.º 5
0
        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 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 WindowsPerformanceLiasonTest_VerifyIncrementBySimple64()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();
            float initialValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name);

            underTest.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name, 3);
            float finalValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name);

            Assert.AreEqual(initialValue + 3, finalValue);
        }
Ejemplo n.º 8
0
        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 WindowsPerformanceLiasonTest_GetTicks()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();
            long firstTick = underTest.StopwatchTimestamp();

            Thread.Sleep(100);
            long secondTick   = underTest.StopwatchTimestamp();
            long elapsedTicks = secondTick - firstTick;

            //// Dividing by Frequency gives you seconds but we want milliseconds
            //// Assume we're not off by more than 10 msec on a 100msec wait
            Assert.AreEqual(100, (1000 * elapsedTicks) / Stopwatch.Frequency, 10);
        }
        public void WindowsPerformanceLiasonTest_VerifySetGetNextValue()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.SetRawValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name, 0);
            float initialValue =
                underTest.GetRawValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name);

            Assert.AreEqual(0.0, initialValue, 0.001); // shouldn't need delta...
            underTest.SetRawValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name, 10);
            float finalValue =
                underTest.GetRawValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name);

            Assert.AreEqual(10.0, finalValue, 0.001);  // shouldn't need delta
        }
        public void WindowsPerformanceLiasonTest_VerifyIncrementAverageTimer32()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.Increment(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            underTest.Increment(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            float finalValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            //// ((N1 - N0) / F) / (B1 - B0)
            //// how fast is our clock
            float freq        = Stopwatch.Frequency;
            float numerator   = ((float)(2 - 1)) / freq;
            float denominator = 2 - 1;

            Assert.AreEqual(numerator / denominator, finalValue, .002, "Freq: " + freq);
        }
        public void WindowsPerformanceLiasonTest_VerifyDecrementAverageTimer32()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.Increment(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            underTest.Increment(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            underTest.Decrement(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            float finalValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            //// ((N1 - N0) / F) / (B1 - B0)
            //// how fast is our clock
            float freq = Stopwatch.Frequency;
            //// ((N1 - N0) / F)
            float numerator   = (1 - 2) / freq;
            float denominator = 3 - 2;

            Assert.AreEqual(numerator / denominator, finalValue, .002, "Freq: " + freq);
            //// the final value is actually 0 here and our calculatd value is very small, almost -0
        }
        public void WindowsPerformanceLiasonTest_VerifyIncrementByAverageTimer32()
        {
            //// The spans need to be ever increasing number like if you used a global stopwatch
            long span1 = 1000;
            long span2 = 2000;

            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            //// average (time) of all measurements performed.  lets assume it was clear before we ran the test
            underTest.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name, span1);
            underTest.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name, span2);
            //// average (time) of all measurements performed.
            float finalValue =
                underTest.NextValue(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestAverageTimer32Name);
            //// ((N1 - N0) / F) / (B1 - B0)
            //// how fast is our clock
            float freq        = Stopwatch.Frequency;
            float numerator   = ((float)(span2 - span1)) / freq;
            float denominator = 2 - 1;

            Assert.AreEqual(numerator / denominator, finalValue, .002, "Freq: " + freq);
        }
Ejemplo n.º 14
0
        public void PerformanceCounterExplorerTest_TimeIncrementVsIncrementBy()
        {
            WindowsPerformanceLiason updatableCounters = new WindowsPerformanceLiason();
            Stopwatch incrementWatcher = new Stopwatch();

            incrementWatcher.Start();
            for (int i = 0; i < 100000; i++)
            {
                updatableCounters.Increment(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name);
            }
            incrementWatcher.Stop();

            Stopwatch incrementByWatcher = new Stopwatch();

            incrementByWatcher.Start();
            for (int i = 0; i < 100000; i++)
            {
                updatableCounters.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name, 1);
            }
            incrementByWatcher.Stop();
            Assert.AreEqual(incrementWatcher.ElapsedMilliseconds, incrementByWatcher.ElapsedMilliseconds, " expected time is the 'increment', actual is 'incrementBy'");
        }
Ejemplo n.º 15
0
        public void WindowsPerformanceLiasonBoundsTest_VerifyIncrementByEmptyCategoryCheck()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.IncrementBy(string.Empty, CounterTestUtilities.TestCounterNumberOfItems64Name, 3);
        }
Ejemplo n.º 16
0
        public void WindowsPerformanceLiasonBoundsTest_VerifyDecrementEmptyCounterCheck()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.Decrement(CounterTestUtilities.TestCategoryName, string.Empty);
        }
Ejemplo n.º 17
0
        public void WindowsPerformanceLiasonBoundsTest_VerifyGetRawValueEmptyCategoryCheck()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.GetRawValue(string.Empty, CounterTestUtilities.TestCounterNumberOfItems64Name);
        }
Ejemplo n.º 18
0
        public void WindowsPerformanceLiasonBoundsTest_VerifyGetRawValueEmptyCounterCheck()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.GetRawValue(CounterTestUtilities.TestCategoryName, string.Empty);
        }
 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);
 }
Ejemplo n.º 21
0
        public void WindowsPerformanceLiasonBoundsTest_VerifyIncrementByCounterWithoutBase()
        {
            WindowsPerformanceLiason underTest = new WindowsPerformanceLiason();

            underTest.IncrementBy(CounterTestUtilities.TestCategoryName, CounterTestUtilities.TestCounterNumberOfItems64Name, 3, 3);
        }