Size and color by relative utilization of resource
[khome.git] / home / bin / ps2dot
index c8db891..39e8f4f 100755 (executable)
@@ -13,53 +13,89 @@ compile() {
             return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
         }
 
-        function vert_print(v,    _color, _fontcolor) {
+        function vert_print(v,    _color, _fontcolor, _shape, _state, _size, _height, _label, _label_base, _label_ext) {
+            _shape = "rectangle"
+            _state = child2state[v]
+            if (_state == "D") {
+                _shape = "circle"
+            } else if (_state == "I") {
+                _shape = "octagon"
+            } else if (_state == "R") {
+                _shape = "star"
+            } else if (_state == "S") {
+                _shape = "oval"
+            } else if (_state == "T") {
+                _shape = "square"
+            } else if (_state == "t") {
+                _shape = "Msquare"
+            } else if (_state == "Z") {
+                _shape = "diamond"
+            }
             _color =\
                 num_scale(\
-                    child2nice[v] + 20,
-                    20 + 20,
-                    COLORSCHEME_MIN,
-                    COLORSCHEME_MAX\
+                    child2cpu[v],
+                    max_cpu,
+                    VERT_COLORSCHEME_MAX,
+                    VERT_COLORSCHEME_MIN\
                 )
+            _size =\
+                num_scale(\
+                    child2mem[v],
+                    max_mem,
+                    1,
+                    5\
+                ) / 5
+            _height = _size
             _fontcolor = \
-                _color == COLORSCHEME_MAX || _color == COLORSCHEME_MIN \
-                ? sprintf("/%s/%d", COLORSCHEME, COLORSCHEME_MID) \
+                _color == VERT_COLORSCHEME_MAX || _color == VERT_COLORSCHEME_MIN \
+                ? sprintf("/%s/%d", VERT_COLORSCHEME, VERT_COLORSCHEME_MID) \
                 : sprintf("/%s/%d", "greys9", 9)
+            _fontcolor = \
+                _size < 0.5 \
+                ? sprintf("/%s/%d", "greys9", 9) \
+                : _fontcolor
+            _label_base = \
+                sprintf("%s\n%d", child2comm[v], v)
+            _label_ext = \
+                _size >= 0.5 \
+                ? sprintf("\ncpu: %.1f%%\nmem: %.1f%%", child2cpu[v], child2mem[v]) \
+                : ""
+            _label = _label_base _label_ext
             printf(\
                 "\"%d\"\
                 [ fontsize=8 \
-                , style=filled \
+                , fixedsize=true \
+                , height=%f \
+                , border=1 \
+                , style=\"filled,solid\" \
                 , fontname=Helvetica \
-                , shape=ellipse \
-                , label=\"%s\n%d\" \
-                , color=\"/%s/%d\" \
+                , label=\"%s\" \
+                , shape=\"%s\" \
+                , fillcolor=\"/%s/%d\" \
                 , fontcolor=\"%s\" \
                 ];",
                 v,
-                child2cmd[v],
-                v,
-                COLORSCHEME,
+                _height,
+                _label,
+                _shape,
+                VERT_COLORSCHEME,
                 _color,
                 _fontcolor\
             )
         }
 
-        function edge_print(child,    _parent, _color, _colorscheme) {
+        function edge_print(child,    _parent) {
             _parent = child2parent[child]
-            _colorscheme = "greys9"
-            _color = 3
             printf(\
                 "\"%s\" -> \"%s\"\
                 [ fontsize=8 \
                 , fontname=Helvetica \
                 , len=2.0 \
-                , colorscheme=%s \
-                , color=%d \
+                , color=\"%s\" \
                 ];\n",
                 _parent,
                 child,
-                _colorscheme,
-                _color\
+                EDGE_COLOR\
             )
         }
 
@@ -68,6 +104,7 @@ compile() {
             # - rdbu11
             # - rdbu9
             # - rdbu8
+            # - rdylgn10  # 3 - 11
 
             # Light->Dark gradual colorschemes:
             # - reds9
@@ -77,12 +114,14 @@ compile() {
             # - bupu9
             # - greys9
 
-            COLORSCHEME_MIN = 1
-            COLORSCHEME_MID = 5
-            COLORSCHEME_MAX = 9
-            COLORSCHEME = sprintf("rdbu%d", COLORSCHEME_MAX)
+            VERT_COLORSCHEME_MIN = 1
+            VERT_COLORSCHEME_MID = 4
+            VERT_COLORSCHEME_MAX = 8
+            VERT_COLORSCHEME = "rdylgn10"
+
+            EDGE_COLOR = "/ylorbr9/3"
 
-            child2cmd[0] = "swapper/sched"
+            child2comm[0] = "swapper/sched"
         }
 
         NR > 1 {
@@ -95,8 +134,13 @@ compile() {
             child2user_id[$1]   = $3
             child2user_name[$1] = $4
             child2nice[$1]      = $5
-            child2cmd[$1]       = $6
+            child2state[$1]     = $6
+            child2cpu[$1]       = $7
+            child2mem[$1]       = $8
+            child2comm[$1]      = $9
             user_names[$4]      = 1
+            max_cpu = $7 > max_cpu ? $7 : max_cpu
+            max_mem = $8 > max_mem ? $8 : max_mem
         }
 
         END {
@@ -106,8 +150,7 @@ compile() {
             print "fontsize=8;";
             print "fontname=Helvetica;";
             print "label=\"" kernel "\";";
-            printf "colorscheme=%s;\n", COLORSCHEME
-            print "fontcolor=9;"
+            print "fontcolor=\"/greys9/9\";"
 
             ##### Vertices (clustered by user)
             for (user_name in user_names) {
@@ -120,7 +163,7 @@ compile() {
             }
 
             ##### Vertices (without a user)
-            for (c in child2cmd)
+            for (c in child2comm)
                 if (!child2user_name[c])
                     vert_print(c)
 
@@ -136,9 +179,9 @@ compile() {
 
 procs() {
     if [ "$(uname)" = 'Linux' ]; then
-        ps -eo 'pid,ppid,euid,euser,nice,comm'
+        ps -eo  'pid,ppid,euid,euser,nice,s,%cpu,%mem,comm'
     else
-        ps -eco 'pid,ppid,euid,euser,nice,comm'
+        ps -eco 'pid,ppid,euid,euser,nice,s,%cpu,%mem,comm'
     fi
 }
 
This page took 0.03882 seconds and 4 git commands to generate.