Exemplo n.º 1
0
        protected override CPUUsage NextValue()
        {
            Int64 idleTime;
            Int64 kernelTime;
            Int64 userTime;

            NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation(1)[0];

            idleTime   = sysProcessorPerfInfo.IdleTime;
            kernelTime = sysProcessorPerfInfo.KernelTime - idleTime;
            userTime   = sysProcessorPerfInfo.UserTime;

            Int64 idleTimeDiff   = idleTime - idleTimePrev;
            Int64 userTimeDiff   = userTime - userTimePrev;
            Int64 kernelTimeDiff = kernelTime - kernelTimePrev;
            Int64 totalTimeDiff  = idleTimeDiff + userTimeDiff + kernelTimeDiff;

            idleTimePrev   = idleTime;
            kernelTimePrev = kernelTime;
            userTimePrev   = userTime;

            return(new CPUUsage(
                       (Int32)(((Double)userTimeDiff / totalTimeDiff) * 100),
                       (Int32)(((Double)kernelTimeDiff / totalTimeDiff) * 100),
                       (Int32)(((Double)idleTimeDiff / totalTimeDiff) * 100)
                       ));
        }
        protected override MemoryUsage NextValue()
        {
            NtKernel.SYSTEM_PERFORMANCE_INFORMATION sysPerfInfo = NtKernel.QuerySystemPerformanceInformation();

            UInt32 pageSize = 4096;

            _commitLimit = (UInt64)(sysPerfInfo.TotalCommitLimit * pageSize);

            Int32 pageIn  = (Int32)((sysPerfInfo.PagesRead - _prevPagesRead) / ((TimeSpan)(DateTime.Now - _prevCollectTime)).TotalSeconds);
            Int32 pageOut = (Int32)((sysPerfInfo.PagefilePagesWritten - _prevPagesWritten) / ((TimeSpan)(DateTime.Now - _prevCollectTime)).TotalSeconds);

            _prevCollectTime  = DateTime.Now;
            _prevPagesRead    = sysPerfInfo.PagesRead;
            _prevPagesWritten = sysPerfInfo.PagefilePagesWritten;

            return(new MemoryUsage(
                       (UInt64)sysPerfInfo.AvailablePages * pageSize,
                       (UInt64)sysPerfInfo.TotalCommittedPages * pageSize,
                       pageIn,
                       pageOut,
                       (UInt64)sysPerfInfo.MmSystemCachePage * pageSize,
                       (UInt64)sysPerfInfo.PagedPoolUsage * pageSize,
                       (UInt64)sysPerfInfo.NonPagedPoolUsage * pageSize,
                       (UInt64)sysPerfInfo.SystemDriverPage * pageSize,
                       (UInt64)sysPerfInfo.SystemCodePage * pageSize));
        }
Exemplo n.º 3
0
 public NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] ProcessorPerformances()
 {
     return(NtKernel.QuerySystemProcessorPerformanceInfomation(processorCount));
 }
Exemplo n.º 4
0
 protected MachineStatus()
 {
     NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation();
     processorCount = info.NumberProcessors;
 }