コード例 #1
0
        // 单元测试,待添加TODO
#if TEST
        static void Main(string[] args)
        {
            //var counter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            //Console.WriteLine(Convert.ToString(counter.NextValue()));
            //Thread.Sleep(1000);
            //Console.WriteLine(Convert.ToString(counter.NextValue()));

            var counter = new PerformanceCounter("Memory", "Pages/sec", null);

            Console.WriteLine(Convert.ToString(counter.NextValue()));
            Thread.Sleep(10);
            Console.WriteLine(Convert.ToString(counter.NextValue()));

            var counter1 = new PerformanceCounter("Memory", "Pages/sec", null);

            Console.WriteLine(Convert.ToString(counter1.NextValue()));
            Thread.Sleep(1000);
            Console.WriteLine(Convert.ToString(counter1.NextValue()));

            WinPerfCounter winPerfCounter = new WinPerfCounter();

            winPerfCounter.initAllCounterValue();
            Thread.Sleep(1000);
            Console.WriteLine("CPU占用率:" + Convert.ToString(winPerfCounter.getProcessorCpuTime()) + "\nProcessor Queue Length:" + Convert.ToString(winPerfCounter.ProcessorQueueLengh) + "\n可用内存大小:" + Convert.ToString(winPerfCounter.MEMAvailable + "\nPage Faults" + Convert.ToString(winPerfCounter.PageFaultsPerSec) + "\nPages Input" + Convert.ToString(winPerfCounter.PagesInputPerSec)));
        }