Changeset 1188
- Timestamp:
- 9/16/2009 8:32:46 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/eraser6/Eraser.Util/KernelApi.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util/KernelApi.cs
r1094 r1188 277 277 return (ThreadExecutionState)NativeMethods.SetThreadExecutionState( 278 278 (NativeMethods.EXECUTION_STATE)executionState); 279 } 280 281 public class DiskPerformanceInfo 282 { 283 unsafe internal DiskPerformanceInfo(NativeMethods.DiskPerformanceInfoInternal info) 284 { 285 BytesRead = info.BytesRead; 286 BytesWritten = info.BytesWritten; 287 ReadTime = info.ReadTime; 288 WriteTime = info.WriteTime; 289 IdleTime = info.IdleTime; 290 ReadCount = info.ReadCount; 291 WriteCount = info.WriteCount; 292 QueueDepth = info.QueueDepth; 293 SplitCount = info.SplitCount; 294 QueryTime = info.QueryTime; 295 StorageDeviceNumber = info.StorageDeviceNumber; 296 StorageManagerName = new string((char*)info.StorageManagerName); 297 } 298 299 public long BytesRead { get; private set; } 300 public long BytesWritten { get; private set; } 301 public long ReadTime { get; private set; } 302 public long WriteTime { get; private set; } 303 public long IdleTime { get; private set; } 304 public uint ReadCount { get; private set; } 305 public uint WriteCount { get; private set; } 306 public uint QueueDepth { get; private set; } 307 public uint SplitCount { get; private set; } 308 public long QueryTime { get; private set; } 309 public uint StorageDeviceNumber { get; private set; } 310 public string StorageManagerName { get; private set; } 311 } 312 313 /// <summary> 314 /// Queries the performance information for the given disk. 315 /// </summary> 316 /// <param name="diskHandle">A read-only handle to a device (disk).</param> 317 /// <returns>A DiskPerformanceInfo structure describing the performance 318 /// information for the given disk.</returns> 319 public static DiskPerformanceInfo QueryDiskPerformanceInfo(SafeFileHandle diskHandle) 320 { 321 if (diskHandle.IsInvalid) 322 throw new ArgumentException("The disk handle must not be invalid."); 323 324 //This only works if the user has turned on the disk performance 325 //counters with 'diskperf -y'. These counters are off by default 326 NativeMethods.DiskPerformanceInfoInternal result = 327 new NativeMethods.DiskPerformanceInfoInternal(); 328 uint bytesReturned = 0; 329 if (NativeMethods.DeviceIoControl(diskHandle, NativeMethods.IOCTL_DISK_PERFORMANCE, 330 IntPtr.Zero, 0, out result, (uint)Marshal.SizeOf(result), out bytesReturned, IntPtr.Zero)) 331 { 332 return new DiskPerformanceInfo(result); 333 } 334 335 return null; 279 336 } 280 337 … … 601 658 public const ushort COMPRESSION_FORMAT_DEFAULT = 0x0001; 602 659 603 660 [DllImport("Kernel32.dll", SetLastError = true)] 661 [return: MarshalAs(UnmanagedType.Bool)] 662 public extern static bool DeviceIoControl(SafeFileHandle hDevice, 663 uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, 664 out DiskPerformanceInfoInternal lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned, 665 IntPtr lpOverlapped); 666 667 public const uint IOCTL_DISK_PERFORMANCE = ((0x00000007) << 16) | ((0x0008) << 2); 668 669 public unsafe struct DiskPerformanceInfoInternal 670 { 671 public long BytesRead; 672 public long BytesWritten; 673 public long ReadTime; 674 public long WriteTime; 675 public long IdleTime; 676 public uint ReadCount; 677 public uint WriteCount; 678 public uint QueueDepth; 679 public uint SplitCount; 680 public long QueryTime; 681 public uint StorageDeviceNumber; 682 public fixed short StorageManagerName[8]; 683 } 684 604 685 /// <summary> 605 686 /// Retrieves a set of FAT file system attributes for a specified file or
Note: See TracChangeset
for help on using the changeset viewer.
