aboutsummaryrefslogtreecommitdiff
path: root/benchmarks-script/quadrant/run.py
blob: 4615304761b2a10f606a2b4f4844dc042251bab2 (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
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_canvas.log')
result_path = os.path.join(cur_dir, 'results.txt')


def parseLog(log_file=log_path):
    if not os.path.exists(log_file):
        return
    res_f = open(log_file)
    lines = res_f.readlines()
    res_f.close()

    pat_str = (
                '^\s*D/Canvas\s*\(\s*\d+\s*\)\s*:'
                '\s*(?P<key>(Total|CPU|Mem|I/O|2D|3D))\s*:'
                '\s*(?P<score>\d+)\s*$'
                )
    pat = re.compile(pat_str)
    res_hash = {}
    for line in lines:
        match = pat.search(line)
        if not match:
            continue
        data = match.groupdict()
        res_hash[data['key'].strip()] = data['score'].strip()

    result_path = os.path.join(os.path.realpath(os.path.dirname(__file__)),
                               'results.txt')
    res_fd = open(result_path, 'w')
    for key in res_hash.keys():
        res_fd.write('%s=%s\n' % (key,
                                  res_hash.get(key)))
    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])
        parseLog()


if __name__ == '__main__':
    main()