made cleaner way to print the debug_each_opcode. #703
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In trying to diagnose another problem, I attempted to turn on the DEBUG_EACH_OPCODE check in Cpu.ExecuteInstruction(), like so:
The code that this enabled prints out a log of each and every execution of every opcode. That's very verbose, but that's what it's for.
The problem is that it massively kills the framerate, and the reason is that it runs each opcode through the Unity.Debug.Log() method, which RE-OPENS the log file, writes one thing, and then closes the log file again. That's why it's so slow.
To speed it up, and make it still possible to use that option without killing the framerate (and thus invalidating whatever you are testing for as the timings are all wrong), I changed it to append the per-instruction messages to a StringBuilder in memory, and then only dump the result through Unity.Debug.Log() once per Update() rather than once per Instruction. (there's also a try/catch to make sure it prints the partial Update()'s worth of stuff when it hits an exception and stops.)
Here's an example of what the new output looks like if you set DEBUG_EACH_OPCODE to true: