Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

RP2040 / Pico crappy profiler bash one liner #5

Closed
MattMills opened this issue Dec 15, 2021 · 1 comment
Closed

RP2040 / Pico crappy profiler bash one liner #5

MattMills opened this issue Dec 15, 2021 · 1 comment

Comments

@MattMills
Copy link

Just as an FYI for you or Google, I used this (DapperMime) code to build a crappy profiler for the RP2040 or Pico, posting it here in case it's useful for anyone else, feel free to include in your repo if you'd like, otherwise feel free to close.

#!/bin/bash
# This should be run from your pico-sdk based application's build directory, already built, flashed onto a device, and running
# also, openOCD should be running in SWD mode, with pico-debug-core0.cfg  or pico-debug-core1.cfg as the configuration (or similar SWD config).
# You should have a ~/.gdbinit containing only 'file relative_path_to.elf' so GDB is reading the correct symbols for the running code.
# The code should run for the entire sample period. If you have multiple *.dis files, it may not detect the correct assembly.

MAX_SAMPLES=100000
TIMESTAMP=$(date +"%Y_%m_%d_%H_%M_%S")
echo "This will take some time"
(for i in {1..100000}; do echo "mrw 0xE000101C"; done) | nc -w1 127.0.0.1 4444 |  grep -av mrw | grep -av '>' | grep -av pen | sort | uniq -c | sort -n  | tr -d "\0" | awk -- '{gsub(/[ \t\r\n]+$/, "", $2); cmd=sprintf("gdb-multiarch -q --e
val-command='\''info symbol 0x%x'\'' --eval-command quit", $2); printf("echo -n '\''%d\t%x\t'\''; %s \n", $1, $2, cmd);}' | /bin/bash | awk '{cmd=sprintf("grep %s *.dis", $2); gsub(/[\n\r]+$/, "", $0); printf("%s\t\t", $0); system(cmd);}'
> crappy_profiler.output.$TIMESTAMP.txt

The 0xE000101C is the DWT_PCSR register that allows you to monitor the PC register address via the debug interface.

Output looks like this:


683     20001178        render_led_frame + 788 in section .data         20001178:       468a            mov     sl, r1
687     20000f7c        render_led_frame + 280 in section .data         20000f7c:       468a            mov     sl, r1
697     20001158        render_led_frame + 756 in section .data         20001158:       468c            mov     ip, r1
711     20001078        render_led_frame + 532 in section .data         20001078:       468a            mov     sl, r1
712     200010f8        render_led_frame + 660 in section .data         200010f8:       468a            mov     sl, r1
796     200010e4        render_led_frame + 640 in section .data         200010e4:       468b            mov     fp, r1
853     20001358        render_led_frame + 1268 in section .data                20001358:       468b            mov     fp, r1
854     200011e4        render_led_frame + 896 in section .data         200011e4:       468b            mov     fp, r1
861     20001164        render_led_frame + 768 in section .data         20001164:       468b            mov     fp, r1

With from left to right, # of calls in sample set, address of instruction, GDB symbol info, and disassembly.

@majbthrd
Copy link
Owner

Cool! Since this is not an Issue with the Dapper Mime code, I'm going to close this, but I've now enabled the github "Discussions" feature (which is supposed to be a forum for such information) and will link back to this. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants