Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
2ab7b00f
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,发现更多精彩内容 >>
提交
2ab7b00f
编写于
5月 01, 2014
作者:
S
Shirou WAKAYAMA
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implements Process.NumCtxSwitches() on linux.
上级
70f7f517
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
51 addition
and
18 deletion
+51
-18
README.rst
README.rst
+1
-1
process.go
process.go
+10
-0
process_freebsd.go
process_freebsd.go
+2
-2
process_linux.go
process_linux.go
+26
-13
process_test.go
process_test.go
+10
-0
process_windows.go
process_windows.go
+2
-2
未找到文件。
README.rst
浏览文件 @
2ab7b00f
...
...
@@ -88,6 +88,7 @@ Current Status
- io_counters (linux)
- nice (linux)
- num_fds (linux)
- num_ctx_switches (linux)
- num_threads (linux, freebsd, windows)
- cpu_times (linux)
- memory_info (linux, freebsd)
...
...
@@ -110,7 +111,6 @@ Current Status
- username
- ionice
- rlimit
- num_ctx_switches
- num_handlers
- threads
- cpu_percent
...
...
process.go
浏览文件 @
2ab7b00f
...
...
@@ -31,6 +31,11 @@ type IOCountersStat struct {
WriteBytes
int32
`json:"write_bytes"`
}
type
NumCtxSwitchesStat
struct
{
Voluntary
int32
`json:"voluntary"`
Involuntary
int32
`json:"involuntary"`
}
func
(
p
Process
)
String
()
string
{
s
,
_
:=
json
.
Marshal
(
p
)
return
string
(
s
)
...
...
@@ -56,6 +61,11 @@ func (i IOCountersStat) String() string {
return
string
(
s
)
}
func
(
p
NumCtxSwitchesStat
)
String
()
string
{
s
,
_
:=
json
.
Marshal
(
p
)
return
string
(
s
)
}
func
PidExists
(
pid
int32
)
(
bool
,
error
)
{
pids
,
err
:=
Pids
()
if
err
!=
nil
{
...
...
process_freebsd.go
浏览文件 @
2ab7b00f
...
...
@@ -124,8 +124,8 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
func
(
p
*
Process
)
IOCounters
()
(
*
IOCountersStat
,
error
)
{
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
NumCtxSwitches
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
func
(
p
*
Process
)
NumCtxSwitches
()
(
*
NumCtxSwitchesStat
,
error
)
{
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
NumFDs
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
...
...
process_linux.go
浏览文件 @
2ab7b00f
...
...
@@ -3,6 +3,7 @@
package
gopsutil
import
(
"encoding/json"
"errors"
"io/ioutil"
"os"
...
...
@@ -10,7 +11,6 @@ import (
"strconv"
"strings"
"syscall"
"encoding/json"
)
const
(
...
...
@@ -27,6 +27,7 @@ type MemoryInfoExStat struct {
Data
uint64
`json:"data"`
// bytes
Dirty
uint64
`json:"dirty"`
// bytes
}
func
(
m
MemoryInfoExStat
)
String
()
string
{
s
,
_
:=
json
.
Marshal
(
m
)
return
string
(
s
)
...
...
@@ -51,8 +52,6 @@ func (m MemoryMapsStat) String() string {
return
string
(
s
)
}
// Create new Process instance
// This only stores Pid
func
NewProcess
(
pid
int32
)
(
*
Process
,
error
)
{
...
...
@@ -70,7 +69,7 @@ func (p *Process) Ppid() (int32, error) {
return
ppid
,
nil
}
func
(
p
*
Process
)
Name
()
(
string
,
error
)
{
name
,
_
,
_
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
name
,
_
,
_
,
_
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -97,7 +96,7 @@ func (p *Process) Parent() (*Process, error) {
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
Status
()
(
string
,
error
)
{
_
,
status
,
_
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
_
,
status
,
_
,
_
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -107,14 +106,14 @@ func (p *Process) Username() (string, error) {
return
""
,
nil
}
func
(
p
*
Process
)
Uids
()
([]
int32
,
error
)
{
_
,
_
,
uids
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
_
,
_
,
uids
,
_
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
if
err
!=
nil
{
return
nil
,
err
}
return
uids
,
nil
}
func
(
p
*
Process
)
Gids
()
([]
int32
,
error
)
{
_
,
_
,
_
,
gids
,
_
,
err
:=
p
.
fillFromStatus
()
_
,
_
,
_
,
gids
,
_
,
_
,
err
:=
p
.
fillFromStatus
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -143,14 +142,18 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
func
(
p
*
Process
)
IOCounters
()
(
*
IOCountersStat
,
error
)
{
return
p
.
fillFromIO
()
}
func
(
p
*
Process
)
NumCtxSwitches
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
func
(
p
*
Process
)
NumCtxSwitches
()
(
*
NumCtxSwitchesStat
,
error
)
{
_
,
_
,
_
,
_
,
_
,
numCtxSwitches
,
err
:=
p
.
fillFromStatus
()
if
err
!=
nil
{
return
nil
,
err
}
return
numCtxSwitches
,
nil
}
func
(
p
*
Process
)
NumFDs
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
NumThreads
()
(
int32
,
error
)
{
_
,
_
,
_
,
_
,
numThreads
,
err
:=
p
.
fillFromStatus
()
_
,
_
,
_
,
_
,
numThreads
,
_
,
err
:=
p
.
fillFromStatus
()
if
err
!=
nil
{
return
0
,
err
}
...
...
@@ -407,18 +410,20 @@ func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
}
// Get various status from /proc/(pid)/status
func
(
p
*
Process
)
fillFromStatus
()
(
string
,
string
,
[]
int32
,
[]
int32
,
int32
,
error
)
{
func
(
p
*
Process
)
fillFromStatus
()
(
string
,
string
,
[]
int32
,
[]
int32
,
int32
,
*
NumCtxSwitchesStat
,
error
)
{
pid
:=
p
.
Pid
statPath
:=
filepath
.
Join
(
"/"
,
"proc"
,
strconv
.
Itoa
(
int
(
pid
)),
"status"
)
contents
,
err
:=
ioutil
.
ReadFile
(
statPath
)
if
err
!=
nil
{
return
""
,
""
,
nil
,
nil
,
0
,
err
return
""
,
""
,
nil
,
nil
,
0
,
nil
,
err
}
lines
:=
strings
.
Split
(
string
(
contents
),
"
\n
"
)
name
:=
""
status
:=
""
var
numThreads
int32
var
vol
int32
var
unvol
int32
var
uids
[]
int32
var
gids
[]
int32
for
_
,
line
:=
range
lines
{
...
...
@@ -446,10 +451,18 @@ func (p *Process) fillFromStatus() (string, string, []int32, []int32, int32, err
}
case
"Threads"
:
numThreads
=
parseInt32
(
field
[
1
])
case
"voluntary_ctxt_switches"
:
vol
=
parseInt32
(
field
[
1
])
case
"nonvoluntary_ctxt_switches"
:
unvol
=
parseInt32
(
field
[
1
])
}
}
return
name
,
status
,
uids
,
gids
,
numThreads
,
nil
numctx
:=
&
NumCtxSwitchesStat
{
Voluntary
:
vol
,
Involuntary
:
unvol
,
}
return
name
,
status
,
uids
,
gids
,
numThreads
,
numctx
,
nil
}
func
(
p
*
Process
)
fillFromStat
()
(
string
,
int32
,
*
CPUTimesStat
,
int64
,
int32
,
error
)
{
...
...
process_test.go
浏览文件 @
2ab7b00f
...
...
@@ -101,3 +101,13 @@ func Test_Process_IOCounters(t *testing.T) {
fmt
.
Println
(
v
)
}
func
Test_Process_NumCtx
(
t
*
testing
.
T
)
{
p
:=
test_getProcess
()
_
,
err
:=
p
.
NumCtxSwitches
()
if
err
!=
nil
{
t
.
Errorf
(
"geting numctx error %v"
,
err
)
return
}
}
process_windows.go
浏览文件 @
2ab7b00f
...
...
@@ -111,8 +111,8 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
func
(
p
*
Process
)
IOCounters
()
(
*
IOCountersStat
,
error
)
{
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
NumCtxSwitches
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
func
(
p
*
Process
)
NumCtxSwitches
()
(
*
NumCtxSwitchesStat
,
error
)
{
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
NumFDs
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录