Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
4d4bd26b
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,发现更多精彩内容 >>
提交
4d4bd26b
编写于
6月 16, 2015
作者:
H
Hideo Hattori
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement NumThreads on darwin. use ps command
上级
72772e9a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
9 deletion
+15
-9
process/process_darwin.go
process/process_darwin.go
+15
-9
未找到文件。
process/process_darwin.go
浏览文件 @
4d4bd26b
...
...
@@ -43,7 +43,7 @@ type MemoryMapsStat struct {
func
Pids
()
([]
int32
,
error
)
{
var
ret
[]
int32
pids
,
err
:=
callPs
(
"pid"
,
0
)
pids
,
err
:=
callPs
(
"pid"
,
0
,
false
)
if
err
!=
nil
{
return
ret
,
err
}
...
...
@@ -60,7 +60,7 @@ func Pids() ([]int32, error) {
}
func
(
p
*
Process
)
Ppid
()
(
int32
,
error
)
{
r
,
err
:=
callPs
(
"ppid"
,
p
.
Pid
)
r
,
err
:=
callPs
(
"ppid"
,
p
.
Pid
,
false
)
v
,
err
:=
strconv
.
Atoi
(
r
[
0
][
0
])
if
err
!=
nil
{
return
0
,
err
...
...
@@ -80,7 +80,7 @@ func (p *Process) Exe() (string, error) {
return
""
,
common
.
NotImplementedError
}
func
(
p
*
Process
)
Cmdline
()
(
string
,
error
)
{
r
,
err
:=
callPs
(
"command"
,
p
.
Pid
)
r
,
err
:=
callPs
(
"command"
,
p
.
Pid
,
false
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -96,7 +96,7 @@ func (p *Process) Parent() (*Process, error) {
return
p
,
common
.
NotImplementedError
}
func
(
p
*
Process
)
Status
()
(
string
,
error
)
{
r
,
err
:=
callPs
(
"state"
,
p
.
Pid
)
r
,
err
:=
callPs
(
"state"
,
p
.
Pid
,
false
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -167,8 +167,6 @@ func (p *Process) NumFDs() (int32, error) {
return
0
,
common
.
NotImplementedError
}
func
(
p
*
Process
)
NumThreads
()
(
int32
,
error
)
{
return
0
,
common
.
NotImplementedError
/*
k, err := p.getKProc()
if err != nil {
...
...
@@ -177,6 +175,12 @@ func (p *Process) NumThreads() (int32, error) {
return k.KiNumthreads, nil
*/
r
,
err
:=
callPs
(
"utime,stime"
,
p
.
Pid
,
true
)
if
err
!=
nil
{
return
0
,
err
}
return
int32
(
len
(
r
)),
nil
}
func
(
p
*
Process
)
Threads
()
(
map
[
string
]
string
,
error
)
{
ret
:=
make
(
map
[
string
]
string
,
0
)
...
...
@@ -209,7 +213,7 @@ func convertCpuTimes(s string) (ret float64, err error) {
return
float64
(
t
)
/
ClockTicks
,
nil
}
func
(
p
*
Process
)
CPUTimes
()
(
*
cpu
.
CPUTimesStat
,
error
)
{
r
,
err
:=
callPs
(
"utime,stime"
,
p
.
Pid
)
r
,
err
:=
callPs
(
"utime,stime"
,
p
.
Pid
,
false
)
utime
,
err
:=
convertCpuTimes
(
r
[
0
][
0
])
if
err
!=
nil
{
...
...
@@ -231,7 +235,7 @@ func (p *Process) CPUAffinity() ([]int32, error) {
return
nil
,
common
.
NotImplementedError
}
func
(
p
*
Process
)
MemoryInfo
()
(
*
MemoryInfoStat
,
error
)
{
r
,
err
:=
callPs
(
"rss,vsize,pagein"
,
p
.
Pid
)
r
,
err
:=
callPs
(
"rss,vsize,pagein"
,
p
.
Pid
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -374,10 +378,12 @@ func NewProcess(pid int32) (*Process, error) {
// Return value deletes Header line(you must not input wrong arg).
// And splited by Space. Caller have responsibility to manage.
// If passed arg pid is 0, get information from all process.
func
callPs
(
arg
string
,
pid
int32
)
([][]
string
,
error
)
{
func
callPs
(
arg
string
,
pid
int32
,
threadOption
bool
)
([][]
string
,
error
)
{
var
cmd
[]
string
if
pid
==
0
{
// will get from all processes.
cmd
=
[]
string
{
"-x"
,
"-o"
,
arg
}
}
else
if
threadOption
{
cmd
=
[]
string
{
"-x"
,
"-o"
,
arg
,
"-M"
,
"-p"
,
strconv
.
Itoa
(
int
(
pid
))}
}
else
{
cmd
=
[]
string
{
"-x"
,
"-o"
,
arg
,
"-p"
,
strconv
.
Itoa
(
int
(
pid
))}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录