cpu_plan9.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //go:build plan9
  2. // +build plan9
  3. package cpu
  4. import (
  5. "context"
  6. "os"
  7. "runtime"
  8. stats "github.com/lufia/plan9stats"
  9. "github.com/shirou/gopsutil/v3/internal/common"
  10. )
  11. func Times(percpu bool) ([]TimesStat, error) {
  12. return TimesWithContext(context.Background(), percpu)
  13. }
  14. func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
  15. // BUG: percpu flag is not supported yet.
  16. root := os.Getenv("HOST_ROOT")
  17. c, err := stats.ReadCPUType(ctx, stats.WithRootDir(root))
  18. if err != nil {
  19. return nil, err
  20. }
  21. s, err := stats.ReadCPUStats(ctx, stats.WithRootDir(root))
  22. if err != nil {
  23. return nil, err
  24. }
  25. return []TimesStat{
  26. {
  27. CPU: c.Name,
  28. User: s.User.Seconds(),
  29. System: s.Sys.Seconds(),
  30. Idle: s.Idle.Seconds(),
  31. },
  32. }, nil
  33. }
  34. func Info() ([]InfoStat, error) {
  35. return InfoWithContext(context.Background())
  36. }
  37. func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
  38. return []InfoStat{}, common.ErrNotImplementedError
  39. }
  40. func CountsWithContext(ctx context.Context, logical bool) (int, error) {
  41. return runtime.NumCPU(), nil
  42. }