|
|
|
@ -11,45 +11,111 @@
@@ -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 |
|
|
|
|
for i in "$@" |
|
|
|
|
do |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
# Temporary files |
|
|
|
|
# |
|
|
|
|
stacksfile=/tmp/pmpn-stacks.log |
|
|
|
|
foldfile=/tmp/pmpn-folded.txt |
|
|
|
|
graphfile=/tmp/pmpn-flamegraph.svg |
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
# Sampling if requested. Note that if $append is true, the stack file will not be rewritten. |
|
|
|
|
# |
|
|
|
|
cd $root |
|
|
|
|
rm -f $stacksfile |
|
|
|
|
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 |
|
|
|
|
if [[ $nsamples > 0 && "$taskname" != "" ]] |
|
|
|
|
then |
|
|
|
|
[[ $append = 0 ]] && (rm -f $stacksfile; echo "Old stacks removed") |
|
|
|
|
|
|
|
|
|
echo |
|
|
|
|
echo "Stacks saved to $stacksfile" |
|
|
|
|
echo "Sampling..." |
|
|
|
|
|
|
|
|
|
cat $stacksfile | perl -e 'my $current = ""; |
|
|
|
|
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(<>) {
@@ -57,10 +123,12 @@ while(<>) {
|
|
|
|
|
} |
|
|
|
|
foreach my $k (sort { $a cmp $b } keys %stacks) { |
|
|
|
|
print "$k $stacks{$k}\n"; |
|
|
|
|
}' > /tmp/$taskname-folded.txt |
|
|
|
|
|
|
|
|
|
echo "Folded stacks saved to /tmp/$taskname-folded.txt" |
|
|
|
|
}' > $foldfile |
|
|
|
|
|
|
|
|
|
cat /tmp/$taskname-folded.txt | flamegraph.pl --fontsize=8 --width=1800 > /tmp/$taskname-flamegraph.svg |
|
|
|
|
echo "Folded stacks saved to $foldfile" |
|
|
|
|
|
|
|
|
|
xdg-open /tmp/$taskname-flamegraph.svg |
|
|
|
|
# |
|
|
|
|
# Graphing. |
|
|
|
|
# |
|
|
|
|
cat $foldfile | flamegraph.pl --fontsize=$fgfontsize --width=$fgwidth > $graphfile |
|
|
|
|
xdg-open $graphfile |
|
|
|
|