summaryrefslogtreecommitdiff
path: root/vendor/github.com/shirou/gopsutil/v4/cpu/cpu_plan9.go
blob: 02ad3f747c8a48b47a0d22c1e13e3dbe1affdb6e (plain)
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, _ 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(_ context.Context) ([]InfoStat, error) {
	return []InfoStat{}, common.ErrNotImplementedError
}

func CountsWithContext(_ context.Context, _ bool) (int, error) {
	return runtime.NumCPU(), nil
}