shirou_gopsutil/cpu/cpu_plan9.go

51 lines
1.1 KiB
Go
Raw Normal View History

2021-12-23 05:54:41 +08:00
//go:build plan9
2021-10-12 21:25:49 +08:00
// +build plan9
package cpu
import (
"context"
"os"
"runtime"
stats "github.com/lufia/plan9stats"
"github.com/shirou/gopsutil/v3/internal/common"
)
func Times(percpu bool) ([]TimesStat, error) {
return TimesWithContext(context.Background(), percpu)
}
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
// BUG: percpu flag is not supported yet.
root := os.Getenv("HOST_ROOT")
c, err := stats.ReadCPUType(ctx, stats.WithRootDir(root))
if err != nil {
return nil, err
}
s, err := stats.ReadCPUStats(ctx, stats.WithRootDir(root))
if err != nil {
return nil, err
}
return []TimesStat{
{
CPU: c.Name,
User: s.User.Seconds(),
System: s.Sys.Seconds(),
Idle: s.Idle.Seconds(),
},
}, nil
}
func Info() ([]InfoStat, error) {
return InfoWithContext(context.Background())
}
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
return []InfoStat{}, common.ErrNotImplementedError
}
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
return runtime.NumCPU(), nil
}