pylibemu
pylibemu copied to clipboard
test function is quit expensive
Hi,
currently, my work need me to call test repeatedly for i in range(x): #do something pylibemu.Emulator().test(1) #continue do something
if x less than 5000, its working fine. But when x getting bigger, such as 1000000, my whole desktop freeze :)
looking at test() implementation, it seem quite expensive. Is it possible to expose/wrap all needed variable to allow my code instrument emu_cpu_parse() and emu_cpu_step() so it wont using the built in function test()?
or if possible add callback function in test(), so I can execute my function in each loop before execute emu_cpu_step().
If you think that having the possibility to insert an hook just before calling emu_cpu_step (line 592) could be beneficial for your purposes I can easily add this feature for your convenience. Thinking about something like
self.test_hook = None
[..]
ret = emu_cpu_parse(emu_cpu_get(self._emu))
hook = NULL
if ret != -1:
hook = emu_env_linux_syscall_check(_env)
if hook is NULL:
if self.test_hook:
self.test_hook(self._emu)
ret = emu_cpu_step(emu_cpu_get(self._emu))
else:
logging.warning("Error")
Maybe I need to think about details but think that this approach could easily allow you to subclass Emulator and define your own hook(s). Please let me know if it could be ok for you.
cython complain pylibemu.pyx:595:47: Cannot convert 'c_emu *' to Python object
but if you can find a way to solve that, please add break if return for self.test_hook(self._emu) is True
ret = emu_cpu_parse(emu_cpu_get(self._emu))
hook = NULL
if ret != -1:
hook = emu_env_linux_syscall_check(_env)
if hook is NULL:
if self.test_hook:
if (self.test_hook(self._emu) == True):
break
ret = emu_cpu_step(emu_cpu_get(self._emu))
else:
logging.warning("Error")
Hi Angelo, I 've come with some solution, can you take a look at it
https://gist.github.com/66de39d5dfc04214c81f