#! /bin/sh
+set -e
+
usage() {
echo "EXAMPLE (whole tree) : $0 | neato -T png > ps.png && open ps.png"
echo "EXAMPLE (user clusters): $0 | sdp -T png > ps.png && open ps.png"
}
-compile() {
+ps2dot() {
awk -v kernel="$(uname -v)" -v whoami="$(whoami)" \
'
function num_scale(src_cur, src_max, dst_min, dst_max) {
}
function vert_print(v, _color, _fontcolor, _shape, _state, _size, _height, _label, _label_base, _label_ext) {
- _shape = "rectangle"
_state = child2state[v]
+ _style = "filled,solid"
+
+ # -----------------------------------------------------------------
+ # Sleeping/idling
+ # -----------------------------------------------------------------
+ # D uninterruptible sleep (usually IO)
if (_state == "D") {
_shape = "circle"
+ # I Idle kernel thread
} else if (_state == "I") {
- _shape = "octagon"
- } else if (_state == "R") {
- _shape = "star"
+ _shape = "circle"
+ # S interruptible sleep (waiting for an event to complete)
} else if (_state == "S") {
- _shape = "oval"
+ _shape = "circle"
+ # -----------------------------------------------------------------
+ # Running
+ # -----------------------------------------------------------------
+ # R running or runnable (on run queue)
+ } else if (_state == "R") {
+ _shape = "rarrow"
+ # -----------------------------------------------------------------
+ # Stopped
+ # -----------------------------------------------------------------
+ # T stopped by job control signal
} else if (_state == "T") {
_shape = "square"
+ # t stopped by debugger during the tracing
} else if (_state == "t") {
- _shape = "Msquare"
+ _shape = "square"
+ # -----------------------------------------------------------------
+ # Dead
+ # -----------------------------------------------------------------
+ # Z defunct ("zombie") process, terminated but not reaped by its parent
} else if (_state == "Z") {
- _shape = "diamond"
+ _shape = "Msquare"
+ _style = "solid"
+ # -----------------------------------------------------------------
+ # UNKNOWN STATE
+ # -----------------------------------------------------------------
+ } else {
+ _shape = "doublecircle"
}
+
_color =\
num_scale(\
child2cpu[v],
child2mem[v],
max_mem,
1,
- 5\
- ) / 5
+ 4\
+ ) / 4
_height = _size
+ _width = _size
_fontcolor = \
_color == VERT_COLORSCHEME_MAX || _color == VERT_COLORSCHEME_MIN \
? sprintf("/%s/%d", VERT_COLORSCHEME, VERT_COLORSCHEME_MID) \
[ fontsize=8 \
, fixedsize=true \
, height=%f \
+ , width=%f \
, border=1 \
- , style=\"filled,solid\" \
+ , style=\"%s\" \
, fontname=Helvetica \
, label=\"%s\" \
, shape=\"%s\" \
];",
v,
_height,
+ _width,
+ _style,
_label,
_shape,
VERT_COLORSCHEME,
main() {
case "$1" in
- '--help') usage
+ '--help')
+ usage
;;
- *) procs | grep "$1" | compile
+ *)
+ timestamp="$(date +'%Y-%m-%d_%H:%M:%S%z')"
+ host="$(hostname)"
+ kernel="$(uname -s | awk '{print tolower($0)}')"
+ filename_base=$(mktemp "ps.$host.$kernel.$timestamp.XXXXX")
+ file_log="$filename_base.log"
+ file_dot="$filename_base.dot"
+ mv "$filename_base" "$file_log"
+ procs | grep "$1" | ps2dot 2> "$file_log" > "$file_dot"
+ time neato -T png "$file_dot" 2> "$file_log" > "$filename_base.neato.png"
+ time fdp -T png "$file_dot" 2> "$file_log" > "$filename_base.fdp.png"
+ time dot -T png "$file_dot" 2> "$file_log" > "$filename_base.dot.png"
+ ls -1 "$filename_base"*
;;
esac
}