Skip to content

Commit 8bd5bc3

Browse files
committed
Add readhexfile function
1 parent a9991e4 commit 8bd5bc3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

blockdevice/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func (fs FS) SysBlockDeviceIOStat(device string) (IODeviceStats, error) {
494494
"ioerr_cnt": &ioDeviceStats.IOErrCount,
495495
} {
496496
var val uint64
497-
val, err = util.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysDevicePath, file))
497+
val, err = util.ReadHexFromFile(fs.sys.Path(sysBlockPath, device, sysDevicePath, file))
498498
if err != nil {
499499
return IODeviceStats{}, err
500500
}

internal/util/parse.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,12 @@ func ParseBool(b string) *bool {
110110
}
111111
return &truth
112112
}
113+
114+
// ReadHexFromFile reads a file and attempts to parse a uint64 from a hexadecimal format 0xXX.
115+
func ReadHexFromFile(path string) (uint64, error) {
116+
data, err := os.ReadFile(path)
117+
if err != nil {
118+
return 0, err
119+
}
120+
return strconv.ParseUint(strings.TrimSpace(string(data[2:])), 16, 64)
121+
}

0 commit comments

Comments
 (0)