Skip to main content

parse_diskstats

Function parse_diskstats 

Source
pub fn parse_diskstats(
    buf: &[u8],
    is_whole_disk: impl Fn(&[u8]) -> bool,
) -> DiskCounters
Expand description

Parse /proc/diskstats into cumulative host counters.

Fields 3 and 6 (1-based) are sectors read and written; a sector is always 512 bytes on Linux regardless of the device’s physical sector size. Only the whole-disk entries are counted: a partition’s counters are already included in its parent disk’s, so summing both would double every byte.

A device counts as a whole disk when /sys/block/<name> exists. Without sysfs (a fixture tree, a container with a masked /sys) fall back to a name heuristic, which is what htop’s diskio does too.