Skip to content

Instantly share code, notes, and snippets.

@ferd
Last active December 19, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferd/6030174 to your computer and use it in GitHub Desktop.
Save ferd/6030174 to your computer and use it in GitHub Desktop.
Processing erlang crash dumps to find refc binaries and associated processes
#!/usr/bin/env awk -f
BEGIN {
# crash dump separators
FS=":"
# states
proc=1 # in a proc_heap or proc_stack
binary=2 # after the proc_heap or proc_stack
memory=3 # memory printing area
state=0
min=100
}
NR == 2 { print "Generated on", $0 }
NR == 3 { print } # slogan
state == memory && /^=/ { state=0 }
state == memory { print }
/^=memory/ { state=memory }
# The order is always proc_stack, proc_heap. proc_dictionary may prefix
# them but we do not care about that. only proc_heap should hold
# references to refc binaries
/^=proc_heap/ { # values on the heap
pid = $2
pid_count += 1
pids[pid_count] = $2
state=proc
}
state==proc && /^[0-9A-F]+:Yc[0-9A-F]+:/ {
refc[pid] += 1
refs[pid,refc[pid]] = substr($2, 3); # cut the Yc tag
}
/^=binary/ {
state=binary
bin_count += 1
ref=$2
bin[ref]=0
getline
bin_mem += strtonum("0x" $1)
}
END {
print "process-count:", pid_count
for(i in pids) {
pid = pids[i]
total = refc[pid]
if (total >= min) {
print "process," pid "," total
}
for(j=1;j<=total;j++) {
ref = refs[pid,j]
bin[ref] += 1
}
}
print "binaries:", bin_count
print "binary-memory-counted:" bin_mem
for(ref in bin) {
print "binary," ref "," bin[ref]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment