Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test function is quit expensive #10

Open
cperdana opened this issue Jul 26, 2012 · 3 comments
Open

test function is quit expensive #10

cperdana opened this issue Jul 26, 2012 · 3 comments
Assignees

Comments

@cperdana
Copy link

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().

@ghost ghost assigned buffer Jul 26, 2012
@buffer
Copy link
Owner

buffer commented Jul 26, 2012

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.

@cperdana
Copy link
Author

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")

@cperdana
Copy link
Author

Hi Angelo,
I 've come with some solution, can you take a look at it

https://gist.github.com/66de39d5dfc04214c81f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants