• Status Closed
  • Percent Complete
  • Task Type Patches
  • Category
  • Assigned To No-one
  • Operating System
  • Severity Low
  • Priority Very Low
  • Reported Version
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: Rockbox
Opened by lostlogic - 2005-12-08
Last edited by lostlogic - 2006-01-18

FS#2815 - Profiling support for codecs and plugins

This patch includes profiling functions for rockbox

Currently this support profiling most of the codecs, I
think only alac and faad had to be turned off due to
ICEs when compiled with profiling.

Profiling sessions start and end with codecs, and since
codecs share space in RAM, a profiling session across
multiple codecs wouldn’t make sense, so when profiling,
ensure that your playlist includes files of the same
codec only for proper results.

Plugin profiling should also be possible, but I have
not tested this yet. The same type of modifications
that I made in the Makefiles for codecs should enable
it for plugins, but each indifidual plugin would need
to start and stop profiling and initialize the profile
functions (see wav2wv for example inititialization. I
had to at least initialize profiling on wav2wv due to
the sharing of objects post-compile between wav2wv and
wavepack codec.

Profiling is enabled by selecting developer build and
the profiling option. Profileing and DEBUG are
mutually exclusive (enforced in the configure script),
due to the fomit-frame-pointer flag. Note that
profiling turns on -fomit-frame-pointer on dev builds
which it normally is not.

More information about the design and status is here:

Also included in the patch is Java 1.5 source for a
parsing program, I know that Java is probably not the
prefered language for anything here in the rockbox
world, but it’s my most fluent language currently, so
when I needed to parse a bunch of files and symbols
into a usable format, Java is how I did it.

Example commandline for the parser is:
java ProfileReader ../../profile.out

Example output files at:

Closed by  lostlogic
2006-01-18 22:31
Reason for closing:  Fixed

Updated the patch attached with a bug fix to the java
parser, and now a profile output comparator which takes two
parser output files, and compares them (changes in number of
ticks / number of calls).

Uploaded a new version of the patch with minor bug fixes,
and optimizations in the profile.c file. I was forced to
use a little bit of assembly to optimize the functions in
there, because GCC isn’t smart enough to use the subqi and
addqi features of m68k, I also ran through the rest of the
compiler output and made some adjustments to my C which let
GCC be smarter.

The minor bug that was fixed was probably never an issue,
but the thread switching functions were not being handled
just right, in case a function being profiled called yield

Gah, another version – I introduced a bug in the last
version with my optimizations.

VERSION SPEW TODAY: This latest patch fixes a bug in the
parsing code, and adds the object file name that the symbol
was found in to the output. No changes to the core
profiling code here. Yes, the parsing code is still in Java1.5.


Latest patch should reduce the impact of number of calls on
perceived number of ticks by deactivating timing on the
second instruction into the profiling call and reactivating
it as the last instruction before return. This also makes
profiling a bit faster, I spend more time in
profile_timer_tick slightly, but a lot less time in
profile_func_enter and profile_func_exit is the tradeoff.
Another loss here is that we lose the total time spent on
profiling thread counter.

To go with this, I’ve changed the to
display percent change in number of ticks by default instead
of the change in number of calls, because if you are
comparing profiling results, they should really have the
same number of calls to each function in the runs being
compared. To regain the previous behavior of comparing
ticks and calls, just pass a third argument (any value) to
the perl call.

I also fixed a bug where the parser java would throw a null
pointer if it couldn’t find some symbols. Now it just
displays their address and nothing for their object if that

bah, that version has a minor bug that results in a bad row
being output which is pointed to by indices[0] I’ll hunt it
down later or tomorrow. It doesn’t seem to hurt the
profiling results though.

Updated patch: Fix the bug mentioned below, addq.l on a
short is not generally a good idea.
The profile comparator now also outputs total calls and
ticks with %change in ticks.

Minor update. Just a change to the profile comparator perl

attaching a new file for the first version of a profile
output parsing program in perl. Once I’ve tested it a bit,
I’ll post a new patchfile with it included.

Oh, usage on the perl parser is:
./ profile.out mapfile lib/objectfiles
mapfile lib/objectfiles [012]
the last argument tells the parser how to sort the output.
0 for calls, 1 for ticks, 2 for symbol name.

eg: ./ ../../profile.out
../../build-firmware/libTremor.a 0

It is important that you parse your profiling output before
doing anything (a new build for instance) that would change
the map or library files that match it.

Here’s an updated patch file. To make the patch easier to
read, I’ve dropped the use of the NO_PROF_ATTR within the
Tremor codec. Because of this, I will not delete the
previous version which has those changes, in case they are

This drops the java profilereader code and includes the new
perl profile_reader code (updated from the one I posted
earlier) and updated profile_comparator code. Both of these
scripts now include USAGE methods.

At Lear’s suggestion, here’s a new patch with the updated to allow optional printing by
percent instead of by count. still
only accepts count style, not percent.

Fixed the things that preglow mentioned so far toward
getting this committed.

Outstanding questions:
* Should it be enabled for all codecs from the patch?
* Is the license in the file that I based the profiling on
from gcc compatible?

Update patch so it applies with amiconn’s latest changes

in CVS.


Available keyboard shortcuts


Task Details

Task Editing