At its simplest, toggling an I/O bit at the start and end
of the function to be timed allows you to measure the
elapsed time directly with an oscilloscope.
HTH,
Ken
Or conversely do the same in an idle loop if you have one. Other option is
to use a counter to count idle loops. At init, run the counter for some
fixed period of time, 1 tick of an interrupt driven clock possibly, and
compare the idle loop counts to the value you collected at init to get a
relative percentage of idle time.
Scott