2017-07-28 16:46:44 +00:00
|
|
|
// +build darwin
|
|
|
|
// +build cgo
|
|
|
|
|
|
|
|
package disk
|
|
|
|
|
|
|
|
/*
|
2020-03-15 08:36:59 +00:00
|
|
|
#cgo LDFLAGS: -framework CoreFoundation -framework IOKit
|
2017-07-28 16:46:44 +00:00
|
|
|
#include <stdint.h>
|
2020-03-15 08:36:59 +00:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2020-06-03 20:09:27 +00:00
|
|
|
#include "iostat_darwin.h"
|
2017-07-28 16:46:44 +00:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2018-03-06 00:52:43 +00:00
|
|
|
"context"
|
2017-07-28 16:46:44 +00:00
|
|
|
|
|
|
|
"github.com/shirou/gopsutil/internal/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
2018-03-06 00:52:43 +00:00
|
|
|
return IOCountersWithContext(context.Background(), names...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
2020-03-15 08:36:59 +00:00
|
|
|
var buf [C.NDRIVE]C.DriveStats
|
|
|
|
n, err := C.readdrivestat(&buf[0], C.int(len(buf)))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-07-28 16:46:44 +00:00
|
|
|
}
|
|
|
|
ret := make(map[string]IOCountersStat, 0)
|
2020-03-15 08:36:59 +00:00
|
|
|
for i := 0; i < int(n); i++ {
|
2017-07-28 16:46:44 +00:00
|
|
|
d := IOCountersStat{
|
2020-03-15 08:36:59 +00:00
|
|
|
ReadBytes: uint64(buf[i].read),
|
|
|
|
WriteBytes: uint64(buf[i].written),
|
|
|
|
ReadCount: uint64(buf[i].nread),
|
|
|
|
WriteCount: uint64(buf[i].nwrite),
|
|
|
|
ReadTime: uint64(buf[i].readtime / 1000 / 1000), // note: read/write time are in ns, but we want ms.
|
|
|
|
WriteTime: uint64(buf[i].writetime / 1000 / 1000),
|
|
|
|
IoTime: uint64((buf[i].readtime + buf[i].writetime) / 1000 / 1000),
|
|
|
|
Name: C.GoString(&buf[i].name[0]),
|
2017-07-28 16:46:44 +00:00
|
|
|
}
|
|
|
|
if len(names) > 0 && !common.StringsHas(names, d.Name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ret[d.Name] = d
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|