Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
fb65e185
G
Gopsutil
项目概览
Canread
/
Gopsutil
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gopsutil
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
fb65e185
编写于
10月 23, 2021
作者:
S
shirou
提交者:
GitHub
10月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1155 from lufia/add-plan9-cpu
[v3][cpu] add plan9 support
上级
ed86f283
8f489b62
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
118 addition
and
6 deletion
+118
-6
README.md
README.md
+2
-2
v3/cpu/cpu_fallback.go
v3/cpu/cpu_fallback.go
+1
-1
v3/cpu/cpu_plan9.go
v3/cpu/cpu_plan9.go
+49
-0
v3/cpu/cpu_plan9_test.go
v3/cpu/cpu_plan9_test.go
+50
-0
v3/cpu/testdata/plan9/2cores/dev/cputype
v3/cpu/testdata/plan9/2cores/dev/cputype
+1
-0
v3/cpu/testdata/plan9/2cores/dev/sysstat
v3/cpu/testdata/plan9/2cores/dev/sysstat
+2
-0
v3/cpu/testdata/plan9/2cores/dev/time
v3/cpu/testdata/plan9/2cores/dev/time
+1
-0
v3/cpu/testdata/plan9/2cores/proc/1/status
v3/cpu/testdata/plan9/2cores/proc/1/status
+1
-0
v3/cpu/testdata/plan9/2cores/proc/331/.gitkeep
v3/cpu/testdata/plan9/2cores/proc/331/.gitkeep
+0
-0
v3/cpu/testdata/plan9/2cores/proc/54384/status
v3/cpu/testdata/plan9/2cores/proc/54384/status
+1
-0
v3/cpu/testdata/plan9/2cores/proc/54412/status
v3/cpu/testdata/plan9/2cores/proc/54412/status
+1
-0
v3/cpu/testdata/plan9/2cores/proc/72/status
v3/cpu/testdata/plan9/2cores/proc/72/status
+1
-0
v3/go.mod
v3/go.mod
+2
-1
v3/go.sum
v3/go.sum
+6
-2
未找到文件。
README.md
浏览文件 @
fb65e185
...
...
@@ -157,8 +157,8 @@ Some code is ported from Ohai. many thanks.
|name |Linux |FreeBSD |OpenBSD |macOS |Windows |Solaris |Plan 9 |
|----------------------|-------|---------|---------|--------|---------|---------|---------|
|cpu
\_
times |x |x |x |x |x | |
|
|cpu
\_
count |x |x |x |x |x | |
|
|cpu
\_
times |x |x |x |x |x | |
b
|
|cpu
\_
count |x |x |x |x |x | |
x
|
|cpu
\_
percent |x |x |x |x |x | | |
|cpu
\_
times
\_
percent |x |x |x |x |x | | |
|virtual
\_
memory |x |x |x |x |x | b |x |
...
...
v3/cpu/cpu_fallback.go
浏览文件 @
fb65e185
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly
,!plan9
package
cpu
...
...
v3/cpu/cpu_plan9.go
0 → 100644
浏览文件 @
fb65e185
// +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
}
v3/cpu/cpu_plan9_test.go
0 → 100644
浏览文件 @
fb65e185
// +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
\n
want: %+v"
,
stats
,
tt
.
stats
)
}
})
}
}
v3/cpu/testdata/plan9/2cores/dev/cputype
0 → 100644
浏览文件 @
fb65e185
Core i7/Xeon 2403
v3/cpu/testdata/plan9/2cores/dev/sysstat
0 → 100644
浏览文件 @
fb65e185
0 59251106 37524162 1208203 65907 0 0 7 100 0
1 219155408 28582838 5017097 1002072 0 0 0 98 1
v3/cpu/testdata/plan9/2cores/dev/time
0 → 100644
浏览文件 @
fb65e185
1633882064 1633882064926300833 2825920097745864 1999997644
\ No newline at end of file
v3/cpu/testdata/plan9/2cores/proc/1/status
0 → 100644
浏览文件 @
fb65e185
init bootes Await 10 20 1404307210 110 20 0 116 10 10
\ No newline at end of file
v3/cpu/testdata/plan9/2cores/proc/331/.gitkeep
0 → 100644
浏览文件 @
fb65e185
v3/cpu/testdata/plan9/2cores/proc/54384/status
0 → 100644
浏览文件 @
fb65e185
rc lufia Await 0 0 589160 8770 3260 0 248 10 10
\ No newline at end of file
v3/cpu/testdata/plan9/2cores/proc/54412/status
0 → 100644
浏览文件 @
fb65e185
git-remote-https lufia Semacquire 390 310 370670 0 0 0 98368 10 10
\ No newline at end of file
v3/cpu/testdata/plan9/2cores/proc/72/status
0 → 100644
浏览文件 @
fb65e185
httpd none Open 2380 29690 1404804330 0 0 0 23616 10 10
\ No newline at end of file
v3/go.mod
浏览文件 @
fb65e185
...
...
@@ -4,8 +4,9 @@ go 1.15
require (
github.com/StackExchange/wmi v1.2.1
github.com/google/go-cmp v0.5.6
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/lufia/plan9stats v0.0.0-202110
08203909-9b7c2b47d7c3
github.com/lufia/plan9stats v0.0.0-202110
12122336-39d0f177ccd0
github.com/stretchr/testify v1.7.0
github.com/tklauser/go-sysconf v0.3.9
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c
...
...
v3/go.sum
浏览文件 @
fb65e185
...
...
@@ -6,9 +6,13 @@ github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiU
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/lufia/plan9stats v0.0.0-202110
08203909-9b7c2b47d7c3 h1:zvvlSubuP3jgjD69jAfrprCEKZkjn0D9FpZ168E1rDc
=
github.com/lufia/plan9stats v0.0.0-202110
08203909-9b7c2b47d7c3
/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/lufia/plan9stats v0.0.0-202110
12122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4
=
github.com/lufia/plan9stats v0.0.0-202110
12122336-39d0f177ccd0
/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录