aboutsummaryrefslogtreecommitdiff
path: root/benchmarks-script/geekbench/run.py
blob: 173476bcf5e5dcab0a876f84bef58848d386b451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import re
import sys
import subprocess

cur_dir = os.path.realpath(os.path.dirname(__file__))
log_path = os.path.join(cur_dir, 'logcat_webview.log')
result_path = os.path.join(cur_dir, 'results.txt')


def checkResults():

    if not os.path.exists(log_path):
        return
    log_fd = open(log_path)
    lines = log_fd.readlines()
    log_fd.close()

    usefull_info = []
    begin_pat_str = ('^\s*D/WebViewClassic.loadDataWithBaseURL\(\s*\d+\s*\)'
                     '\s*:\s*(?P<content>\<.*)\s*$')
    begin_pat = re.compile(begin_pat_str)
    replace_pat = re.compile('<[^>]*>')
    found_start_of_integer_perf = False
    for line in lines:

        if not found_start_of_integer_perf:
            if line.find('overall-score') == -1 and \
               line.find('Geekbench Score') == -1:
                if line.find('<h1>Integer Performance</h1>') == -1:
                    continue
                else:
                    found_start_of_integer_perf = True

        match = begin_pat.search(line)
        if not match:
            continue
        data = match.groupdict()
        value = data['content'].strip()
        if value.find('<h1>') > -1:
            continue
        value = re.sub(replace_pat, '', value)
        if not value.strip():
            continue
        usefull_info.append(value)

    res_ary = []
    index = 0
    while index < len(usefull_info):
        line = usefull_info[index].strip()
        if line.find("Score") > -1:
            res_ary.append({'key': line,
                            'value': usefull_info[index + 1].strip()})
            index = index + 2
        else:
            key = "%s_%s" % (line, usefull_info[index + 1].strip())
            res_ary.append({'key': "%s Score" % key,
                            'value': usefull_info[index + 2].strip()})
            res_ary.append({'key': key,
                            'value': usefull_info[index + 3].strip()})
            index = index + 4

    result_path = os.path.join(os.path.realpath(os.path.dirname(__file__)),
                               'results.txt')
    res_fd = open(result_path, 'w')
    for test_hash in res_ary:
        res_fd.write('%s=%s\n' % (test_hash.get('key'),
                                  test_hash.get('value')))
    res_fd.close()


def main():

    dev_ids = []
    if len(sys.argv) >= 2:
        dev_ids = sys.argv[1:]
    else:
        dev_ids = ['']
    for dev_id in dev_ids:
        if os.path.exists(result_path):
            os.unlink(result_path)
        run_sh = os.path.realpath(os.path.dirname(__file__)) + "/run.sh"
        subprocess.call(['/bin/bash', run_sh, dev_id])
        checkResults()

if __name__ == '__main__':
    main()