weixin_39970823 2020-11-30 12:43
浏览 0

Add disk reads/writes to OS X and Windows

147 added disk statistics, using Linux's sysfs (accessed via udev commands/structure) which included reads/writes. At the time, I couldn't find an easy way to include this information for other OS's. However, with a bit more digging I've found some more leads.

OS X has the iostat command which shows only transfers, but digging into the source code I can see that the information is pulled from the registry where a search for IOBlockStorageDriver uncovers a Statistics field with a dictionary containing the read and write values. It looks like we can start with the BSD Name of the drive (disk0, disk1, etc.) to find it in the registry. The parent of the matching bsdname entry is the IOBlockStorageDriver with the statistics.

Windows is a tougher nut to crack. There is a command line fsutil with the information, but it requires an elevated command prompt (admin priveleges) to get the info: fsutil fsinfo statistics <drive letter> I don't think we can rely on elevated privileges (especially on Windows) but it gives me hope that the information is somewhere in the system that we can get to it.

Windows also has PerfMon counters for disk I/O but they're read/write per second (so we'd have to multiply by elapsed time and maintain a cumulative counter each time the method was called, similar to what we do for CPU ticks) but they would start at zero when OSHI starts. I still think this is a better option than leaving it at zero, however, so I'll keep digging but use this as a fall back.

该提问来源于开源项目:oshi/oshi

  • 写回答

5条回答 默认 最新

  • weixin_39970823 2020-11-30 12:43
    关注

    OK, this is too easy. Having earlier investigated the PerfMon counters, I completely ignored the Win32_PerfRawData_PerfDisk_PhysicalDisk WMI class because the names were similar. However, trying out some queries, it appears that one can ignore the "per second" bit... the WMI counters report cumulatively increasing integer numbers.... (and a timestamp) so I can report these values straight out. PerfMon (which was harder to do to begin with) does the math with these numbers and the timestamp... so it actually looks like the Windows result is trivial and the OS X result is less trivial but doable.

    评论

报告相同问题?