パフォーマンス モニターのように、パフォーマンスに関するデータを収集するプロジェクトに取り組んでいます。
ただし、ページ/秒でモニターを実行すると、パフォーマンス モニターとは異なる結果が得られます。パフォーマンス カウンターがすべての小数点以下を表示せず、平均計算が不正確になるためだと考えています。
私のコードが更新されました:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Net;
using System.Management;
using System.Net.NetworkInformation;
namespace PerformanceMonitor
{
class Program
{
static void Main(string[] args)
{
List<float> pagesSec = new List<float>();
PerformanceCounter memoryPages = new PerformanceCounter("Memory", "Pages/sec");
while (count < 50)
{
pagesSecValue = memoryPages.NextValue();
pagesSec.Add(pagesSecValue);
Console.WriteLine("Pages: " + pagesSecValue);
count++;
Thread.Sleep(1000);
Console.Clear();
}
Console.WriteLine("Avg pages/sec: " + pagesSec.Average());
Console.ReadLine();
}
}
}
プログラムの実行中、ほとんどの場合、コンソールに 0 が表示されます。
結果: 私のプログラム: 4,06349 Windows パフォーマンス モニター: 12,133
違いはなぜですか?