forked from shirou/gopsutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request shirou#1155 from lufia/add-plan9-cpu
[v3][cpu] add plan9 support
- Loading branch information
Showing
14 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// +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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// +build plan9 | ||
|
||
package cpu | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
) | ||
|
||
var timesTests = []struct { | ||
mockedRootFS string | ||
stats []TimesStat | ||
}{ | ||
{ | ||
"2cores", | ||
[]TimesStat{ | ||
{ | ||
CPU: "Core i7/Xeon", | ||
User: 2780.0 / 1000.0, | ||
System: 30020.0 / 1000.0, | ||
Idle: (1412961713341830*2)/1000000000.0 - 2.78 - 30.02, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func TestTimesPlan9(t *testing.T) { | ||
origRoot := os.Getenv("HOST_ROOT") | ||
t.Cleanup(func() { | ||
os.Setenv("HOST_ROOT", origRoot) | ||
}) | ||
for _, tt := range timesTests { | ||
t.Run(tt.mockedRootFS, func(t *testing.T) { | ||
os.Setenv("HOST_ROOT", filepath.Join("testdata/plan9", tt.mockedRootFS)) | ||
stats, err := Times(false) | ||
skipIfNotImplementedErr(t, err) | ||
if err != nil { | ||
t.Errorf("error %v", err) | ||
} | ||
eps := cmpopts.EquateApprox(0, 0.00000001) | ||
if !cmp.Equal(stats, tt.stats, eps) { | ||
t.Errorf("got: %+v\nwant: %+v", stats, tt.stats) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Core i7/Xeon 2403 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
0 59251106 37524162 1208203 65907 0 0 7 100 0 | ||
1 219155408 28582838 5017097 1002072 0 0 0 98 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1633882064 1633882064926300833 2825920097745864 1999997644 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
init bootes Await 10 20 1404307210 110 20 0 116 10 10 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rc lufia Await 0 0 589160 8770 3260 0 248 10 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git-remote-https lufia Semacquire 390 310 370670 0 0 0 98368 10 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
httpd none Open 2380 29690 1404804330 0 0 0 23616 10 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters