0

Recently I discovered monkeyrunner tool for automating android actions, testing, macros, all that stuff. That said, I am very appalled by how slow it's takeSnapshot() is. I am doing tests on android emulator, I compared two methods - takeSnapshot() and android shell's screencap.

Test script for takeSnapshot function (d - already connected MonkeyDevice):

start = int(d.getProperty("clock.millis"))
for n in range(100):
    p = d.takeSnapshot()
    print n
stop = int(d.getProperty("clock.millis"))
print "%d" % (stop-start,)

Test for shell screenshot (/sdcard/tmp is tmpfs file system I mounted to get rid of hdd latency):

start = int(d.getProperty("clock.millis"))
for n in range(100):
    res = d.shell("screencap \"/sdcard/tmp/screen.dump\" && echo \"done\"")
    print n, res
stop = int(d.getProperty("clock.millis"))
print "%d" % (stop-start,)

First test:

99
17945
>>>

Second test:

99 done
11118
>>>

I was kind of surprised that calling android shell was actually faster then using in-built monkey function. I think if I wrote the whole bench script in sh and run it in adb shell it would be even faster... If anyone can suggest some way to improve MR's speed here I would be very glad. Generally I need this for detecting pixel color or getting subpicture (with MR) for automated tests. Currently I write it in pure sh scripts with a lot of ifs, but I'd really like to switch to MR and python. I like python.

So, the main question is: can I somehow make MonkeyRunner's takeSnapshot() run faster? Or, maybe there's some other way to get pixel color within the tool beside taking full snapshot and using it's getRawPixel method?

I understand that the difference in speed isn't THAT overwhelming, maybe it won't be noticeable in real-life application tests, I am just annoyed by the fact itself - that in-built function works so much slower than starting a new shell session and executing external program...

Andy Scull
  • 51
  • 3
  • Take a look at https://stackoverflow.com/questions/53143331/python-androidviewclient-take-snapshots-in-high-fps – Diego Torres Milano Feb 06 '19 at 17:12
  • From what I see in that thread, AndroidViewClient isn't that much faster. 4fps screenshots (250ms) is already worse than my test result with MonkeyRunner. Also, maybe offtopic - AVC still uses python2, I try to avoid these projects since it's almost near end of life – Andy Scull Feb 08 '19 at 06:26

0 Answers0