Distinguish process states by shape
[khome.git] / home / bin / ps2dot
index 1db1ce4..528d100 100755 (executable)
@@ -13,44 +13,60 @@ compile() {
             return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
         }
 
-        function vert_print(v,    _color) {
+        function vert_print(v,    _color, _fontcolor, _shape, _state) {
+            _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(\
-                    parent2child_count[v],
-                    max_children,
+                    child2nice[v] + 20,
+                    20 + 20,
                     COLORSCHEME_MIN,
                     COLORSCHEME_MAX\
                 )
-            fontcolor = _color >= 5 ? 1 : 9
+            _fontcolor = \
+                _color == COLORSCHEME_MAX || _color == COLORSCHEME_MIN \
+                ? sprintf("/%s/%d", COLORSCHEME, COLORSCHEME_MID) \
+                : sprintf("/%s/%d", "greys9", 9)
             printf(\
                 "\"%d\"\
                 [ fontsize=8 \
-                , style=filled \
+                , border=1 \
+                , style=\"filled,solid\" \
                 , fontname=Helvetica \
-                , shape=ellipse \
                 , label=\"%s\n%d\" \
-                , colorscheme=%s \
-                , color=%d \
-                , fontcolor=%d \
+                , shape=\"%s\" \
+                , fillcolor=\"/%s/%d\" \
+                , fontcolor=\"%s\" \
                 ];",
                 v,
-                child2cmd[v],
+                child2comm[v],
                 v,
+                _shape,
                 COLORSCHEME,
                 _color,
-                fontcolor\
+                _fontcolor\
             )
         }
 
-        function edge_print(child,    _parent, _color) {
+        function edge_print(child,    _parent, _color, _colorscheme) {
             _parent = child2parent[child]
-            _color =\
-                num_scale(\
-                    parent2child_count[_parent],
-                    max_children,
-                    COLORSCHEME_MIN,
-                    COLORSCHEME_MAX\
-                )
+            _colorscheme = COLORSCHEME
+            _color = COLORSCHEME_MID
             printf(\
                 "\"%s\" -> \"%s\"\
                 [ fontsize=8 \
@@ -61,22 +77,31 @@ compile() {
                 ];\n",
                 _parent,
                 child,
-                COLORSCHEME,
+                _colorscheme,
                 _color\
             )
         }
 
         BEGIN {
-            COLORSCHEME = "orrd9"
-            # Good gradient colorschemes:
-            # - "orrd9"
-            # - "oranges9"
-            # - "bupu9"
-            # - "greys9"
-
-            COLORSCHEME_MIN = 2
-            COLORSCHEME_MAX = 9
-            child2cmd[0] = "swapper/sched"
+            # Hot->Cold gradual colorschemes:
+            # - rdbu11
+            # - rdbu9
+            # - rdbu8
+
+            # Light->Dark gradual colorschemes:
+            # - reds9
+            # - blues9
+            # - orrd9
+            # - oranges9
+            # - bupu9
+            # - greys9
+
+            COLORSCHEME_MIN = 1
+            COLORSCHEME_MID = 5
+            COLORSCHEME_MAX = 10
+            COLORSCHEME = sprintf("rdylgn%d", COLORSCHEME_MAX)
+
+            child2comm[0] = "swapper/sched"
         }
 
         NR > 1 {
@@ -88,7 +113,9 @@ compile() {
             child2parent[$1]    = $2
             child2user_id[$1]   = $3
             child2user_name[$1] = $4
-            child2cmd[$1]       = $5
+            child2nice[$1]      = $5
+            child2state[$1]     = $6
+            child2comm[$1]      = $7
             user_names[$4]      = 1
         }
 
@@ -99,8 +126,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) {
@@ -113,7 +139,7 @@ compile() {
             }
 
             ##### Vertices (without a user)
-            for (c in child2cmd)
+            for (c in child2comm)
                 if (!child2user_name[c])
                     vert_print(c)
 
@@ -129,9 +155,9 @@ compile() {
 
 procs() {
     if [ "$(uname)" = 'Linux' ]; then
-        ps -eo pid,ppid,euid,euser,comm
+        ps -eo 'pid,ppid,euid,euser,nice,s,comm'
     else
-        ps -eco pid,ppid,euid,euser,comm
+        ps -eco 'pid,ppid,euid,euser,nice,s,comm'
     fi
 }
 
This page took 0.037396 seconds and 4 git commands to generate.