-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpu && host: fix compile time errors
- Loading branch information
Showing
7 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package cpu | ||
|
||
type cpuTimes struct { | ||
User uint64 | ||
User uint64 | ||
Nice uint64 | ||
Sys uint64 | ||
Spin uint64 | ||
Intr uint64 | ||
Intr uint64 | ||
Idle uint64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build netbsd | ||
// +build netbsd | ||
|
||
package host | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/shirou/gopsutil/v3/internal/common" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func HostIDWithContext(ctx context.Context) (string, error) { | ||
return "", common.ErrNotImplementedError | ||
} | ||
|
||
func numProcs(ctx context.Context) (uint64, error) { | ||
return 0, common.ErrNotImplementedError | ||
} | ||
|
||
func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { | ||
platform := "" | ||
family := "" | ||
version := "" | ||
|
||
p, err := unix.Sysctl("kern.ostype") | ||
if err == nil { | ||
platform = strings.ToLower(p) | ||
} | ||
v, err := unix.Sysctl("kern.osrelease") | ||
if err == nil { | ||
version = strings.ToLower(v) | ||
} | ||
|
||
return platform, family, version, nil | ||
} | ||
|
||
func VirtualizationWithContext(ctx context.Context) (string, string, error) { | ||
return "", "", common.ErrNotImplementedError | ||
} | ||
|
||
func UsersWithContext(ctx context.Context) ([]UserStat, error) { | ||
var ret []UserStat | ||
return ret, common.ErrNotImplementedError | ||
} | ||
|
||
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) { | ||
return []TemperatureStat{}, common.ErrNotImplementedError | ||
} | ||
|
||
func KernelVersionWithContext(ctx context.Context) (string, error) { | ||
_, _, version, err := PlatformInformationWithContext(ctx) | ||
return version, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//go:build netbsd | ||
// +build netbsd | ||
|
||
package common | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"unsafe" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func DoSysctrl(mib string) ([]string, error) { | ||
cmd := exec.Command("sysctl", "-n", mib) | ||
cmd.Env = getSysctrlEnv(os.Environ()) | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return []string{}, err | ||
} | ||
v := strings.Replace(string(out), "{ ", "", 1) | ||
v = strings.Replace(string(v), " }", "", 1) | ||
values := strings.Fields(string(v)) | ||
|
||
return values, nil | ||
} | ||
|
||
func CallSyscall(mib []int32) ([]byte, uint64, error) { | ||
mibptr := unsafe.Pointer(&mib[0]) | ||
miblen := uint64(len(mib)) | ||
|
||
// get required buffer size | ||
length := uint64(0) | ||
_, _, err := unix.Syscall6( | ||
unix.SYS___SYSCTL, | ||
uintptr(mibptr), | ||
uintptr(miblen), | ||
0, | ||
uintptr(unsafe.Pointer(&length)), | ||
0, | ||
0) | ||
if err != 0 { | ||
var b []byte | ||
return b, length, err | ||
} | ||
if length == 0 { | ||
var b []byte | ||
return b, length, err | ||
} | ||
// get proc info itself | ||
buf := make([]byte, length) | ||
_, _, err = unix.Syscall6( | ||
unix.SYS___SYSCTL, | ||
uintptr(mibptr), | ||
uintptr(miblen), | ||
uintptr(unsafe.Pointer(&buf[0])), | ||
uintptr(unsafe.Pointer(&length)), | ||
0, | ||
0) | ||
if err != 0 { | ||
return buf, length, err | ||
} | ||
|
||
return buf, length, nil | ||
} |