Skip to content

Commit

Permalink
More useful help; disable broken -once
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremiah Roth committed Feb 18, 2019
1 parent 56b5913 commit 10279ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# uptop
# uptop [![Build Status](https://travis-ci.org/rothwerx/uptop.svg?branch=master)](https://travis-ci.org/rothwerx/uptop)
> Top-like tool for displaying per-process USS (unique set size) and PSS (proportional set size) memory usage
Standard Linux memory observation tools will show you the resident set size (RSS or RES) and virtual memory size (VMSIZE or VIRT) for each process, but neither are useful for giving you actual memory usage. RSS is more useful than VMSIZE as a general measurement, but RSS still includes the full memory consumed by each shared library. Here's a simplistic example: if you have 10 processes that each use 20kB of memory, and they all use the library foo.so which consumes 10kB of memory, each process will report 30kB memory usage even though foo.so only takes 10kB total.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/rothwerx/uptop

require (
github.com/cjbassi/drawille-go v0.1.0 // indirect
github.com/gizak/termui v0.0.0-20190214045005-bb0b559103cb // indirect
github.com/gizak/termui v0.0.0-20190214045005-bb0b559103cb
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
)
38 changes: 22 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// Program version
const version = "0.2"
const version = "0.3"

// UID->username map cache
var ucache = make(map[uint32]string)
Expand Down Expand Up @@ -197,15 +197,16 @@ func processIt(fpath string) (*Process, bool) {
return nil, false
}

// Fix this
// Print header and then the contents of each Process
func printProcesses(a []*Process) {
fmt.Printf("%6s %-16s %-14s %5s %5s %5s %5s %-80s",
"PID", "Name", "User", "Swap", "USS", "PSS", "RSS", "Command")
for _, p := range a {
fmt.Printf("%6d %-16s %-14s %5d %5d %5d %5d %-80s",
p.PID, p.Name, p.User, p.Swap, p.USS, p.PSS, p.RSS, p.Command)
}
}
// func printProcesses(a []*Process) {
// fmt.Printf("%6s %-16s %-14s %5s %5s %5s %5s %-80s",
// "PID", "Name", "User", "Swap", "USS", "PSS", "RSS", "Command")
// for _, p := range a {
// fmt.Printf("%6d %-16s %-14s %5d %5d %5d %5d %-80s",
// p.PID, p.Name, p.User, p.Swap, p.USS, p.PSS, p.RSS, p.Command)
// }
// }

// Formats the processes for the termui table
func tableFormat(a []*Process) [][]string {
Expand Down Expand Up @@ -288,18 +289,23 @@ func runTermui() {
}

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Once running, hit n, r, p, s, or u to sort by Name, RSS, PSS, SwapPSS, or USS. RSS is default.\n")
flag.PrintDefaults()
os.Exit(0)
}
wantVersion := flag.Bool("version", false, "Print the version")
wantOnce := flag.Bool("once", false, "Print table once and exit")
flag.StringVar(&sortKey, "sort", "rss", "Sort by name, rss, pss, swap, or uss")
// wantOnce := flag.Bool("once", false, "Print table once and exit")
flag.StringVar(&sortKey, "sort", "rss", "Start sorted by name, rss, pss, swap, or uss")
flag.Parse()
if *wantVersion {
fmt.Println(version)
os.Exit(0)
}
if *wantOnce {
procs := GetProcesses("/proc")
printProcesses(procs)
os.Exit(0)
}
// if *wantOnce {
// procs := GetProcesses("/proc")
// printProcesses(procs)
// os.Exit(0)
// }
runTermui()
}

0 comments on commit 10279ad

Please sign in to comment.