def main(): argv = parser.parse_args() if argv.no_logger: logger.disabled = True else: addconsolehandler() if argv.record_input and not argv.loadstate: logger.warning( "To replay input consistently later, it is required to load a state at boot. This will be" "embedded into the .replay file.") # Start PyBoy and run loop pyboy = PyBoy( argv.ROM, window_type=argv.window, window_scale=argv.scale, bootrom_file=argv.bootrom, autopause=argv.autopause, debugging=argv.debug, profiling=argv.profiling, record_input=argv.record_input is not None, disable_input=argv.no_input, enable_rewind=argv.rewind, ) if argv.loadstate is not None: if argv.loadstate != '': # Use filepath given with open(argv.loadstate, 'rb') as f: pyboy.load_state(f) else: # Guess filepath from ROM path with open(argv.ROM + ".state", 'rb') as f: pyboy.load_state(f) while not pyboy.tick(): pass pyboy.stop() if argv.profiling: print("\n".join(profiling_printer(pyboy._get_cpu_hitrate()))) if argv.record_input: save_replay(argv.ROM, argv.loadstate, argv.record_input, pyboy._get_recorded_input())
def test_profiling(): pyboy = PyBoy(any_rom, window_type="dummy", bootrom_file=utils.boot_rom, profiling=True) pyboy.tick() hitrate = pyboy._get_cpu_hitrate() CHECK_SUM = 7546 assert sum( hitrate ) == CHECK_SUM, "The amount of instructions called in the first frame of the boot-ROM has changed" assert list(main.profiling_printer(hitrate)) == [ ' 32 LD (HL-),A 2515', '17c BIT 7,H 2514', ' 20 JR NZ,r8 2514', ' af XOR A 1', ' 31 LD SP,d16 1', ' 21 LD HL,d16 1', ], "The output of the profiling formatter has changed. Either the output is wrong, or the formatter has changed." pyboy.stop(save=False)