aboutsummaryrefslogtreecommitdiff
path: root/Debug
diff options
context:
space:
mode:
authorPavel Kirienko <pavel.kirienko@gmail.com>2015-01-15 02:44:54 +0300
committerLorenz Meier <lm@inf.ethz.ch>2015-01-21 14:54:23 +0100
commitdd3fa2532e63118bfd076e1027d74af2d06b9e05 (patch)
treee4346fa37d2d1444077a90f8d58a9a3db15a0e21 /Debug
parente41bf13ac57081342a94f48a468e3f6f24404f8b (diff)
downloadpx4-firmware-dd3fa2532e63118bfd076e1027d74af2d06b9e05.tar.gz
px4-firmware-dd3fa2532e63118bfd076e1027d74af2d06b9e05.tar.bz2
px4-firmware-dd3fa2532e63118bfd076e1027d74af2d06b9e05.zip
Poor man's sampling profiler for NuttX
Diffstat (limited to 'Debug')
-rwxr-xr-xDebug/poor-mans-profiler.sh66
1 files changed, 66 insertions, 0 deletions
diff --git a/Debug/poor-mans-profiler.sh b/Debug/poor-mans-profiler.sh
new file mode 100755
index 000000000..f706fad85
--- /dev/null
+++ b/Debug/poor-mans-profiler.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# Poor man's sampling profiler for NuttX.
+#
+# The stack folding script was inspired by stackcollapse-gdb.pl from the FlameGraph project.
+#
+# Usage: Install flamegraph.pl in your PATH, define the variables below, configure your .gdbinit, run the script and go
+# have a coffee. When you're back, you'll see the flamegraph. Note that frequent calls to GDB significantly
+# interfere with normal operation of the target, which means that you can't profile real-time tasks with it.
+#
+# Requirements: ARM GDB with Python support
+#
+
+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
+
+set -e
+
+stacksfile=/tmp/$taskname-stacks.log
+
+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
+
+echo
+echo "Stacks saved to $stacksfile"
+
+cat $stacksfile | perl -e '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; }
+ }
+ } elsif(!($current eq "")) {
+ $stacks{$current} += 1;
+ $current = "";
+ }
+}
+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"
+
+cat /tmp/$taskname-folded.txt | flamegraph.pl --fontsize=8 --width=1800 > /tmp/$taskname-flamegraph.svg
+
+xdg-open /tmp/$taskname-flamegraph.svg