protected override float ReadCounter()
        {
            float result;

            CPUUsage.CalculateCPUUsagePercentage(this.currentProcess, ref this.lastTime, ref this.lastCPU, out result);
            return(result);
        }
예제 #2
0
        // Token: 0x0600729A RID: 29338 RVA: 0x0017B664 File Offset: 0x00179864
        private static bool InternalCalculateCPUUsagePercentage(IntPtr process, ref DateTime lastUpdatedTime, ref long lastCPU, out float cpuUsage)
        {
            cpuUsage = 0f;
            long num = 0L;

            if (!CPUUsage.InternalGetCurrentCPU(process, ref num))
            {
                return(false);
            }
            DateTime utcNow       = DateTime.UtcNow;
            long     num2         = num - lastCPU;
            double   totalSeconds = (utcNow - lastUpdatedTime).TotalSeconds;

            if (totalSeconds > 0.0)
            {
                cpuUsage = (float)((double)num2 * 1E-05 / (totalSeconds * (double)CPUUsage.processorCount));
                if (cpuUsage > 100f)
                {
                    cpuUsage = 100f;
                }
                lastUpdatedTime = utcNow;
                lastCPU         = num;
            }
            return(true);
        }
예제 #3
0
 // Token: 0x06007299 RID: 29337 RVA: 0x0017B641 File Offset: 0x00179841
 internal static bool GetCurrentCPU(IntPtr process, ref long cpuTime)
 {
     if (process == IntPtr.Zero)
     {
         throw new ArgumentNullException("process");
     }
     return(CPUUsage.InternalGetCurrentCPU(process, ref cpuTime));
 }
예제 #4
0
 // Token: 0x06007297 RID: 29335 RVA: 0x0017B611 File Offset: 0x00179811
 internal static bool CalculateCPUUsagePercentage(IntPtr process, ref DateTime lastUpdatedTime, ref long lastCPU, out float cpuUsage)
 {
     if (process == IntPtr.Zero)
     {
         throw new ArgumentNullException("process");
     }
     return(CPUUsage.InternalCalculateCPUUsagePercentage(process, ref lastUpdatedTime, ref lastCPU, out cpuUsage));
 }
예제 #5
0
 // Token: 0x06007413 RID: 29715 RVA: 0x0017F070 File Offset: 0x0017D270
 static ServerCPUUsage()
 {
     if (CPUUsage.GetCurrentCPU(ref ServerCPUUsage.lastServerCPUUsage))
     {
         ServerCPUUsage.lastUpdatedTime = DateTime.UtcNow;
         return;
     }
     ServerCPUUsage.lastServerCPUUsage = 0L;
     ServerCPUUsage.lastUpdatedTime    = DateTime.MinValue;
 }
 public ProcessCPURunningAveragePerfCounterReader() : base(10, 500U)
 {
     this.currentProcess = NativeMethods.GetCurrentProcess();
     if (CPUUsage.GetCurrentCPU(this.currentProcess, ref this.lastCPU))
     {
         this.lastTime = DateTime.UtcNow;
         return;
     }
     this.lastCPU  = 0L;
     this.lastTime = DateTime.MinValue;
 }
예제 #7
0
 // Token: 0x06007414 RID: 29716 RVA: 0x0017F0C8 File Offset: 0x0017D2C8
 private static void Refresh()
 {
     if (DateTime.UtcNow - ServerCPUUsage.lastUpdatedTime <= ServerCPUUsage.refreshInterval)
     {
         return;
     }
     lock (ServerCPUUsage.lockObject)
     {
         if (!(DateTime.UtcNow - ServerCPUUsage.lastUpdatedTime <= ServerCPUUsage.refreshInterval))
         {
             float num;
             if (CPUUsage.CalculateCPUUsagePercentage(ref ServerCPUUsage.lastUpdatedTime, ref ServerCPUUsage.lastServerCPUUsage, out num))
             {
                 ServerCPUUsage.lastServerCPUUsagePercentage = (uint)Math.Round((double)num);
             }
         }
     }
 }
예제 #8
0
 // Token: 0x06007298 RID: 29336 RVA: 0x0017B634 File Offset: 0x00179834
 internal static bool GetCurrentCPU(ref long cpuTime)
 {
     return(CPUUsage.InternalGetCurrentCPU(IntPtr.Zero, ref cpuTime));
 }
예제 #9
0
 // Token: 0x06007296 RID: 29334 RVA: 0x0017B602 File Offset: 0x00179802
 internal static bool CalculateCPUUsagePercentage(ref DateTime lastUpdatedTime, ref long lastCPU, out float cpuUsage)
 {
     return(CPUUsage.InternalCalculateCPUUsagePercentage(IntPtr.Zero, ref lastUpdatedTime, ref lastCPU, out cpuUsage));
 }