diff --git a/src/ttop/format.nim b/src/ttop/format.nim index b081626..c518820 100644 --- a/src/ttop/format.nim +++ b/src/ttop/format.nim @@ -20,6 +20,12 @@ proc formatSPair*(b: int): (float, string) = return (b.float, ".") +proc formatN3*(a: int): string = + if a > 999: + fmt "{(a div 1000):2}k" + else: + fmt "{a:3}" + proc formatS*(a: int): string = let (n, s) = formatSPair(a) if a < 1024: diff --git a/src/ttop/procfs.nim b/src/ttop/procfs.nim index 702257c..966e024 100644 --- a/src/ttop/procfs.nim +++ b/src/ttop/procfs.nim @@ -58,6 +58,7 @@ type PidInfo* = object netInDiff*, netOutDiff*: uint parents*:seq[uint] # generated from ppid, used to build tree threads*: int + count*: int docker*: string type CpuInfo* = object @@ -550,15 +551,18 @@ proc sort*(info: FullInfoRef, sortOrder = Pid, threads = false, group = false) = elif sortOrder != Pid: sort(info.pidsInfo, sortFunc(sortOrder)) +proc id(cmd: string): string = + let idx = cmd.find(' ') + if idx >= 0: + cmd[0.. 0: - tb.write fmt" {blog}: {tui.hist} / {cnt} " + tb.write fmt" {blog} {tui.hist}/{cnt} " elif blog == "": tb.write fmt" autoupdate log: empty " else: - tb.write fmt" autoupdate {blog}: {cnt} " + tb.write fmt" autoupdate {blog} {cnt}/{cnt} " let curX = tb.getCursorXPos() if tb.width - curX - 2 > 0: tb.write ' '.repeat(tb.width - curX - 2) tb.setCursorXPos curX + tb.write resetStyle # let powerStr = fmt"{float(info.power) / 1000000:5.2f} W" let procStr = fmt"PROCS: {$info.pidsInfo.len}" tb.writeR procStr @@ -278,25 +280,31 @@ proc checkFilter(filter: string, p: PidInfo): bool = proc table(tui: Tui, tb: var TerminalBuffer, pi: OrderedTableRef[uint, PidInfo], statsLen: int) = var y = tb.getCursorYPos() + 1 - tb.write styleBright - tb.write(offset, y, bgBlue, fmt"""{"S":1}""") + tb.write styleDim + tb.write(offset, y, fmt"""{"S":1}""") if not tui.group: tb.write fmt""" {"PID":>6}""" tb.write fmt""" {"USER":<8} {"RSS":>10} {"MEM%":>5} {"CPU%":>5} {"r/w IO":>9} {"UP":>8}""" - if tui.threads: + if tui.group: + tb.write fmt""" {"CNT":>3}""" + if tui.threads or tui.group: tb.write fmt""" {"THR":>3} """ - elif tui.group: - tb.write fmt""" {"CNT":>3} """ if tb.width - 63 > 0: tb.write ' '.repeat(tb.width-63), bgNone inc y - var i: uint = 0 + var i = 0 + tb.setStyle {} tb.write fgColor + if tui.scrollY > 0: + tb.setCursorPos (tb.width div 2)-1, tb.getCursorYPos()+1 + tb.write "..." + inc y + dec i for (_, p) in pi.pairs: if tui.filter.isSome: if checkFilter(tui.filter.get, p): continue - elif i < uint tui.scrollY: + elif i < tui.scrollY: inc i continue tb.setCursorPos offset, y @@ -325,8 +333,10 @@ proc table(tui: Tui, tb: var TerminalBuffer, pi: OrderedTableRef[uint, PidInfo], let lvl = p.parents.len var cmd = "" + if tui.group: + tb.write " ", p.count.formatN3() if tui.threads or tui.group: - tb.write " ", ($p.threads).cut(3, true, tui.scrollX), " " + tb.write " ", p.threads.formatN3(), " " if lvl > 0: tb.write fgCyan, repeat("ยท", lvl) else: diff --git a/ttop.nimble b/ttop.nimble index 0183fab..7b817f0 100644 --- a/ttop.nimble +++ b/ttop.nimble @@ -1,6 +1,6 @@ # Package -version = "1.4.2" +version = "1.4.3" author = "inv2004" description = "Monitoring tool with historical snapshots and alerts" license = "MIT"