gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > How to profile code?

#5701 - Berno - Tue May 06, 2003 12:46 pm

Hey, I was wondering if its possible to profile GBA code?? I have read of gprof for gcc but never used it.
Thanks.

#5709 - Touchstone - Tue May 06, 2003 3:36 pm

To get an "all-round" profiler you can sample the program counter (PC) a given number of times during a frame to see what code is currently running. This can be done by writing an interrupt routine in asm that look at the return address, link register (depending on your interrupt handling code), and store it somewhere for you to postprocess by matching the stored PC with the symbolmap produced by the linker. Note that symbols for static methods are not exported!

If you want to measure how many clock-cycles is spent in a function you can write functions/macros for starting and stopping a GBA timer with a given resolution. I think you can link all four timers together to produce 64bit measure value which can measure up to 15.62ms (a frame is 1/60 seconds, i.e. 16.67ms) with highest precision, one clock-cycle.

EDIT: Maybe there are some built-in profiling functions in GCC, I don't know. In that case you might want to use them. :) But if you want to write your own profiling-code then that's what I can help you with.
_________________
You can't beat our meat

#5727 - Berno - Wed May 07, 2003 2:18 am

Hey thanks, I guess I can use the interrupts to do it myself.

#5755 - Berno - Thu May 08, 2003 2:29 am

I actually found a version of gprof at http://vboy.emuhq.com/downloads.shtml intended to run on VBA. Can anybody help me with using it when I try to compiler my code for profiling with devkit adv the following occurs:
gcc sprite.c -pg
/cygdrive/c/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../../armagb-elf/bin/ld: cannot find -lc_p
collect2: ld returned 1 exit status

#5942 - Jason Wilkins - Tue May 13, 2003 4:15 pm

libc_p.a is the profiling version of libc.

gcc is trying to link to it because of the -pg option. You may be able to get a valid profile even if you do not use the profiling version of libc.

To do this, try adding these options to your gcc linking command line:

-nostdlib -lgcc -lc -lgcc

This will force it to link with the normal versions of the lib.

I have been thinking about producing profiling and debugging versions of newlib (libc) as additional packages.
_________________
http://devkitadv.sourceforge.net