File: cpu_plan9.go

package info (click to toggle)
golang-github-shirou-gopsutil 4.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,824 kB
  • sloc: makefile: 76; ansic: 19; sh: 11
file content (51 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: BSD-3-Clause
//go:build plan9

package cpu

import (
	"context"
	"os"
	"runtime"

	stats "github.com/lufia/plan9stats"

	"github.com/shirou/gopsutil/v4/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
}