Skip to content

Commit

Permalink
Merge pull request #69 from leahneukirchen/rss
Browse files Browse the repository at this point in the history
psgo: add RSS format
  • Loading branch information
vrothberg authored Apr 9, 2020
2 parents b17148b + e04e78e commit 7686e6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions psgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ var (
onHost: true,
procFn: processHGROUP,
},
{
normal: "rss",
header: "RSS",
procFn: processRSS,
},
{
normal: "state",
header: "STATE",
Expand Down Expand Up @@ -862,6 +867,16 @@ func processHGROUP(p *process.Process, ctx *psContext) (string, error) {
return "?", nil
}

// processRSS returns the resident set size of process p in KiB (1024-byte
// units).
func processRSS(p *process.Process, ctx *psContext) (string, error) {
if p.Status.VMRSS == "" {
// probably a kernel thread
return "0", nil
}
return p.Status.VMRSS, nil
}

// processState returns the process state of process p.
func processState(p *process.Process, ctx *psContext) (string, error) {
return p.Status.State, nil
Expand Down
9 changes: 8 additions & 1 deletion test/format.bats
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ function is_labeling_enabled() {
[[ ${lines[0]} =~ "LABEL" ]]
}

@test "RSS header" {
run ./bin/psgo -format "rss"
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ "RSS" ]]
}

@test "STATE header" {
run ./bin/psgo -format "state"
[ "$status" -eq 0 ]
Expand All @@ -244,7 +250,7 @@ function is_labeling_enabled() {
}

@test "ALL header" {
run ./bin/psgo -format "pcpu, group, ppid, user, args, comm, rgroup, nice, pid, pgid, etime, ruser, time, tty, vsz, capamb, capinh, capprm, capeff, capbnd, seccomp, hpid, huser, hgroup, state"
run ./bin/psgo -format "pcpu, group, ppid, user, args, comm, rgroup, nice, pid, pgid, etime, ruser, time, tty, vsz, capamb, capinh, capprm, capeff, capbnd, seccomp, hpid, huser, hgroup, rss, state"
[ "$status" -eq 0 ]

[[ ${lines[0]} =~ "%CPU" ]]
Expand All @@ -270,5 +276,6 @@ function is_labeling_enabled() {
[[ ${lines[0]} =~ "HPID" ]]
[[ ${lines[0]} =~ "HUSER" ]]
[[ ${lines[0]} =~ "HGROUP" ]]
[[ ${lines[0]} =~ "RSS" ]]
[[ ${lines[0]} =~ "STATE" ]]
}
2 changes: 1 addition & 1 deletion test/list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
@test "List descriptors" {
run ./bin/psgo -list
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ "args, capamb, capbnd, capeff, capinh, capprm, comm, etime, group, hgroup, hpid, huser, label, nice, pcpu, pgid, pid, ppid, rgroup, ruser, seccomp, state, stime, time, tty, user, vsz" ]]
[[ ${lines[0]} =~ "args, capamb, capbnd, capeff, capinh, capprm, comm, etime, group, hgroup, hpid, huser, label, nice, pcpu, pgid, pid, ppid, rgroup, rss, ruser, seccomp, state, stime, time, tty, user, vsz" ]]
}

0 comments on commit 7686e6f

Please sign in to comment.