From 10279ad69d145df3e2ecebdf095cba8c7f614a96 Mon Sep 17 00:00:00 2001 From: Jeremiah Roth Date: Mon, 18 Feb 2019 03:15:27 +0000 Subject: [PATCH] More useful help; disable broken -once --- README.md | 2 +- go.mod | 2 +- main.go | 38 ++++++++++++++++++++++---------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a5c364c..978d996 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/go.mod b/go.mod index 7921237..79ae0cd 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/main.go b/main.go index c1ca35a..da60369 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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 { @@ -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() }