Skip to content

Instantly share code, notes, and snippets.

@Morozov-5F
Created November 13, 2017 10:12
Show Gist options
  • Save Morozov-5F/000f6fa1371d4de24f8c0453a76cb1bb to your computer and use it in GitHub Desktop.
Save Morozov-5F/000f6fa1371d4de24f8c0453a76cb1bb to your computer and use it in GitHub Desktop.
Sort process by theis stack depth
#!/usr/bin/gawk -f
# Prepare file list
$1 ~ /[0-9]+/ {
pid = $1
fname = "/proc/" pid "/stack";
stack_level = 0
# Read file and count stack depth
getline_ret = getline < fname
while (getline_ret == 1) {
getline_ret = getline < fname
stack_level++
}
stack_levels[stack_level] = pid " " stack_levels[stack_level]
}
END {
print "\\documentclass{article}"
print "\\begin{document}"
# TODO: add sane latex code
print "\\begin{tabular}[c]{|r| p{7.5cm}|}"
print "\\hline"
print "Stack Level & PIDs \\\\ \\hline"
for (stack_level in stack_levels) {
print stack_level " & " stack_levels[stack_level] " \\\\ \\hline"
# split(stack_levels[stack_level], pids)
# for (pid in pids) {
# print " " pids[pid]
# }
}
print "\\end{tabular}"
print "\\end{document}"
}
#!/bin/bash
LATEX_JOB_NAME="pids_by_stack_depth"
pids=$(ps -A -o pid)
latex_file=$(echo "$pids" | awk -f task.awk)
echo "$latex_file" > main.tex
echo "$latex_file" | pdflatex -jobname=$LATEX_JOB_NAME >/dev/null
# Clean temporary files
rm -f "$LATEX_JOB_NAME.aux" 2>/dev/null
rm -f "$LATEX_JOB_NAME.log" 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment