mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-28 13:48:49 +08:00
fix smap parser
This commit is contained in:
parent
afe0c04c5d
commit
5b1d8ecae7
@ -399,9 +399,9 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||||||
lines := strings.Split(string(contents), "\n")
|
lines := strings.Split(string(contents), "\n")
|
||||||
|
|
||||||
// function of parsing a block
|
// function of parsing a block
|
||||||
getBlock := func(first_line []string, block []string) (MemoryMapsStat, error) {
|
getBlock := func(firstLine []string, block []string) (MemoryMapsStat, error) {
|
||||||
m := MemoryMapsStat{}
|
m := MemoryMapsStat{}
|
||||||
m.Path = first_line[len(first_line)-1]
|
m.Path = firstLine[len(firstLine)-1]
|
||||||
|
|
||||||
for _, line := range block {
|
for _, line := range block {
|
||||||
if strings.Contains(line, "VmFlags") {
|
if strings.Contains(line, "VmFlags") {
|
||||||
@ -444,13 +444,15 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks := make([]string, 16)
|
var firstLine []string
|
||||||
for _, line := range lines {
|
blocks := make([]string, 0, 16)
|
||||||
|
for i, line := range lines {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) > 0 && !strings.HasSuffix(fields[0], ":") {
|
|
||||||
|
if (len(fields) > 0 && !strings.HasSuffix(fields[0], ":")) || i == len(lines)-1 {
|
||||||
// new block section
|
// new block section
|
||||||
if len(blocks) > 0 {
|
if len(firstLine) > 0 && len(blocks) > 0 {
|
||||||
g, err := getBlock(fields, blocks)
|
g, err := getBlock(firstLine, blocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &ret, err
|
return &ret, err
|
||||||
}
|
}
|
||||||
@ -470,7 +472,8 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// starts new block
|
// starts new block
|
||||||
blocks = make([]string, 16)
|
blocks = make([]string, 0, 16)
|
||||||
|
firstLine = fields
|
||||||
} else {
|
} else {
|
||||||
blocks = append(blocks, line)
|
blocks = append(blocks, line)
|
||||||
}
|
}
|
||||||
|
@ -394,9 +394,9 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||||||
lines := strings.Split(string(contents), "\n")
|
lines := strings.Split(string(contents), "\n")
|
||||||
|
|
||||||
// function of parsing a block
|
// function of parsing a block
|
||||||
getBlock := func(first_line []string, block []string) (MemoryMapsStat, error) {
|
getBlock := func(firstLine []string, block []string) (MemoryMapsStat, error) {
|
||||||
m := MemoryMapsStat{}
|
m := MemoryMapsStat{}
|
||||||
m.Path = first_line[len(first_line)-1]
|
m.Path = firstLine[len(firstLine)-1]
|
||||||
|
|
||||||
for _, line := range block {
|
for _, line := range block {
|
||||||
if strings.Contains(line, "VmFlags") {
|
if strings.Contains(line, "VmFlags") {
|
||||||
@ -439,13 +439,15 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks := make([]string, 16)
|
var firstLine []string
|
||||||
for _, line := range lines {
|
blocks := make([]string, 0, 16)
|
||||||
|
|
||||||
|
for i, line := range lines {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) > 0 && !strings.HasSuffix(fields[0], ":") {
|
if (len(fields) > 0 && !strings.HasSuffix(fields[0], ":")) || i == len(lines)-1 {
|
||||||
// new block section
|
// new block section
|
||||||
if len(blocks) > 0 {
|
if len(firstLine) > 0 && len(blocks) > 0 {
|
||||||
g, err := getBlock(fields, blocks)
|
g, err := getBlock(firstLine, blocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &ret, err
|
return &ret, err
|
||||||
}
|
}
|
||||||
@ -465,7 +467,8 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// starts new block
|
// starts new block
|
||||||
blocks = make([]string, 16)
|
blocks = make([]string, 0, 16)
|
||||||
|
firstLine = fields
|
||||||
} else {
|
} else {
|
||||||
blocks = append(blocks, line)
|
blocks = append(blocks, line)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user