From 16d7f3242cf4ebef0464b166493b6da2e6724146 Mon Sep 17 00:00:00 2001 From: Mingyang Zheng Date: Fri, 9 Aug 2024 15:40:01 -0700 Subject: [PATCH] fix(IOCountersWithContext): Fix the issue of not using names to filter devices in func IOCountersWithContext of the windows implementation --- disk/disk_windows.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/disk/disk_windows.go b/disk/disk_windows.go index 86d6a4e9d..9fefb1465 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -218,14 +218,17 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC if err != nil { return drivemap, err } - drivemap[path] = IOCountersStat{ - ReadBytes: uint64(diskPerformance.BytesRead), - WriteBytes: uint64(diskPerformance.BytesWritten), - ReadCount: uint64(diskPerformance.ReadCount), - WriteCount: uint64(diskPerformance.WriteCount), - ReadTime: uint64(diskPerformance.ReadTime / 10000 / 1000), // convert to ms: https://github.com/giampaolo/psutil/issues/1012 - WriteTime: uint64(diskPerformance.WriteTime / 10000 / 1000), - Name: path, + + if len(names) == 0 || common.StringsHas(names, path) { + drivemap[path] = IOCountersStat{ + ReadBytes: uint64(diskPerformance.BytesRead), + WriteBytes: uint64(diskPerformance.BytesWritten), + ReadCount: uint64(diskPerformance.ReadCount), + WriteCount: uint64(diskPerformance.WriteCount), + ReadTime: uint64(diskPerformance.ReadTime / 10000 / 1000), // convert to ms: https://github.com/giampaolo/psutil/issues/1012 + WriteTime: uint64(diskPerformance.WriteTime / 10000 / 1000), + Name: path, + } } } }