#!/bin/rc
#This script takes a kernel image and the data from /dev/trace and creates
#gnuplot-ready output.

if (! ~ $#* 3) {
	echo 'usage: plots/createplot <kernel image> <minimum #ticks> <data file>'
	exit usage
}

#Chop leading f's, convert hex to decimal, and rearrange the columns
sed 's/ffffffff//g' < $3 | plots/rearrange > /tmp/ntr
#Run the addresses through acid in order to get function names
plots/getaddr $1 < $3 > /tmp/addrs
#Unhex the addresses from above
plots/fmtfunc /tmp/addrs > /tmp/faddrs
#Sort and merge the function names with the other info
sort /tmp/faddrs |  uniq > /tmp/saddrs
sort /tmp/ntr > /tmp/sntr
join /tmp/saddrs /tmp/sntr > /tmp/output
#Rearrange more columns and sort
awk '{print $3,$1,$4,$2}' < /tmp/output > /tmp/toprocess
sort -n /tmp/toprocess > /tmp/data
#The important part: 'stackify' function calls and print them out
#in a manner gnuplot can understand.
plots/process $2 < /tmp/data
#/tmp/data can be useful if you want to only plot the behavior of
#one function, so I don't delete it.
rm /tmp/ntr /tmp/addrs /tmp/faddrs /tmp/saddrs /tmp/sntr /tmp/output
