error handling in Process.fillFromStatus

pull/12/head
Nikolay Sivko 11 years ago
parent 1b8d61144d
commit ba82ea1c90

@ -390,11 +390,9 @@ func (p *Process) fillFromStatus() error {
return err return err
} }
lines := strings.Split(string(contents), "\n") lines := strings.Split(string(contents), "\n")
p.numCtxSwitches = &NumCtxSwitchesStat{}
var vol int32
var unvol int32
for _, line := range lines { for _, line := range lines {
tabParts := strings.SplitN(line, "\t", 1) tabParts := strings.SplitN(line, "\t", 2)
if len(tabParts) < 2 { if len(tabParts) < 2 {
continue continue
} }
@ -410,25 +408,41 @@ func (p *Process) fillFromStatus() error {
case "Uid": case "Uid":
p.uids = make([]int32, 0, 4) p.uids = make([]int32, 0, 4)
for _, i := range strings.Split(value, "\t") { for _, i := range strings.Split(value, "\t") {
p.uids = append(p.uids, mustParseInt32(i)) v, err := strconv.ParseInt(i, 10, 32)
if err != nil {
return err
}
p.uids = append(p.uids, int32(v))
} }
case "Gid": case "Gid":
p.gids = make([]int32, 0, 4) p.gids = make([]int32, 0, 4)
for _, i := range strings.Split(value, "\t") { for _, i := range strings.Split(value, "\t") {
p.gids = append(p.gids, mustParseInt32(i)) v, err := strconv.ParseInt(i, 10, 32)
if err != nil {
return err
}
p.gids = append(p.gids, int32(v))
} }
case "Threads": case "Threads":
p.numThreads = mustParseInt32(value) v, err := strconv.ParseInt(value, 10, 32)
if err != nil {
return err
}
p.numThreads = int32(v)
case "voluntary_ctxt_switches": case "voluntary_ctxt_switches":
vol = mustParseInt32(value) v, err := strconv.ParseInt(value, 10, 32)
if err != nil {
return err
}
p.numCtxSwitches.Voluntary = int32(v)
case "nonvoluntary_ctxt_switches": case "nonvoluntary_ctxt_switches":
unvol = mustParseInt32(value) v, err := strconv.ParseInt(value, 10, 32)
if err != nil {
return err
}
p.numCtxSwitches.Involuntary = int32(v)
} }
} }
p.numCtxSwitches = &NumCtxSwitchesStat{
Voluntary: vol,
Involuntary: unvol,
}
return nil return nil
} }

Loading…
Cancel
Save