Example #1
0
        /// <summary>
        /// Prints only the option name, counter name and counter value
        /// </summary>
        /// <param name="counter">Uses a CounterManager object to get the counter data</param>
        public static void PrintMinimalCounter(CounterManager counter)
        {
            string counterLine;

            while (true)
            {
                try
                {
                    if (counter.SetCounterAsReady() && string.IsNullOrEmpty(counter.options.Name))
                    {
                        counterLine = counter.options.CategoryName + " \\ " + counter.options.CounterName + " : " +
                                      counter.GetCounterValue();
                    }
                    else
                    {
                        counterLine = counter.options.Name + ": " + counter.options.CategoryName + " \\ " +
                                      counter.options.CounterName + " : " + counter.GetCounterValue();
                    }

                    Console.WriteLine(counterLine);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Tests one Performance Counter for 10 iterations
        /// </summary>
        /// <param name="performanceCounter"></param>
        public static void TestRunSinglePerformanceCounter(PerformanceCounter performanceCounter)
        {
            // Bind the PerformanceCounter to a manager
            var    manager = new CounterManager(performanceCounter);
            string value   = null;
            var    values  = new List <string>();

            performanceCounter.NextValue();
            var count = 0;

            while (count < 10)
            {
                value = manager.GetCounterValue();
                Console.WriteLine(performanceCounter.NextValue());
                values.Add(value);
                Thread.Sleep(1000);
                count++;
            }
        }