1
1
#!/usr/bin/env python
2
+ import io
2
3
import os
3
4
import re
4
5
import subprocess
@@ -20,6 +21,19 @@ def wait_for_console_log(cls, regex):
20
21
def clear_log (cls ):
21
22
os .system ('adb logcat -c' )
22
23
24
+ @classmethod
25
+ def get_memory (cls , app_id ):
26
+ output = subprocess .check_output ([
27
+ 'adb' , 'shell' , 'dumpsys' , 'meminfo' ,
28
+ 'com.rnbenchmark.{}' .format (app_id )]).decode ('utf8' )
29
+
30
+ with io .StringIO (output ) as f :
31
+ for line in f :
32
+ if line .find ('TOTAL' ) != - 1 :
33
+ columns = line .split ()
34
+ if len (columns ) >= 8 :
35
+ return columns [1 ]
36
+ return - 1
23
37
24
38
@classmethod
25
39
def stop_app (cls , app_id ):
@@ -60,25 +74,40 @@ def run(self):
60
74
self ._app_id ,
61
75
'/RenderComponentThroughput?interval={}' .format (self ._interval ))
62
76
result = AdbTool .wait_for_console_log (r'count=(\d+)' ).group (1 )
63
- return result
77
+ memory = AdbTool .get_memory (self ._app_id )
78
+ return (int (result ), int (memory ))
79
+
80
+ def run_with_average (self , times ):
81
+ ret = {
82
+ 'result' : 0 ,
83
+ 'memory' : 0 ,
84
+ }
85
+ for _ in range (times ):
86
+ (result , memory ) = self .run ()
87
+ ret ['result' ] += result
88
+ ret ['memory' ] += memory
89
+
90
+ # NOTE(kudo): Keeps thing simpler to trim as integer
91
+ ret ['result' ] = int (ret ['result' ] / times )
92
+ ret ['memory' ] = int (ret ['memory' ] / times )
93
+ return ret
64
94
65
95
66
96
def main ():
67
97
ApkTool .reinstall ('jsc' )
68
98
ApkTool .reinstall ('v8' )
69
99
70
- for _ in range (3 ):
71
- print ('=========== RenderComponentThroughput 10s ===========' )
72
- print ('jsc' , RenderComponentThroughput ('jsc' , 10000 ).run ())
73
- print ('v8' , RenderComponentThroughput ('v8' , 10000 ).run ())
100
+ print ('=========== RenderComponentThroughput 10s ===========' )
101
+ print ('jsc' , RenderComponentThroughput ('jsc' , 10000 ).run_with_average (3 ))
102
+ print ('v8' , RenderComponentThroughput ('v8' , 10000 ).run_with_average (3 ))
74
103
75
- print ('=========== RenderComponentThroughput 60s ===========' )
76
- print ('jsc' , RenderComponentThroughput ('jsc' , 60000 ).run ( ))
77
- print ('v8' , RenderComponentThroughput ('v8' , 60000 ).run ( ))
104
+ print ('=========== RenderComponentThroughput 60s ===========' )
105
+ print ('jsc' , RenderComponentThroughput ('jsc' , 60000 ).run_with_average ( 3 ))
106
+ print ('v8' , RenderComponentThroughput ('v8' , 60000 ).run_with_average ( 3 ))
78
107
79
- print ('=========== RenderComponentThroughput 180s ===========' )
80
- print ('jsc' , RenderComponentThroughput ('jsc' , 180000 ).run ( ))
81
- print ('v8' , RenderComponentThroughput ('v8' , 180000 ).run ( ))
108
+ print ('=========== RenderComponentThroughput 180s ===========' )
109
+ print ('jsc' , RenderComponentThroughput ('jsc' , 180000 ).run_with_average ( 3 ))
110
+ print ('v8' , RenderComponentThroughput ('v8' , 180000 ).run_with_average ( 3 ))
82
111
83
112
return 0
84
113
0 commit comments