12.07.2015 Views

Nios Software Tutorial - Faculty.lasierra.edu

Nios Software Tutorial - Faculty.lasierra.edu

Nios Software Tutorial - Faculty.lasierra.edu

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix—Other Board Communication & Debug <strong>Nios</strong> <strong>Software</strong> Development <strong>Tutorial</strong>Because Gprof uses information collected during the actual execution ofyour program, you can use it on programs that are too large or toocomplex to analyze by reading the source code. However, how you runyour program affects the information that shows up in the profile data.For example, if you don’t use a program’s feature while it is beingprofiled, profile information is not generated for that feature.fFor more information on Gprof, go to:www.sources.redhat.com/binutils/docs-2.10/gprof.html.RequirementsGprof requires the following items:■■■■A full-featured timer, named timer1, which cannot be usedanywhere else in your code.A UART to download profiling information to your PC. The UARTcan be shared because it is only needed after the user’s program iscomplete.Because the profiling data is downloaded after the user’s program iscomplete, the program must exit normally.Extra memory to store the profiling data. The amount of memoryneeded depends on your profile settings. Using the default settings,a 32-bit <strong>Nios</strong> system needs an extra 100% of code size of memory anda 16-bit <strong>Nios</strong> system would need an extra 25%.Debugging Code with GprofThis section describes an example using Gprof. The example assumes youare attempting to profile the Dhrystone benchmark program, dhry.c. Touse Gprof, first compile the program in the <strong>Nios</strong> SDK Shell with the gcccompiler option -pg:nios-build dhry.c -cc -pg rThe file nios_gprof.c is included in your compilation. The programprovides two operations.■The profiling code keeps track of the function calls. Using the -pgcommand, the compiler adds a call to _mcount at the beginning ofeach function, including main(), and interrupts the user code at aspecific rate. The first call to mcount() sets up all the data structures,buffers, and the interrupt service routine. Subsequent calls trace thecalling sequence.42 Altera Corporation

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!