Пример #1
0
        private static bool GetTimes(out long[] idle, out long[] total)
        {
            SystemProcessorPerformanceInformation[] informations = new SystemProcessorPerformanceInformation[64];

            int size = Marshal.SizeOf(typeof(SystemProcessorPerformanceInformation));

            idle  = null;
            total = null;

            IntPtr returnLength;

            if (NativeMethods.NtQuerySystemInformation(SystemInformationClass.SystemProcessorPerformanceInformation,
                                                       informations, informations.Length * size, out returnLength) != 0)
            {
                return(false);
            }

            idle  = new long[(int)returnLength / size];
            total = new long[(int)returnLength / size];

            for (int i = 0; i < idle.Length; i++)
            {
                idle[i]  = informations[i].IdleTime;
                total[i] = informations[i].KernelTime + informations[i].UserTime;
            }

            return(true);
        }
Пример #2
0
    private static bool GetTimes(out long[] idle, out long[] total) {      
      SystemProcessorPerformanceInformation[] informations = new
        SystemProcessorPerformanceInformation[64];

      int size = Marshal.SizeOf(typeof(SystemProcessorPerformanceInformation));

      idle = null;
      total = null;

      IntPtr returnLength;
      if (NativeMethods.NtQuerySystemInformation(
        SystemInformationClass.SystemProcessorPerformanceInformation,
        informations, informations.Length * size, out returnLength) != 0)
        return false;

      idle = new long[(int)returnLength / size];
      total = new long[(int)returnLength / size];

      for (int i = 0; i < idle.Length; i++) {
        idle[i] = informations[i].IdleTime;
        total[i] = informations[i].KernelTime + informations[i].UserTime;
      }

      return true;
    }
Пример #3
0
        private static long[] GetIdleTimes()
        {
            SystemProcessorPerformanceInformation[] informations = new
                                                                   SystemProcessorPerformanceInformation[64];

            int size = Marshal.SizeOf(typeof(SystemProcessorPerformanceInformation));

            IntPtr returnLength;

            if (NativeMethods.NtQuerySystemInformation(
                    SystemInformationClass.SystemProcessorPerformanceInformation,
                    informations, informations.Length * size, out returnLength) != 0)
            {
                return(null);
            }

            long[] result = new long[(int)returnLength / size];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = informations[i].IdleTime;
            }

            return(result);
        }
Пример #4
0
        private long[] GetIdleTimes()
        {
            long[] result = new long[coreCount * logicalProcessorsPerCore];
            SystemProcessorPerformanceInformation[] informations = new
                                                                   SystemProcessorPerformanceInformation[result.Length];

            IntPtr returnLength;

            NtQuerySystemInformation(
                SystemInformationClass.SystemProcessorPerformanceInformation,
                informations, informations.Length *
                Marshal.SizeOf(typeof(SystemProcessorPerformanceInformation)),
                out returnLength);

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = informations[i].IdleTime;
            }

            return(result);
        }