Set default font color to near-black
[khome.git] / home / bin / ps2dot
CommitLineData
77bd540c
SK
1#! /bin/sh
2
3usage() {
4 echo "EXAMPLE (whole tree) : $0 | neato -T png > ps.png && open ps.png"
5 echo "EXAMPLE (user clusters): $0 | sdp -T png > ps.png && open ps.png"
6}
7
8
9compile() {
10 awk -v kernel="$(uname -v)" -v whoami="$(whoami)" \
11 '
4a01bf49
SK
12 function num_scale(src_cur, src_max, dst_min, dst_max) {
13 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
14 }
15
5259a527 16 function vert_print(v, _color, _fontcolor) {
4a01bf49
SK
17 _color =\
18 num_scale(\
5259a527
SK
19 child2nice[v] + 20,
20 20 + 20,
4a01bf49
SK
21 COLORSCHEME_MIN,
22 COLORSCHEME_MAX\
23 )
5259a527
SK
24 _fontcolor = \
25 _color == COLORSCHEME_MAX || _color == COLORSCHEME_MIN \
26 ? sprintf("/%s/%d", COLORSCHEME, COLORSCHEME_MID) \
27 : sprintf("/%s/%d", "greys9", 9)
4a01bf49
SK
28 printf(\
29 "\"%d\"\
30 [ fontsize=8 \
31 , style=filled \
32 , fontname=Helvetica \
33 , shape=ellipse \
34 , label=\"%s\n%d\" \
5259a527
SK
35 , color=\"/%s/%d\" \
36 , fontcolor=\"%s\" \
4a01bf49
SK
37 ];",
38 v,
39 child2cmd[v],
40 v,
41 COLORSCHEME,
42 _color,
5259a527 43 _fontcolor\
4a01bf49
SK
44 )
45 }
46
5259a527 47 function edge_print(child, _parent, _color, _colorscheme) {
4a01bf49 48 _parent = child2parent[child]
5259a527
SK
49 _colorscheme = "greys9"
50 _color = 3
4a01bf49
SK
51 printf(\
52 "\"%s\" -> \"%s\"\
53 [ fontsize=8 \
54 , fontname=Helvetica \
55 , len=2.0 \
56 , colorscheme=%s \
57 , color=%d \
58 ];\n",
59 _parent,
60 child,
5259a527 61 _colorscheme,
4a01bf49
SK
62 _color\
63 )
64 }
65
77bd540c 66 BEGIN {
5259a527
SK
67 # Hot->Cold gradual colorschemes:
68 # - rdbu11
69 # - rdbu9
70 # - rdbu8
71
72 # Light->Dark gradual colorschemes:
73 # - reds9
74 # - blues9
75 # - orrd9
76 # - oranges9
77 # - bupu9
78 # - greys9
79
80 COLORSCHEME_MIN = 1
81 COLORSCHEME_MID = 5
4a01bf49 82 COLORSCHEME_MAX = 9
5259a527
SK
83 COLORSCHEME = sprintf("rdbu%d", COLORSCHEME_MAX)
84
4a01bf49 85 child2cmd[0] = "swapper/sched"
77bd540c
SK
86 }
87
88 NR > 1 {
4a01bf49
SK
89 parent2child_count[$2]++
90 max_children = \
91 parent2child_count[$2] > max_children\
92 ? parent2child_count[$2]\
93 : max_children
94 child2parent[$1] = $2
95 child2user_id[$1] = $3
96 child2user_name[$1] = $4
5259a527
SK
97 child2nice[$1] = $5
98 child2cmd[$1] = $6
4a01bf49 99 user_names[$4] = 1
77bd540c
SK
100 }
101
102 END {
103 print "strict digraph G {";
104
105 print "start=0;";
77bd540c
SK
106 print "fontsize=8;";
107 print "fontname=Helvetica;";
108 print "label=\"" kernel "\";";
af6e57a2 109 print "fontcolor=\"/greys9/9\";"
77bd540c
SK
110
111 ##### Vertices (clustered by user)
4a01bf49
SK
112 for (user_name in user_names) {
113 printf "subgraph \"cluster_%s\" {\n", user_name
114 printf "label=\"%s\"\n", user_name
115 for (c in child2parent)
116 if (child2user_name[c] == user_name)
117 vert_print(c)
77bd540c
SK
118 print "}"
119 }
120
121 ##### Vertices (without a user)
4a01bf49
SK
122 for (c in child2cmd)
123 if (!child2user_name[c])
124 vert_print(c)
77bd540c
SK
125
126 ##### Edges (across clusters)
4a01bf49
SK
127 for (c in child2parent)
128 edge_print(c)
77bd540c
SK
129
130 print "}";
131 }
132 '
133}
134
135
136procs() {
137 if [ "$(uname)" = 'Linux' ]; then
5259a527 138 ps -eo 'pid,ppid,euid,euser,nice,comm'
77bd540c 139 else
5259a527 140 ps -eco 'pid,ppid,euid,euser,nice,comm'
77bd540c
SK
141 fi
142}
143
144
145main() {
146 case "$1" in
147 '--help') usage
148 ;;
149 *) procs | grep "$1" | compile
150 ;;
151 esac
152}
153
154
155main "$1"
This page took 0.02626 seconds and 4 git commands to generate.