Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
dd3fa253
Commit
dd3fa253
authored
10 years ago
by
Pavel Kirienko
Committed by
Lorenz Meier
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Poor man's sampling profiler for NuttX
parent
e41bf13a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Debug/poor-mans-profiler.sh
+66
-0
66 additions, 0 deletions
Debug/poor-mans-profiler.sh
with
66 additions
and
0 deletions
Debug/poor-mans-profiler.sh
0 → 100755
+
66
−
0
View file @
dd3fa253
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment