mirror of https://github.com/shirou/gopsutil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
3 years ago
|
// +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
|
||
|
}
|