I have an old diff that fixes (most of) these monitor leaks, but there are two paths: Manual adding a lot of lib_free($2)s and similar in mon_parse.y, or Making all the called function from mon_parse.y free their memory. I initially did (1) – free all yylval.str, but it felt a bit fragile as there were one or two instances where the called function actually needed to retain the memory pointer, and there's no documentation to help make sure this remains correct. The other option (2) seems like it...
The root context is a virtual context that's the root of all other execution contexts (i.e. all interrupts). The root context gets initialized with a PC=0, because that's the PC the machine boots up with. "prof func 0" searches for all contexts with a PC=0, so you will simply get this virtual root context. Maybe it's a bit wonky, but it might be useful. All children of the root context should be the different interrupts – and in theory all contexts should be a descendant of one of the following interrupts:...
This patch should fix this:
Here's a hopefully more user-friendly branch taken % stat patch. It's adding a new column (or overloading and renaming the Context column when that exists) and doing the branch taken % calculation per above. (C:$e5cf) prof context 7 Context [7] IRQ -> ff48 Parent [1] START Entered 767 times Exited 767 times Total 172,054 cycles 175 ms Self 82,449 cycles 83.7 ms Average 224 cycles 228 us Stolen total 9,649 cycles 9.79 ms Stolen self 4,235 cycles 4.30 ms Avg inc stolen 237 cycles 240 us Memory Banking...
Here are two quick patches. The first one adds stolen cycle stats to the profiling contexts. This information is useful for profiling e.g. raster interrupts and ensuring the reported timings match wall-clock timings. It adds a bit more to the stat output: (C:$e5cd) prof context 54 Context [54] IRQ -> ff48 Parent [1] START Entered 78 times Exited 78 times Total 47,267 cycles 48.0 ms Self 8,821 cycles 8.95 ms Average 606 cycles 615 us Stolen total 2,880 cycles 2.92 ms Stolen self 516 cycles 524 us...
Here's an updated version of the latest patch that removed the dependency on <assert.h></assert.h>
Thanks for testing! I think I'd rather delete the assert() call that triggered the need for that include. I'm traveling r/n – will upload a fixed version this weekend.
One thing that struck me while writing the previous patch – there is a potentially easy way to handling bank swapping more generally. Currently for each profiling context, and for each memory page touched by the program counter in each context, the profiler stores 256 x 2 32-bit counters (cycle and sample count). It would only add a trivial amount of ram to also store the 256 bytes of actual memory content that that page contained during the context's execution. This would address things like cartridge...