NuttX profiler improvements

This commit is contained in:
Pavel Kirienko 2015-01-16 20:47:29 +03:00 committed by Lorenz Meier
parent dd3fa2532e
commit 9293950cdb
1 changed files with 102 additions and 34 deletions

View File

@ -11,45 +11,111 @@
# Requirements: ARM GDB with Python support
#
set -e
root=$(dirname $0)/..
nsamples=100
sleeptime=0.01 # Doctors recommend 7-8 hours a day
taskname=uavcan
exe=$root/Build/px4fmu-v2_default.build/firmware.elf
#
# Parsing the arguments. Read this section for usage info.
#
nsamples=0
sleeptime=0.1 # Doctors recommend 7-8 hours a day
taskname=
elf=$root/Build/px4fmu-v2_default.build/firmware.elf
append=0
fgfontsize=5
fgwidth=1900
set -e
function usage()
{
echo "Invalid usage. Supported options:"
cat $0 | sed -n 's/^\s*--\([^)\*]*\).*/\1/p' # Don't try this at home.
exit 1
}
stacksfile=/tmp/$taskname-stacks.log
cd $root
rm -f $stacksfile
echo "Sampling..."
for x in $(seq 1 $nsamples)
for i in "$@"
do
arm-none-eabi-gdb $exe --batch -ex "set print asm-demangle on" \
-ex "source $root/Debug/Nuttx.py" \
-ex "show mybt $taskname" \
2> /dev/null \
| sed -n 's/0\.0:\(#.*\)/\1/p' \
>> $stacksfile
echo -e '\n\n' >> $stacksfile
echo -ne "\r$x/$nsamples"
sleep $sleeptime
case $i in
--nsamples=*)
nsamples="${i#*=}"
;;
--sleeptime=*)
sleeptime="${i#*=}"
;;
--taskname=*)
taskname="${i#*=}"
;;
--elf=*)
elf="${i#*=}"
;;
--append)
append=1
;;
--fgfontsize=*)
fgfontsize="${i#*=}"
;;
--fgwidth=*)
fgwidth="${i#*=}"
;;
*)
usage
;;
esac
shift
done
echo
echo "Stacks saved to $stacksfile"
#
# Temporary files
#
stacksfile=/tmp/pmpn-stacks.log
foldfile=/tmp/pmpn-folded.txt
graphfile=/tmp/pmpn-flamegraph.svg
cat $stacksfile | perl -e 'my $current = "";
#
# Sampling if requested. Note that if $append is true, the stack file will not be rewritten.
#
cd $root
if [[ $nsamples > 0 && "$taskname" != "" ]]
then
[[ $append = 0 ]] && (rm -f $stacksfile; echo "Old stacks removed")
echo "Sampling..."
for x in $(seq 1 $nsamples)
do
arm-none-eabi-gdb $exe --batch -ex "set print asm-demangle on" \
-ex "source $root/Debug/Nuttx.py" \
-ex "show mybt $taskname" \
2> /dev/null \
| sed -n 's/0\.0:\(#.*\)/\1/p' \
>> $stacksfile
echo -e '\n\n' >> $stacksfile
echo -ne "\r$x/$nsamples"
sleep $sleeptime
done
echo
echo "Stacks saved to $stacksfile"
else
echo "Sampling skipped - set 'nsamples' and 'taskname' to re-sample."
fi
#
# Folding the stacks.
#
if [ ! -f $stacksfile ]; then
echo "Where are the stack samples?"
exit 1
fi
cat $stacksfile | perl -e 'use File::Basename;
my $current = "";
my %stacks;
while(<>) {
if(m/^#[0-9]*\s*0x[a-zA-Z0-9]*\s*in (.*) at/) {
if ($1 ne "None") {
if ($current eq "") { $current = $1; }
else { $current = $1 . ";" . $current; }
}
if(m/^#[0-9]*\s*0x[a-zA-Z0-9]*\s*in (.*) at (.*)/) {
my $x = $1 eq "None" ? basename($2) : $1;
if ($current eq "") { $current = $x; }
else { $current = $x . ";" . $current; }
} elsif(!($current eq "")) {
$stacks{$current} += 1;
$current = "";
@ -57,10 +123,12 @@ while(<>) {
}
foreach my $k (sort { $a cmp $b } keys %stacks) {
print "$k $stacks{$k}\n";
}' > /tmp/$taskname-folded.txt
}' > $foldfile
echo "Folded stacks saved to /tmp/$taskname-folded.txt"
echo "Folded stacks saved to $foldfile"
cat /tmp/$taskname-folded.txt | flamegraph.pl --fontsize=8 --width=1800 > /tmp/$taskname-flamegraph.svg
xdg-open /tmp/$taskname-flamegraph.svg
#
# Graphing.
#
cat $foldfile | flamegraph.pl --fontsize=$fgfontsize --width=$fgwidth > $graphfile
xdg-open $graphfile