ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7
part 8


2 - Tool #1 - Profiling

Code optimization is often a necessity. Rarely does anyone look at a program and complain that it's too fast, while the opposite is frequently heard. Often optimization is simply a matter of identifying a key routine or two that is consuming the lion's share of the CPU cycles and speeding it up. However, picking the right function is notoriously difficult, and often the 'obvious' choice is wrong. An important tool to assist is the profiler.

On the ebm, profiling code involves generating a listing of routines and the time spent executing them. Most importantly, the percentages are listed, allowing you to estimate the benefits of tuning specific code sections. To get the most out of the ebm profiler, consult the SDK documentation, but the basic code profiling is rather simple to do:

  1. Create file 'profcmd' and place it in your program's source directory:
      rsim profile symfile Default link8_strip MYAPP_sa.sym
      rsim profile simple
      #
      #
      # to use, type this into debugger at start
      #
      # (gdb) source profcmd
      #
      # and this to show results
      #
      # (gdb) rsim profile dump Default cycles stdout
    
    The '#' entries are comments, and are used to refer to additional instructions. The file is available here for download, to save you typing. Remember to edit the MYAPP text to refer to your program - if your program is YOURAPP, the entry would become 'YOURAPP_sa.sym'.
  2. Compile and start your code in the emulator
  3. In the debugger display, select the console window (the little monitor icon with the C: prompt), which brings up the console window.
  4. In this separate window, type the following:
      source profcmd 
    
  5. At this point, you can begin debugging - run the program, and concentrate on running the sections you want to profile. Obviously if one function executes speedily, while another pokes along, avoid trying out the first, and repeatedly call the second - this will give you a better view of the time stealers in the program.
  6. At any time, stop the program, and go back to the debugger window and enter the following to display the profiling results so far:
      rsim profile dump Default cycles stdout
    

The text displayed will be the function time listing, showing the total time used by each. With this file, you can accurately know where to concentrate your efforts. As you tweak your code and rerun the profiler, you not only will get a good idea of where you code spends cycles, but also get familiar with how code executes in general (for instance, the relative speeds of different algorithms). And don't forget that as you reduce the time the slow section of code takes, other functions will appear to take more time - it's simply that they are now a greater proportion of the execution time, since you're speeding up the laggard.

While this should get you started, make sure you look over the SDK docs to get an idea of the other features of the ebm profiler.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice