Beispiel #1
0
        private DISK_PERFORMANCE[] GetDiskCounters()
        {
            DISK_PERFORMANCE[] diskStats = new DISK_PERFORMANCE[m_drives.Length];
            for (int i = 0; i < m_drives.Length; i++)
            {
                var drive = m_drives[i];
                if (!drive.Item2.IsClosed && !drive.Item2.IsInvalid)
                {
                    uint             bytesReturned;
                    DISK_PERFORMANCE diskPerf = default(DISK_PERFORMANCE);

                    try
                    {
                        bool result = DeviceIoControl(drive.Item2, IOCTL_DISK_PERFORMANCE,
                                                      inputBuffer: IntPtr.Zero,
                                                      inputBufferSize: 0,
                                                      outputBuffer: out diskPerf,
                                                      outputBufferSize: Marshal.SizeOf(typeof(DISK_PERFORMANCE)),
                                                      bytesReturned: out bytesReturned,
                                                      overlapped: IntPtr.Zero);
                        if (result)
                        {
                            diskStats[i] = diskPerf;
                        }
                    }
                    catch (ObjectDisposedException)
                    {
                        // Occasionally the handle is disposed even though it's checked against being closed and valid
                        // above. In those cases, just catch the failure and continue on to avoid crashes
                    }
                }
            }

            return(diskStats);
        }
Beispiel #2
0
 public static extern bool DeviceIoControl(
     SafeFileHandle deviceHandle,
     uint ioControlCode,
     IntPtr inputBuffer,
     int inputBufferSize,
     out DISK_PERFORMANCE outputBuffer,
     int outputBufferSize,
     out uint bytesReturned,
     IntPtr overlapped);
Beispiel #3
0
        public DrivePerformanceValues ReadThroughputValues()
        {
            if (handle.IsClosed)
            {
                throw new ObjectDisposedException("WindowsATASmart");
            }
            DISK_PERFORMANCE dpf = new DISK_PERFORMANCE();
            int size             = Marshal.SizeOf <DISK_PERFORMANCE>();
            int sizeUsed         = 0;

            if (NativeMethods.DeviceIoControl(handle, DriveCommand.DiskPerformance, IntPtr.Zero, 0, ref dpf, size, out sizeUsed, IntPtr.Zero) && sizeUsed >= size)
            {
                return(new DrivePerformanceValues(dpf));
            }

            return(null);
        }
Beispiel #4
0
 public static extern bool DeviceIoControl(SafeHandle handle,
                                           DriveCommand command, IntPtr inBuffer, int inputSize, ref DISK_PERFORMANCE performance,
                                           int resultSize,
                                           out int bytesReturned, IntPtr overlapped);
Beispiel #5
0
 /// <nodoc/>
 public DiskStats(double?availableDiskSpace = null, DISK_PERFORMANCE diskPerformance = default(DISK_PERFORMANCE))
 {
     IsValid          = true;
     AvailableSpaceGb = availableDiskSpace;
     DiskPerformance  = diskPerformance;
 }