Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
59207b1e
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,发现更多精彩内容 >>
提交
59207b1e
编写于
5月 16, 2014
作者:
W
WAKAYAMA shirou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implements CPUInfoStat on FreeBSD.
上级
e68563b7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
14 deletion
+52
-14
cpu.go
cpu.go
+11
-11
cpu_freebsd.go
cpu_freebsd.go
+37
-0
cpu_linux.go
cpu_linux.go
+2
-2
cpu_test.go
cpu_test.go
+2
-1
未找到文件。
cpu.go
浏览文件 @
59207b1e
...
...
@@ -21,17 +21,17 @@ type CPUTimesStat struct {
}
type
CPUInfoStat
struct
{
CPU
int32
`json:"cpu"`
VendorI
d
string
`json:"vendorId"`
Family
string
`json:"family"`
Model
string
`json:"model"`
Stepping
int32
`json:"stepping"`
PhysicalID
string
`json:"physicalId"`
CoreID
string
`json:"coreId"`
Cores
int32
`json:"cores"`
ModelName
string
`json:"modelName"`
Mhz
float64
`json:"mhz"`
CacheSize
int32
`json:"cacheSize"`
CPU
int32
`json:"cpu"`
VendorI
D
string
`json:"vendorId"`
Family
string
`json:"family"`
Model
string
`json:"model"`
Stepping
int32
`json:"stepping"`
PhysicalID
string
`json:"physicalId"`
CoreID
string
`json:"coreId"`
Cores
int32
`json:"cores"`
ModelName
string
`json:"modelName"`
Mhz
float64
`json:"mhz"`
CacheSize
int32
`json:"cacheSize"`
Flags
[]
string
`json:"flags"`
}
...
...
cpu_freebsd.go
浏览文件 @
59207b1e
...
...
@@ -3,7 +3,9 @@
package
gopsutil
import
(
"regexp"
"strconv"
"strings"
)
// sys/resource.h
...
...
@@ -48,3 +50,38 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
return
ret
,
nil
}
// Returns only one CPUInfoStat on FreeBSD
func
CPUInfo
()
([]
CPUInfoStat
,
error
)
{
filename
:=
"/var/run/dmesg.boot"
lines
,
_
:=
readLines
(
filename
)
var
ret
[]
CPUInfoStat
c
:=
CPUInfoStat
{}
for
_
,
line
:=
range
lines
{
if
matches
:=
regexp
.
MustCompile
(
`CPU:\s+(.+) \(([\d.]+).+\)`
)
.
FindStringSubmatch
(
line
);
matches
!=
nil
{
c
.
ModelName
=
matches
[
1
]
c
.
Mhz
=
parseFloat64
(
matches
[
2
])
}
else
if
matches
:=
regexp
.
MustCompile
(
`Origin = "(.+)" Id = (.+) Family = (.+) Model = (.+) Stepping = (.+)`
)
.
FindStringSubmatch
(
line
);
matches
!=
nil
{
c
.
VendorID
=
matches
[
1
]
c
.
Family
=
matches
[
3
]
c
.
Model
=
matches
[
4
]
c
.
Stepping
=
parseInt32
(
matches
[
5
])
}
else
if
matches
:=
regexp
.
MustCompile
(
`Features=.+<(.+)>`
)
.
FindStringSubmatch
(
line
);
matches
!=
nil
{
for
_
,
v
:=
range
strings
.
Split
(
matches
[
1
],
","
)
{
c
.
Flags
=
append
(
c
.
Flags
,
strings
.
ToLower
(
v
))
}
}
else
if
matches
:=
regexp
.
MustCompile
(
`Features2=[a-f\dx]+<(.+)>`
)
.
FindStringSubmatch
(
line
);
matches
!=
nil
{
for
_
,
v
:=
range
strings
.
Split
(
matches
[
1
],
","
)
{
c
.
Flags
=
append
(
c
.
Flags
,
strings
.
ToLower
(
v
))
}
}
else
if
matches
:=
regexp
.
MustCompile
(
`Logical CPUs per core: (\d+)`
)
.
FindStringSubmatch
(
line
);
matches
!=
nil
{
// FIXME: no this line?
c
.
Cores
=
parseInt32
(
matches
[
1
])
}
}
return
append
(
ret
,
c
),
nil
}
cpu_linux.go
浏览文件 @
59207b1e
...
...
@@ -34,7 +34,7 @@ func CPUInfo() ([]CPUInfoStat, error) {
var
c
CPUInfoStat
for
_
,
line
:=
range
lines
{
fields
:=
strings
.
Split
(
line
,
":"
)
if
len
(
fields
)
<
2
{
if
len
(
fields
)
<
2
{
if
c
.
VendorId
!=
""
{
ret
=
append
(
ret
,
c
)
}
...
...
@@ -48,7 +48,7 @@ func CPUInfo() ([]CPUInfoStat, error) {
c
=
CPUInfoStat
{}
c
.
CPU
=
parseInt32
(
value
)
case
"vendor_id"
:
c
.
VendorI
d
=
value
c
.
VendorI
D
=
value
case
"cpu family"
:
c
.
Family
=
value
case
"model"
:
...
...
cpu_test.go
浏览文件 @
59207b1e
...
...
@@ -50,7 +50,8 @@ func TestCpuInfo(t *testing.T) {
t
.
Errorf
(
"error %v"
,
err
)
}
for
_
,
vv
:=
range
v
{
if
vv
.
ModelName
==
""
{
fmt
.
Println
(
vv
)
if
vv
.
ModelName
==
""
{
t
.
Errorf
(
"could not get CPU Info: %v"
,
vv
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录