Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
400054f2
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,发现更多精彩内容 >>
提交
400054f2
编写于
4月 25, 2014
作者:
S
Shirou WAKAYAMA
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
imeplements Process.Memory_Maps(). This is a function because map is very large.
上级
79811544
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
126 addition
and
10 deletion
+126
-10
README.rst
README.rst
+2
-1
process.go
process.go
+0
-7
process_freebsd.go
process_freebsd.go
+12
-0
process_linux.go
process_linux.go
+82
-1
process_test.go
process_test.go
+18
-1
process_windows.go
process_windows.go
+12
-0
未找到文件。
README.rst
浏览文件 @
400054f2
...
@@ -86,9 +86,11 @@ Current Status
...
@@ -86,9 +86,11 @@ Current Status
- terminal (linux)
- terminal (linux)
- nice (linux)
- nice (linux)
- num_fds (linux)
- num_fds (linux)
- num_threads (linux)
- cpu_times (linux)
- cpu_times (linux)
- memory_info (linux)
- memory_info (linux)
- memory_info_ex (linux)
- memory_info_ex (linux)
- Memory_maps() (linux) <- this is a function
- not yet
- not yet
...
@@ -109,7 +111,6 @@ Current Status
...
@@ -109,7 +111,6 @@ Current Status
- cpu_percent
- cpu_percent
- cpu_affinity
- cpu_affinity
- memory_percent
- memory_percent
- memory_maps
- children
- children
- open_files
- open_files
- connections
- connections
...
...
process.go
浏览文件 @
400054f2
...
@@ -46,13 +46,6 @@ type Memory_infoStat struct {
...
@@ -46,13 +46,6 @@ type Memory_infoStat struct {
VMS
uint64
`json:"vms"`
// bytes
VMS
uint64
`json:"vms"`
// bytes
}
}
type
Memory_mapsStat
struct
{
Path
string
`json:"path"`
RSS
int32
`json:"rss"`
Anonymous
int32
`json:"anonymous"`
Swap
int32
`json:"swap"`
}
type
RlimitStat
struct
{
type
RlimitStat
struct
{
Resource
int32
`json:"resource"`
Resource
int32
`json:"resource"`
Soft
int32
`json:"soft"`
Soft
int32
`json:"soft"`
...
...
process_freebsd.go
浏览文件 @
400054f2
...
@@ -9,6 +9,13 @@ import (
...
@@ -9,6 +9,13 @@ import (
"unsafe"
"unsafe"
)
)
// Memory_info_ex is different between OSes
type
Memory_info_exStat
struct
{
}
type
Memory_mapsStat
struct
{
}
func
Pids
()
([]
int32
,
error
)
{
func
Pids
()
([]
int32
,
error
)
{
ret
:=
make
([]
int32
,
0
)
ret
:=
make
([]
int32
,
0
)
procs
,
err
:=
processes
()
procs
,
err
:=
processes
()
...
@@ -23,6 +30,11 @@ func Pids() ([]int32, error) {
...
@@ -23,6 +30,11 @@ func Pids() ([]int32, error) {
return
ret
,
nil
return
ret
,
nil
}
}
func
(
p
*
Process
)
Memory_Maps
()
(
*
[]
Memory_mapsStat
,
error
)
{
ret
:=
make
([]
Memory_mapsStat
,
0
)
return
ret
,
nil
}
func
copy_params
(
k
*
Kinfo_proc
,
p
*
Process
)
error
{
func
copy_params
(
k
*
Kinfo_proc
,
p
*
Process
)
error
{
p
.
Exe
=
byteToString
(
k
.
Ki_comm
[
:
])
p
.
Exe
=
byteToString
(
k
.
Ki_comm
[
:
])
p
.
Ppid
=
k
.
Ki_ppid
p
.
Ppid
=
k
.
Ki_ppid
...
...
process_linux.go
浏览文件 @
400054f2
...
@@ -27,6 +27,20 @@ type Memory_info_exStat struct {
...
@@ -27,6 +27,20 @@ type Memory_info_exStat struct {
Dirty
uint64
`json:"dirty"`
// bytes
Dirty
uint64
`json:"dirty"`
// bytes
}
}
type
Memory_mapsStat
struct
{
Path
string
`json:"path"`
Rss
uint64
`json:"rss"`
Size
uint64
`json:"size"`
Pss
uint64
`json:"pss"`
Shared_clean
uint64
`json:"shared_clean"`
Shared_dirty
uint64
`json:"shared_dirty"`
Private_clean
uint64
`json:"private_clean"`
Private_dirty
uint64
`json:"private_dirty"`
Referenced
uint64
`json:"referenced"`
Anonymous
uint64
`json:"anonymous"`
Swap
uint64
`json:"swap"`
}
type
fillFunc
func
(
pid
int32
,
p
*
Process
)
error
type
fillFunc
func
(
pid
int32
,
p
*
Process
)
error
func
NewProcess
(
pid
int32
)
(
*
Process
,
error
)
{
func
NewProcess
(
pid
int32
)
(
*
Process
,
error
)
{
...
@@ -51,6 +65,73 @@ func NewProcess(pid int32) (*Process, error) {
...
@@ -51,6 +65,73 @@ func NewProcess(pid int32) (*Process, error) {
return
p
,
nil
return
p
,
nil
}
}
// Get memory maps from /proc/(pid)/smaps
// This is a function. Because Memory map information is very big.
func
(
p
*
Process
)
Memory_Maps
()
(
*
[]
Memory_mapsStat
,
error
)
{
pid
:=
p
.
Pid
ret
:=
make
([]
Memory_mapsStat
,
0
)
smapsPath
:=
filepath
.
Join
(
"/"
,
"proc"
,
strconv
.
Itoa
(
int
(
pid
)),
"smaps"
)
contents
,
err
:=
ioutil
.
ReadFile
(
smapsPath
)
if
err
!=
nil
{
return
nil
,
err
}
lines
:=
strings
.
Split
(
string
(
contents
),
"
\n
"
)
// function of parsing a block
get_block
:=
func
(
first_line
[]
string
,
block
[]
string
)
Memory_mapsStat
{
m
:=
Memory_mapsStat
{}
m
.
Path
=
first_line
[
len
(
first_line
)
-
1
]
for
_
,
line
:=
range
block
{
field
:=
strings
.
Split
(
line
,
":"
)
if
len
(
field
)
<
2
{
continue
}
v
:=
strings
.
Trim
(
field
[
1
],
" kB"
)
// remove last "kB"
switch
field
[
0
]
{
case
"Size"
:
m
.
Size
=
parseUint64
(
v
)
case
"Rss"
:
m
.
Rss
=
parseUint64
(
v
)
case
"Pss"
:
m
.
Pss
=
parseUint64
(
v
)
case
"Shared_Clean"
:
m
.
Shared_clean
=
parseUint64
(
v
)
case
"Shared_Dirty"
:
m
.
Shared_dirty
=
parseUint64
(
v
)
case
"Private_Clean"
:
m
.
Private_clean
=
parseUint64
(
v
)
case
"Private_Dirty"
:
m
.
Private_dirty
=
parseUint64
(
v
)
case
"Referenced"
:
m
.
Referenced
=
parseUint64
(
v
)
case
"Anonymous"
:
m
.
Anonymous
=
parseUint64
(
v
)
case
"Swap"
:
m
.
Swap
=
parseUint64
(
v
)
}
}
return
m
}
blocks
:=
make
([]
string
,
16
)
for
_
,
line
:=
range
lines
{
field
:=
strings
.
Split
(
line
,
" "
)
if
strings
.
HasSuffix
(
field
[
0
],
":"
)
==
false
{
// new block section
if
len
(
blocks
)
>
0
{
ret
=
append
(
ret
,
get_block
(
field
,
blocks
))
}
// starts new block
blocks
=
make
([]
string
,
16
)
}
else
{
blocks
=
append
(
blocks
,
line
)
}
}
return
&
ret
,
nil
}
// Parse to int32 without error
// Parse to int32 without error
func
parseInt32
(
val
string
)
int32
{
func
parseInt32
(
val
string
)
int32
{
vv
,
_
:=
strconv
.
ParseInt
(
val
,
10
,
32
)
vv
,
_
:=
strconv
.
ParseInt
(
val
,
10
,
32
)
...
@@ -146,7 +227,7 @@ func fillFromStatm(pid int32, p *Process) error {
...
@@ -146,7 +227,7 @@ func fillFromStatm(pid int32, p *Process) error {
return
nil
return
nil
}
}
//
g
et various status from /proc/(pid)/status
//
G
et various status from /proc/(pid)/status
func
fillFromStatus
(
pid
int32
,
p
*
Process
)
error
{
func
fillFromStatus
(
pid
int32
,
p
*
Process
)
error
{
statPath
:=
filepath
.
Join
(
"/"
,
"proc"
,
strconv
.
Itoa
(
int
(
pid
)),
"status"
)
statPath
:=
filepath
.
Join
(
"/"
,
"proc"
,
strconv
.
Itoa
(
int
(
pid
)),
"status"
)
contents
,
err
:=
ioutil
.
ReadFile
(
statPath
)
contents
,
err
:=
ioutil
.
ReadFile
(
statPath
)
...
...
process_test.go
浏览文件 @
400054f2
...
@@ -34,7 +34,7 @@ func Test_Pid_exists(t *testing.T) {
...
@@ -34,7 +34,7 @@ func Test_Pid_exists(t *testing.T) {
}
}
func
Test_NewProcess
(
t
*
testing
.
T
)
{
func
Test_NewProcess
(
t
*
testing
.
T
)
{
check_pid
:=
1
check_pid
:=
1
9472
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
check_pid
=
0
check_pid
=
0
}
}
...
@@ -47,3 +47,20 @@ func Test_NewProcess(t *testing.T) {
...
@@ -47,3 +47,20 @@ func Test_NewProcess(t *testing.T) {
d
,
_
:=
json
.
Marshal
(
ret
)
d
,
_
:=
json
.
Marshal
(
ret
)
fmt
.
Println
(
string
(
d
))
fmt
.
Println
(
string
(
d
))
}
}
func
Test_Process_memory_maps
(
t
*
testing
.
T
)
{
check_pid
:=
19472
if
runtime
.
GOOS
==
"windows"
{
check_pid
=
0
}
ret
,
err
:=
NewProcess
(
int32
(
check_pid
))
mmaps
,
err
:=
ret
.
Memory_Maps
()
if
err
!=
nil
{
t
.
Errorf
(
"memory map get error %v"
,
err
)
}
for
_
,
m
:=
range
*
mmaps
{
fmt
.
Println
(
m
)
}
}
process_windows.go
浏览文件 @
400054f2
...
@@ -50,6 +50,13 @@ type SYSTEM_PROCESS_INFORMATION struct {
...
@@ -50,6 +50,13 @@ type SYSTEM_PROCESS_INFORMATION struct {
}
}
*/
*/
// Memory_info_ex is different between OSes
type
Memory_info_exStat
struct
{
}
type
Memory_mapsStat
struct
{
}
func
Pids
()
([]
int32
,
error
)
{
func
Pids
()
([]
int32
,
error
)
{
ret
:=
make
([]
int32
,
0
)
ret
:=
make
([]
int32
,
0
)
...
@@ -64,6 +71,11 @@ func Pids() ([]int32, error) {
...
@@ -64,6 +71,11 @@ func Pids() ([]int32, error) {
return
ret
,
nil
return
ret
,
nil
}
}
func
(
p
*
Process
)
Memory_Maps
()
(
*
[]
Memory_mapsStat
,
error
)
{
ret
:=
make
([]
Memory_mapsStat
,
0
)
return
ret
,
nil
}
func
NewProcess
(
pid
int32
)
(
*
Process
,
error
)
{
func
NewProcess
(
pid
int32
)
(
*
Process
,
error
)
{
p
:=
&
Process
{
Pid
:
pid
}
p
:=
&
Process
{
Pid
:
pid
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录