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"
10 awk -v kernel
="$(uname -v)" -v whoami
="$(whoami)" \
12 function num_scale(src_cur, src_max, dst_min, dst_max) {
13 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
16 function vert_print(v, _color, _fontcolor, _shape, _state, _size, _height, _label, _label_base, _label_ext) {
17 _state = child2state[v]
18 _style = "filled,solid"
20 # -----------------------------------------------------------------
22 # -----------------------------------------------------------------
23 # D uninterruptible sleep (usually IO)
26 # I Idle kernel thread
27 } else if (_state == "I") {
29 # S interruptible sleep (waiting for an event to complete)
30 } else if (_state == "S") {
32 # -----------------------------------------------------------------
34 # -----------------------------------------------------------------
35 # R running or runnable (on run queue)
36 } else if (_state == "R") {
38 # -----------------------------------------------------------------
40 # -----------------------------------------------------------------
41 # T stopped by job control signal
42 } else if (_state == "T") {
44 # t stopped by debugger during the tracing
45 } else if (_state == "t") {
47 # -----------------------------------------------------------------
49 # -----------------------------------------------------------------
50 # Z defunct ("zombie") process, terminated but not reaped by its parent
51 } else if (_state == "Z") {
54 # -----------------------------------------------------------------
56 # -----------------------------------------------------------------
58 _shape = "doublecircle"
78 _color == VERT_COLORSCHEME_MAX || _color == VERT_COLORSCHEME_MIN \
79 ? sprintf("/%s/%d", VERT_COLORSCHEME, VERT_COLORSCHEME_MID) \
80 : sprintf("/%s/%d", "greys9", 9)
83 ? sprintf("/%s/%d", "greys9", 9) \
86 sprintf("%s\n%d", child2comm[v], v)
89 ? sprintf("\ncpu: %.1f%%\nmem: %.1f%%", child2cpu[v], child2mem[v]) \
91 _label = _label_base _label_ext
100 , fontname=Helvetica \
103 , fillcolor=\"/%s/%d\" \
118 function edge_print(child, _parent) {
119 _parent = child2parent[child]
123 , fontname=Helvetica \
134 # Hot->Cold gradual colorschemes:
138 # - rdylgn10 # 3 - 11
140 # Light->Dark gradual colorschemes:
148 VERT_COLORSCHEME_MIN = 1
149 VERT_COLORSCHEME_MID = 4
150 VERT_COLORSCHEME_MAX = 8
151 VERT_COLORSCHEME = "rdylgn10"
153 EDGE_COLOR = "/ylorbr9/3"
155 child2comm[0] = "swapper/sched"
159 parent2child_count[$2]++
161 parent2child_count[$2] > max_children\
162 ? parent2child_count[$2]\
164 child2parent[$1] = $2
165 child2user_id[$1] = $3
166 child2user_name[$1] = $4
173 max_cpu = $7 > max_cpu ? $7 : max_cpu
174 max_mem = $8 > max_mem ? $8 : max_mem
178 print "strict digraph G {";
182 print "fontname=Helvetica;";
183 print "label=\"" kernel "\";";
184 print "fontcolor=\"/greys9/9\";"
186 ##### Vertices (clustered by user)
187 for (user_name in user_names) {
188 printf "subgraph \"cluster_%s\" {\n", user_name
189 printf "label=\"%s\"\n", user_name
190 for (c in child2parent)
191 if (child2user_name[c] == user_name)
196 ##### Vertices (without a user)
197 for (c in child2comm)
198 if (!child2user_name[c])
201 ##### Edges (across clusters)
202 for (c in child2parent)
212 if [ "$(uname)" = 'Linux' ]; then
213 ps
-eo 'pid,ppid,euid,euser,nice,s,%cpu,%mem,comm'
215 ps
-eco 'pid,ppid,euid,euser,nice,s,%cpu,%mem,comm'
224 *) procs |
grep "$1" | compile
This page took 0.118675 seconds and 4 git commands to generate.