mirror of
https://github.com/google/gops.git
synced 2024-11-27 08:31:17 +02:00
go.mod, vendor: update gopsutil and go-ole to fix windows/arm64 build
Update github.com/shirou/gopsutil/v3 to v3.21.9 and github.com/go-ole/go-ole to latest master to fix the build on windows/arm64.
This commit is contained in:
parent
e9831286ac
commit
f57f013e90
3
go.mod
3
go.mod
@ -3,8 +3,9 @@ module github.com/google/gops
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/go-ole/go-ole v1.2.6-0.20210915003542-8b1f7f90f6b1 // indirect
|
||||
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
|
||||
github.com/shirou/gopsutil/v3 v3.21.8
|
||||
github.com/shirou/gopsutil/v3 v3.21.9
|
||||
github.com/xlab/treeprint v1.1.0
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b
|
||||
rsc.io/goversion v1.2.0
|
||||
|
7
go.sum
7
go.sum
@ -2,14 +2,15 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO
|
||||
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.2.6-0.20210915003542-8b1f7f90f6b1 h1:4dntyT+x6QTOSCIrgczbQ+ockAEha0cfxD5Wi0iCzjY=
|
||||
github.com/go-ole/go-ole v1.2.6-0.20210915003542-8b1f7f90f6b1/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 h1:WjT3fLi9n8YWh/Ih8Q1LHAPsTqGddPcHqscN+PJ3i68=
|
||||
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/shirou/gopsutil/v3 v3.21.8 h1:nKct+uP0TV8DjjNiHanKf8SAuub+GNsbrOtM9Nl9biA=
|
||||
github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
|
||||
github.com/shirou/gopsutil/v3 v3.21.9 h1:Vn4MUz2uXhqLSiCbGFRc0DILbMVLAY92DSkT8bsYrHg=
|
||||
github.com/shirou/gopsutil/v3 v3.21.9/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
|
4
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
4
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
@ -185,7 +185,9 @@ func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}
|
||||
uintptr(unsafe.Pointer(&excepInfo)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo)
|
||||
excepInfo.renderStrings()
|
||||
excepInfo.Clear()
|
||||
err = NewErrorWithSubError(hr, excepInfo.description, excepInfo)
|
||||
}
|
||||
for i, varg := range vargs {
|
||||
n := len(params) - i - 1
|
||||
|
85
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
85
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
@ -3,6 +3,7 @@ package ole
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// DISPPARAMS are the arguments that passed to methods or property.
|
||||
@ -24,6 +25,56 @@ type EXCEPINFO struct {
|
||||
pvReserved uintptr
|
||||
pfnDeferredFillIn uintptr
|
||||
scode uint32
|
||||
|
||||
// Go-specific part. Don't move upper cos it'll break structure layout for native code.
|
||||
rendered bool
|
||||
source string
|
||||
description string
|
||||
helpFile string
|
||||
}
|
||||
|
||||
// renderStrings translates BSTR strings to Go ones so `.Error` and `.String`
|
||||
// could be safely called after `.Clear`. We need this when we can't rely on
|
||||
// a caller to call `.Clear`.
|
||||
func (e *EXCEPINFO) renderStrings() {
|
||||
e.rendered = true
|
||||
if e.bstrSource == nil {
|
||||
e.source = "<nil>"
|
||||
} else {
|
||||
e.source = BstrToString(e.bstrSource)
|
||||
}
|
||||
if e.bstrDescription == nil {
|
||||
e.description = "<nil>"
|
||||
} else {
|
||||
e.description = BstrToString(e.bstrDescription)
|
||||
}
|
||||
if e.bstrHelpFile == nil {
|
||||
e.helpFile = "<nil>"
|
||||
} else {
|
||||
e.helpFile = BstrToString(e.bstrHelpFile)
|
||||
}
|
||||
}
|
||||
|
||||
// Clear frees BSTR strings inside an EXCEPINFO and set it to NULL.
|
||||
func (e *EXCEPINFO) Clear() {
|
||||
freeBSTR := func(s *uint16) {
|
||||
// SysFreeString don't return errors and is safe for call's on NULL.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-sysfreestring
|
||||
_ = SysFreeString((*int16)(unsafe.Pointer(s)))
|
||||
}
|
||||
|
||||
if e.bstrSource != nil {
|
||||
freeBSTR(e.bstrSource)
|
||||
e.bstrSource = nil
|
||||
}
|
||||
if e.bstrDescription != nil {
|
||||
freeBSTR(e.bstrDescription)
|
||||
e.bstrDescription = nil
|
||||
}
|
||||
if e.bstrHelpFile != nil {
|
||||
freeBSTR(e.bstrHelpFile)
|
||||
e.bstrHelpFile = nil
|
||||
}
|
||||
}
|
||||
|
||||
// WCode return wCode in EXCEPINFO.
|
||||
@ -38,48 +89,30 @@ func (e EXCEPINFO) SCODE() uint32 {
|
||||
|
||||
// String convert EXCEPINFO to string.
|
||||
func (e EXCEPINFO) String() string {
|
||||
var src, desc, hlp string
|
||||
if e.bstrSource == nil {
|
||||
src = "<nil>"
|
||||
} else {
|
||||
src = BstrToString(e.bstrSource)
|
||||
if !e.rendered {
|
||||
e.renderStrings()
|
||||
}
|
||||
|
||||
if e.bstrDescription == nil {
|
||||
desc = "<nil>"
|
||||
} else {
|
||||
desc = BstrToString(e.bstrDescription)
|
||||
}
|
||||
|
||||
if e.bstrHelpFile == nil {
|
||||
hlp = "<nil>"
|
||||
} else {
|
||||
hlp = BstrToString(e.bstrHelpFile)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
|
||||
e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
|
||||
e.wCode, e.source, e.description, e.helpFile, e.dwHelpContext, e.scode,
|
||||
)
|
||||
}
|
||||
|
||||
// Error implements error interface and returns error string.
|
||||
func (e EXCEPINFO) Error() string {
|
||||
if e.bstrDescription != nil {
|
||||
return strings.TrimSpace(BstrToString(e.bstrDescription))
|
||||
if !e.rendered {
|
||||
e.renderStrings()
|
||||
}
|
||||
|
||||
src := "Unknown"
|
||||
if e.bstrSource != nil {
|
||||
src = BstrToString(e.bstrSource)
|
||||
if e.description != "<nil>" {
|
||||
return strings.TrimSpace(e.description)
|
||||
}
|
||||
|
||||
code := e.scode
|
||||
if e.wCode != 0 {
|
||||
code = uint32(e.wCode)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v: %#x", src, code)
|
||||
return fmt.Sprintf("%v: %#x", e.source, code)
|
||||
}
|
||||
|
||||
// PARAMDATA defines parameter data type.
|
||||
|
4
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
4
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
@ -84,13 +84,13 @@ func (sac *SafeArrayConversion) ToValueArray() (values []interface{}) {
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_BSTR:
|
||||
var v string
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
v , _ := safeArrayGetElementString(sac.Array, i)
|
||||
values[i] = v
|
||||
case VT_VARIANT:
|
||||
var v VARIANT
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v.Value()
|
||||
v.Clear()
|
||||
default:
|
||||
// TODO
|
||||
}
|
||||
|
11
vendor/github.com/go-ole/go-ole/variant_arm.go
generated
vendored
Normal file
11
vendor/github.com/go-ole/go-ole/variant_arm.go
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// +build arm
|
||||
|
||||
package ole
|
||||
|
||||
type VARIANT struct {
|
||||
VT VT // 2
|
||||
wReserved1 uint16 // 4
|
||||
wReserved2 uint16 // 6
|
||||
wReserved3 uint16 // 8
|
||||
Val int64 // 16
|
||||
}
|
13
vendor/github.com/go-ole/go-ole/variant_arm64.go
generated
vendored
Normal file
13
vendor/github.com/go-ole/go-ole/variant_arm64.go
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
//go:build arm64
|
||||
// +build arm64
|
||||
|
||||
package ole
|
||||
|
||||
type VARIANT struct {
|
||||
VT VT // 2
|
||||
wReserved1 uint16 // 4
|
||||
wReserved2 uint16 // 6
|
||||
wReserved3 uint16 // 8
|
||||
Val int64 // 16
|
||||
_ [8]byte // 24
|
||||
}
|
22
vendor/github.com/go-ole/go-ole/variant_date_arm.go
generated
vendored
Normal file
22
vendor/github.com/go-ole/go-ole/variant_date_arm.go
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// +build windows,arm
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||
func GetVariantDate(value uint64) (time.Time, error) {
|
||||
var st syscall.Systemtime
|
||||
v1 := uint32(value)
|
||||
v2 := uint32(value >> 32)
|
||||
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||
if r != 0 {
|
||||
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||
}
|
||||
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||
}
|
23
vendor/github.com/go-ole/go-ole/variant_date_arm64.go
generated
vendored
Normal file
23
vendor/github.com/go-ole/go-ole/variant_date_arm64.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
//go:build windows && arm64
|
||||
// +build windows,arm64
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||
func GetVariantDate(value uint64) (time.Time, error) {
|
||||
var st syscall.Systemtime
|
||||
v1 := uint32(value)
|
||||
v2 := uint32(value >> 32)
|
||||
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||
if r != 0 {
|
||||
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||
}
|
||||
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||
}
|
11
vendor/github.com/shirou/gopsutil/v3/mem/mem.go
generated
vendored
11
vendor/github.com/shirou/gopsutil/v3/mem/mem.go
generated
vendored
@ -103,3 +103,14 @@ func (m SwapMemoryStat) String() string {
|
||||
s, _ := json.Marshal(m)
|
||||
return string(s)
|
||||
}
|
||||
|
||||
type SwapDevice struct {
|
||||
Name string `json:"name"`
|
||||
UsedBytes uint64 `json:"usedBytes"`
|
||||
FreeBytes uint64 `json:"freeBytes"`
|
||||
}
|
||||
|
||||
func (m SwapDevice) String() string {
|
||||
s, _ := json.Marshal(m)
|
||||
return string(s)
|
||||
}
|
||||
|
9
vendor/github.com/shirou/gopsutil/v3/mem/mem_darwin.go
generated
vendored
9
vendor/github.com/shirou/gopsutil/v3/mem/mem_darwin.go
generated
vendored
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/shirou/gopsutil/v3/internal/common"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@ -67,3 +68,11 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func SwapDevices() ([]*SwapDevice, error) {
|
||||
return SwapDevicesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
3
vendor/github.com/shirou/gopsutil/v3/mem/mem_darwin_cgo.go
generated
vendored
3
vendor/github.com/shirou/gopsutil/v3/mem/mem_darwin_cgo.go
generated
vendored
@ -1,5 +1,4 @@
|
||||
// +build darwin
|
||||
// +build cgo
|
||||
// +build darwin,cgo
|
||||
|
||||
package mem
|
||||
|
||||
|
3
vendor/github.com/shirou/gopsutil/v3/mem/mem_darwin_nocgo.go
generated
vendored
3
vendor/github.com/shirou/gopsutil/v3/mem/mem_darwin_nocgo.go
generated
vendored
@ -1,5 +1,4 @@
|
||||
// +build darwin
|
||||
// +build !cgo
|
||||
// +build darwin,!cgo
|
||||
|
||||
package mem
|
||||
|
||||
|
8
vendor/github.com/shirou/gopsutil/v3/mem/mem_fallback.go
generated
vendored
8
vendor/github.com/shirou/gopsutil/v3/mem/mem_fallback.go
generated
vendored
@ -23,3 +23,11 @@ func SwapMemory() (*SwapMemoryStat, error) {
|
||||
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func SwapDevices() ([]*SwapDevice, error) {
|
||||
return SwapDevicesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
86
vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go
generated
vendored
86
vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go
generated
vendored
@ -3,8 +3,11 @@
|
||||
package mem
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -426,3 +429,86 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6
|
||||
|
||||
return availMemory
|
||||
}
|
||||
|
||||
const swapsFilename = "swaps"
|
||||
|
||||
// swaps file column indexes
|
||||
const (
|
||||
nameCol = 0
|
||||
// typeCol = 1
|
||||
totalCol = 2
|
||||
usedCol = 3
|
||||
// priorityCol = 4
|
||||
)
|
||||
|
||||
func SwapDevices() ([]*SwapDevice, error) {
|
||||
return SwapDevicesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
|
||||
swapsFilePath := common.HostProc(swapsFilename)
|
||||
f, err := os.Open(swapsFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return parseSwapsFile(f)
|
||||
}
|
||||
|
||||
func parseSwapsFile(r io.Reader) ([]*SwapDevice, error) {
|
||||
swapsFilePath := common.HostProc(swapsFilename)
|
||||
scanner := bufio.NewScanner(r)
|
||||
if !scanner.Scan() {
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("couldn't read file %q: %w", swapsFilePath, err)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected end-of-file in %q", swapsFilePath)
|
||||
|
||||
}
|
||||
|
||||
// Check header headerFields are as expected
|
||||
headerFields := strings.Fields(scanner.Text())
|
||||
if len(headerFields) < usedCol {
|
||||
return nil, fmt.Errorf("couldn't parse %q: too few fields in header", swapsFilePath)
|
||||
}
|
||||
if headerFields[nameCol] != "Filename" {
|
||||
return nil, fmt.Errorf("couldn't parse %q: expected %q to be %q", swapsFilePath, headerFields[nameCol], "Filename")
|
||||
}
|
||||
if headerFields[totalCol] != "Size" {
|
||||
return nil, fmt.Errorf("couldn't parse %q: expected %q to be %q", swapsFilePath, headerFields[totalCol], "Size")
|
||||
}
|
||||
if headerFields[usedCol] != "Used" {
|
||||
return nil, fmt.Errorf("couldn't parse %q: expected %q to be %q", swapsFilePath, headerFields[usedCol], "Used")
|
||||
}
|
||||
|
||||
var swapDevices []*SwapDevice
|
||||
for scanner.Scan() {
|
||||
fields := strings.Fields(scanner.Text())
|
||||
if len(fields) < usedCol {
|
||||
return nil, fmt.Errorf("couldn't parse %q: too few fields", swapsFilePath)
|
||||
}
|
||||
|
||||
totalKiB, err := strconv.ParseUint(fields[totalCol], 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't parse 'Size' column in %q: %w", swapsFilePath, err)
|
||||
}
|
||||
|
||||
usedKiB, err := strconv.ParseUint(fields[usedCol], 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't parse 'Used' column in %q: %w", swapsFilePath, err)
|
||||
}
|
||||
|
||||
swapDevices = append(swapDevices, &SwapDevice{
|
||||
Name: fields[nameCol],
|
||||
UsedBytes: usedKiB * 1024,
|
||||
FreeBytes: (totalKiB - usedKiB) * 1024,
|
||||
})
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("couldn't read file %q: %w", swapsFilePath, err)
|
||||
}
|
||||
|
||||
return swapDevices, nil
|
||||
}
|
||||
|
4
vendor/github.com/shirou/gopsutil/v3/mem/mem_openbsd_386.go
generated
vendored
4
vendor/github.com/shirou/gopsutil/v3/mem/mem_openbsd_386.go
generated
vendored
@ -1,5 +1,5 @@
|
||||
// +build openbsd
|
||||
// +build 386
|
||||
// +build openbsd,386
|
||||
|
||||
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
|
||||
// cgo -godefs mem/types_openbsd.go
|
||||
|
||||
|
4
vendor/github.com/shirou/gopsutil/v3/mem/mem_openbsd_arm64.go
generated
vendored
4
vendor/github.com/shirou/gopsutil/v3/mem/mem_openbsd_arm64.go
generated
vendored
@ -1,5 +1,5 @@
|
||||
// +build openbsd
|
||||
// +build arm64
|
||||
// +build openbsd,arm64
|
||||
|
||||
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
|
||||
// cgo -godefs mem/types_openbsd.go
|
||||
|
||||
|
84
vendor/github.com/shirou/gopsutil/v3/mem/mem_solaris.go
generated
vendored
84
vendor/github.com/shirou/gopsutil/v3/mem/mem_solaris.go
generated
vendored
@ -1,3 +1,5 @@
|
||||
// +build solaris
|
||||
|
||||
package mem
|
||||
|
||||
import (
|
||||
@ -119,3 +121,85 @@ func nonGlobalZoneMemoryCapacity() (uint64, error) {
|
||||
|
||||
return memSizeBytes, nil
|
||||
}
|
||||
|
||||
const swapsCommand = "swap"
|
||||
|
||||
// The blockSize as reported by `swap -l`. See https://docs.oracle.com/cd/E23824_01/html/821-1459/fsswap-52195.html
|
||||
const blockSize = 512
|
||||
|
||||
// swapctl column indexes
|
||||
const (
|
||||
nameCol = 0
|
||||
// devCol = 1
|
||||
// swaploCol = 2
|
||||
totalBlocksCol = 3
|
||||
freeBlocksCol = 4
|
||||
)
|
||||
|
||||
func SwapDevices() ([]*SwapDevice, error) {
|
||||
return SwapDevicesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
|
||||
swapsCommandPath, err := exec.LookPath(swapsCommand)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not find command %q: %w", swapCommand, err)
|
||||
}
|
||||
output, err := invoke.CommandWithContext(swapsCommandPath, "-l")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not execute %q: %w", swapsCommand, err)
|
||||
}
|
||||
|
||||
return parseSwapsCommandOutput(string(output))
|
||||
}
|
||||
|
||||
func parseSwapsCommandOutput(output string) ([]*SwapDevice, error) {
|
||||
lines := strings.Split(output, "\n")
|
||||
if len(lines) == 0 {
|
||||
return nil, fmt.Errorf("could not parse output of %q: no lines in %q", swapsCommand, output)
|
||||
}
|
||||
|
||||
// Check header headerFields are as expected.
|
||||
headerFields := strings.Fields(lines[0])
|
||||
if len(headerFields) < freeBlocksCol {
|
||||
return nil, fmt.Errorf("couldn't parse %q: too few fields in header %q", swapsCommand, lines[0])
|
||||
}
|
||||
if headerFields[nameCol] != "swapfile" {
|
||||
return nil, fmt.Errorf("couldn't parse %q: expected %q to be %q", swapsCommand, headerFields[nameCol], "swapfile")
|
||||
}
|
||||
if headerFields[totalBlocksCol] != "blocks" {
|
||||
return nil, fmt.Errorf("couldn't parse %q: expected %q to be %q", swapsCommand, headerFields[totalBlocksCol], "blocks")
|
||||
}
|
||||
if headerFields[freeBlocksCol] != "free" {
|
||||
return nil, fmt.Errorf("couldn't parse %q: expected %q to be %q", swapsCommand, headerFields[freeBlocksCol], "free")
|
||||
}
|
||||
|
||||
var swapDevices []*SwapDevice
|
||||
for _, line := range lines[1:] {
|
||||
if line == "" {
|
||||
continue // the terminal line is typically empty
|
||||
}
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < freeBlocksCol {
|
||||
return nil, fmt.Errorf("couldn't parse %q: too few fields", swapsCommand)
|
||||
}
|
||||
|
||||
totalBlocks, err := strconv.ParseUint(fields[totalBlocksCol], 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't parse 'Size' column in %q: %w", swapsCommand, err)
|
||||
}
|
||||
|
||||
freeBlocks, err := strconv.ParseUint(fields[freeBlocksCol], 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't parse 'Used' column in %q: %w", swapsCommand, err)
|
||||
}
|
||||
|
||||
swapDevices = append(swapDevices, &SwapDevice{
|
||||
Name: fields[nameCol],
|
||||
UsedBytes: (totalBlocks - freeBlocks) * blockSize,
|
||||
FreeBytes: freeBlocks * blockSize,
|
||||
})
|
||||
}
|
||||
|
||||
return swapDevices, nil
|
||||
}
|
||||
|
69
vendor/github.com/shirou/gopsutil/v3/mem/mem_windows.go
generated
vendored
69
vendor/github.com/shirou/gopsutil/v3/mem/mem_windows.go
generated
vendored
@ -4,6 +4,8 @@ package mem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/shirou/gopsutil/v3/internal/common"
|
||||
@ -11,8 +13,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
|
||||
procEnumPageFilesW = common.ModPsapi.NewProc("EnumPageFilesW")
|
||||
procGetNativeSystemInfo = common.Modkernel32.NewProc("GetNativeSystemInfo")
|
||||
procGetPerformanceInfo = common.ModPsapi.NewProc("GetPerformanceInfo")
|
||||
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
|
||||
)
|
||||
|
||||
type memoryStatusEx struct {
|
||||
@ -96,3 +100,66 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
var (
|
||||
pageSize uint64
|
||||
pageSizeOnce sync.Once
|
||||
)
|
||||
|
||||
type systemInfo struct {
|
||||
wProcessorArchitecture uint16
|
||||
wReserved uint16
|
||||
dwPageSize uint32
|
||||
lpMinimumApplicationAddress uintptr
|
||||
lpMaximumApplicationAddress uintptr
|
||||
dwActiveProcessorMask uintptr
|
||||
dwNumberOfProcessors uint32
|
||||
dwProcessorType uint32
|
||||
dwAllocationGranularity uint32
|
||||
wProcessorLevel uint16
|
||||
wProcessorRevision uint16
|
||||
}
|
||||
|
||||
// system type as defined in https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-enum_page_file_information
|
||||
type enumPageFileInformation struct {
|
||||
cb uint32
|
||||
reserved uint32
|
||||
totalSize uint64
|
||||
totalInUse uint64
|
||||
peakUsage uint64
|
||||
}
|
||||
|
||||
func SwapDevices() ([]*SwapDevice, error) {
|
||||
return SwapDevicesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
|
||||
pageSizeOnce.Do(func() {
|
||||
var sysInfo systemInfo
|
||||
procGetNativeSystemInfo.Call(uintptr(unsafe.Pointer(&sysInfo)))
|
||||
pageSize = uint64(sysInfo.dwPageSize)
|
||||
})
|
||||
|
||||
// the following system call invokes the supplied callback function once for each page file before returning
|
||||
// see https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumpagefilesw
|
||||
var swapDevices []*SwapDevice
|
||||
result, _, _ := procEnumPageFilesW.Call(windows.NewCallback(pEnumPageFileCallbackW), uintptr(unsafe.Pointer(&swapDevices)))
|
||||
if result == 0 {
|
||||
return nil, windows.GetLastError()
|
||||
}
|
||||
|
||||
return swapDevices, nil
|
||||
}
|
||||
|
||||
// system callback as defined in https://docs.microsoft.com/en-us/windows/win32/api/psapi/nc-psapi-penum_page_file_callbackw
|
||||
func pEnumPageFileCallbackW(swapDevices *[]*SwapDevice, enumPageFileInfo *enumPageFileInformation, lpFilenamePtr *[syscall.MAX_LONG_PATH]uint16) *bool {
|
||||
*swapDevices = append(*swapDevices, &SwapDevice{
|
||||
Name: syscall.UTF16ToString((*lpFilenamePtr)[:]),
|
||||
UsedBytes: enumPageFileInfo.totalInUse * pageSize,
|
||||
FreeBytes: (enumPageFileInfo.totalSize - enumPageFileInfo.totalInUse) * pageSize,
|
||||
})
|
||||
|
||||
// return true to continue enumerating page files
|
||||
ret := true
|
||||
return &ret
|
||||
}
|
||||
|
5
vendor/github.com/shirou/gopsutil/v3/process/process_windows.go
generated
vendored
5
vendor/github.com/shirou/gopsutil/v3/process/process_windows.go
generated
vendored
@ -650,7 +650,10 @@ func (p *Process) TerminateWithContext(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (p *Process) KillWithContext(ctx context.Context) error {
|
||||
process := os.Process{Pid: int(p.Pid)}
|
||||
process, err := os.FindProcess(int(p.Pid))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return process.Kill()
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// +build windows
|
||||
//go:build (windows && amd64) || (windows && arm64)
|
||||
// +build windows,amd64 windows,arm64
|
||||
|
||||
package process
|
||||
|
@ -1,4 +1,5 @@
|
||||
// +build windows
|
||||
//go:build (windows && 386) || (windows && arm)
|
||||
// +build windows,386 windows,arm
|
||||
|
||||
package process
|
||||
|
||||
@ -90,8 +91,8 @@ func readProcessMemory(h syscall.Handle, is32BitProcess bool, address uint64, si
|
||||
|
||||
ret, _, _ := common.ProcNtWow64ReadVirtualMemory64.Call(
|
||||
uintptr(h),
|
||||
uintptr(address & 0xFFFFFFFF), //the call expects a 64-bit value
|
||||
uintptr(address >> 32),
|
||||
uintptr(address&0xFFFFFFFF), //the call expects a 64-bit value
|
||||
uintptr(address>>32),
|
||||
uintptr(unsafe.Pointer(&buffer[0])),
|
||||
uintptr(size), //the call expects a 64-bit value
|
||||
uintptr(0), //but size is 32-bit so pass zero as the high dword
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -1,12 +1,12 @@
|
||||
# github.com/StackExchange/wmi v1.2.1
|
||||
github.com/StackExchange/wmi
|
||||
# github.com/go-ole/go-ole v1.2.5
|
||||
# github.com/go-ole/go-ole v1.2.6-0.20210915003542-8b1f7f90f6b1
|
||||
github.com/go-ole/go-ole
|
||||
github.com/go-ole/go-ole/oleutil
|
||||
# github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
|
||||
github.com/keybase/go-ps
|
||||
github.com/keybase/go-ps/darwincgo
|
||||
# github.com/shirou/gopsutil/v3 v3.21.8
|
||||
# github.com/shirou/gopsutil/v3 v3.21.9
|
||||
github.com/shirou/gopsutil/v3/cpu
|
||||
github.com/shirou/gopsutil/v3/internal/common
|
||||
github.com/shirou/gopsutil/v3/mem
|
||||
|
Loading…
Reference in New Issue
Block a user