I am working on a SHARC architecture on an embedded platform that I cannot use with a JTAG debugger because of real-time constraints.
My idea is to implement a sort of an invasive profiler based on the linker memory-map file (which is a nice XML file with all the symbols and the addresses).
During the runtime and when the target is compiled with the proper declarations -DPROFILING
, I can add a JMP instruction at the beginning and at the end of a function to benchmark it.
With these spies, I can record the execution time for a particular function along with the stack status.
Currently my interface to my target is written in Python and I am thinking about these profiling methods:
p = Profiling('memorymap.xml')
trigger = p.AddTrigger('interrupt_isr', variable_change = 'var_foo')
p.AddSpy('function_foo', nacquisitions = 8, trigger = trigger)
The spy will start recording the next 8 execution of the function function_foo
once the trigger condition is met. A trigger is added a the beginning of the function interrupt_isr
and is fired when the variable var_foo
has changed.
Currently I am not very satisfied of the profiling strategy I came with. Is there any standard profiling interface that I can get inspiration from?
The injection mechanism consists of several steps:
- Read the instruction at the desired label/function name
- Copy the read instruction at the end of the spy routine
- Replace the instruction with a jump to the spy routine
- Execute the spy routine
- Jump back at the original address