Changeset 1569


Ignore:
Timestamp:
1/18/2010 7:11:07 AM (4 years ago)
Author:
lowjoel
Message:

Moved the DiskPerformanceInfo? class to the VolumeInfo? class and that's how we can query volumes for performance information. Addresses #284: Eraser.Util rewrite

Location:
branches/eraser6/CodeReview/Eraser.Util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser.Util/NativeMethods/Kernel.cs

    r1567 r1569  
    412412        public const uint IOCTL_DISK_PERFORMANCE = ((0x00000007) << 16) | ((0x0008) << 2); 
    413413 
    414         public unsafe struct DiskPerformanceInfoInternal 
     414        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 
     415        public struct DiskPerformanceInfoInternal 
    415416        { 
    416417            public long BytesRead; 
     
    425426            public long QueryTime; 
    426427            public uint StorageDeviceNumber; 
    427             public fixed short StorageManagerName[8]; 
     428 
     429            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] 
     430            public string StorageManagerName; 
    428431        } 
    429432 
  • branches/eraser6/CodeReview/Eraser.Util/SystemInfo.cs

    r1568 r1569  
    7070            } 
    7171        } 
    72  
    73         public class DiskPerformanceInfo 
    74         { 
    75             unsafe internal DiskPerformanceInfo(NativeMethods.DiskPerformanceInfoInternal info) 
    76             { 
    77                 BytesRead = info.BytesRead; 
    78                 BytesWritten = info.BytesWritten; 
    79                 ReadTime = info.ReadTime; 
    80                 WriteTime = info.WriteTime; 
    81                 IdleTime = info.IdleTime; 
    82                 ReadCount = info.ReadCount; 
    83                 WriteCount = info.WriteCount; 
    84                 QueueDepth = info.QueueDepth; 
    85                 SplitCount = info.SplitCount; 
    86                 QueryTime = info.QueryTime; 
    87                 StorageDeviceNumber = info.StorageDeviceNumber; 
    88                 StorageManagerName = new string((char*)info.StorageManagerName); 
    89             } 
    90  
    91             public long BytesRead { get; private set; } 
    92             public long BytesWritten { get; private set; } 
    93             public long ReadTime { get; private set; } 
    94             public long WriteTime { get; private set; } 
    95             public long IdleTime { get; private set; } 
    96             public uint ReadCount { get; private set; } 
    97             public uint WriteCount { get; private set; } 
    98             public uint QueueDepth { get; private set; } 
    99             public uint SplitCount { get; private set; } 
    100             public long QueryTime { get; private set; } 
    101             public uint StorageDeviceNumber { get; private set; } 
    102             public string StorageManagerName { get; private set; } 
    103         } 
    104  
    105         /// <summary> 
    106         /// Queries the performance information for the given disk. 
    107         /// </summary> 
    108         /// <param name="diskHandle">A read-only handle to a device (disk).</param> 
    109         /// <returns>A DiskPerformanceInfo structure describing the performance 
    110         /// information for the given disk.</returns> 
    111         public static DiskPerformanceInfo QueryDiskPerformanceInfo(SafeFileHandle diskHandle) 
    112         { 
    113             if (diskHandle.IsInvalid) 
    114                 throw new ArgumentException("The disk handle must not be invalid."); 
    115  
    116             //This only works if the user has turned on the disk performance 
    117             //counters with 'diskperf -y'. These counters are off by default 
    118             NativeMethods.DiskPerformanceInfoInternal result = 
    119                 new NativeMethods.DiskPerformanceInfoInternal(); 
    120             uint bytesReturned = 0; 
    121             if (NativeMethods.DeviceIoControl(diskHandle, NativeMethods.IOCTL_DISK_PERFORMANCE, 
    122                 IntPtr.Zero, 0, out result, (uint)Marshal.SizeOf(result), out bytesReturned, IntPtr.Zero)) 
    123             { 
    124                 return new DiskPerformanceInfo(result); 
    125             } 
    126  
    127             return null; 
    128         } 
    12972    } 
    13073} 
  • branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs

    r1566 r1569  
    479479        } 
    480480 
     481        public class DiskPerformanceInfo 
     482        { 
     483            unsafe internal DiskPerformanceInfo(NativeMethods.DiskPerformanceInfoInternal info) 
     484            { 
     485                BytesRead = info.BytesRead; 
     486                BytesWritten = info.BytesWritten; 
     487                ReadTime = info.ReadTime; 
     488                WriteTime = info.WriteTime; 
     489                IdleTime = info.IdleTime; 
     490                ReadCount = info.ReadCount; 
     491                WriteCount = info.WriteCount; 
     492                QueueDepth = info.QueueDepth; 
     493                SplitCount = info.SplitCount; 
     494                QueryTime = info.QueryTime; 
     495                StorageDeviceNumber = info.StorageDeviceNumber; 
     496                StorageManagerName = new string((char*)info.StorageManagerName); 
     497            } 
     498 
     499            public long BytesRead { get; private set; } 
     500            public long BytesWritten { get; private set; } 
     501            public long ReadTime { get; private set; } 
     502            public long WriteTime { get; private set; } 
     503            public long IdleTime { get; private set; } 
     504            public uint ReadCount { get; private set; } 
     505            public uint WriteCount { get; private set; } 
     506            public uint QueueDepth { get; private set; } 
     507            public uint SplitCount { get; private set; } 
     508            public long QueryTime { get; private set; } 
     509            public uint StorageDeviceNumber { get; private set; } 
     510            public string StorageManagerName { get; private set; } 
     511        } 
     512 
     513        /// <summary> 
     514        /// Queries the performance information for the given disk. 
     515        /// </summary> 
     516        public DiskPerformanceInfo Performance 
     517        { 
     518            get 
     519            { 
     520                using (SafeFileHandle handle = OpenHandle(FileAccess.Read, 
     521                    FileShare.ReadWrite, FileOptions.None)) 
     522                { 
     523                    //Check that the handle is valid 
     524                    if (handle.IsInvalid) 
     525                        throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); 
     526 
     527                    //This only works if the user has turned on the disk performance 
     528                    //counters with 'diskperf -y'. These counters are off by default 
     529                    NativeMethods.DiskPerformanceInfoInternal result = 
     530                        new NativeMethods.DiskPerformanceInfoInternal(); 
     531                    uint bytesReturned = 0; 
     532                    if (NativeMethods.DeviceIoControl(handle, NativeMethods.IOCTL_DISK_PERFORMANCE, 
     533                        IntPtr.Zero, 0, out result, (uint)Marshal.SizeOf(result), 
     534                        out bytesReturned, IntPtr.Zero)) 
     535                    { 
     536                        return new DiskPerformanceInfo(result); 
     537                    } 
     538 
     539                    return null; 
     540                } 
     541            } 
     542        } 
     543 
    481544        public VolumeLock LockVolume(FileStream stream) 
    482545        { 
Note: See TracChangeset for help on using the changeset viewer.