~pwlars/ubuntu-test-cases/auto-offline-devices

« back to all changes in this revision

Viewing changes to tests/bootspeed/bootchart/run.py

  • Committer: Andy Doan
  • Date: 2014-04-23 19:21:18 UTC
  • mto: This revision was merged to the branch mainline in revision 221.
  • Revision ID: andy.doan@canonical.com-20140423192118-pc37rpziylei3nni
add bootchart test

In order to comply with the qa-dashboard expectations, this test
produces a "boot.json" file that re-labels steps to things it
expects like xorg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import datetime
 
4
import json
 
5
import os
 
6
import shutil
 
7
import subprocess
 
8
 
 
9
 
 
10
def _get_dashboard_data(timing_file):
 
11
    info = subprocess.check_output(['adb', 'shell', 'system-image-cli', '-i'])
 
12
    data = {
 
13
        'image_md5': 'n/a',
 
14
        'machine_mac': 'ff:ff:ff:ff:ff:ff',
 
15
        'ran_at': datetime.datetime.now().isoformat(),
 
16
        'kernel_init': 0.0,
 
17
    }
 
18
    for line in info.split('\r\n'):
 
19
        if not line:
 
20
            continue
 
21
        key, val = line.split(':', 1)
 
22
        val = val.strip()
 
23
        if key == 'device name':
 
24
            data['image_arch'] = val
 
25
        elif key == 'channel':
 
26
            # get 'touch' and 'trusty' from something like:
 
27
            # ubuntu-touch/trusty-proposed
 
28
            variant, release = val.split('/')
 
29
            data['image_variant'] = variant.split('-')[1]
 
30
            data['image_release'] = release.split('-')[0]
 
31
        elif key == 'version version':
 
32
            data['number'] = val
 
33
        elif key == 'version ubuntu':
 
34
            data['version_ubuntu'] = val
 
35
        elif key == 'version device':
 
36
            data['version_device'] = val
 
37
    data['build_number'] = '%s:%s:%s' % (
 
38
        data['number'], data['version_ubuntu'], data['version_device'])
 
39
 
 
40
    with open(timing_file) as f:
 
41
        # the timings file is sequence of readings (in hundredths of a second):
 
42
        #  line 0 - the total boot time
 
43
        #  line X - the time from boot until the given annotation *started*
 
44
        timings = [float(x) / 100.0 for x in f.read().split('\n') if x]
 
45
        data['boot'] = timings[0]
 
46
        data['kernel'] = timings[1]
 
47
        data['plumbing'] = timings[2] - timings[1]
 
48
        data['xorg'] = timings[3] - timings[2]
 
49
        data['desktop'] = timings[0] - timings[3]
 
50
    return data
 
51
 
 
52
 
 
53
def chart(results_dir):
 
54
    timings = os.path.join(results_dir, 'timings')
 
55
    os.environ['CHARTOPTS'] = ' '.join([
 
56
        '--crop-after=unity8',
 
57
        '--annotate=mountall',
 
58
        '--annotate=lightdm',
 
59
        '--annotate=unity8',
 
60
        '--annotate-file=%s' % timings,
 
61
    ])
 
62
    subprocess.check_call(['phablet-bootchart', '-n', '-k',
 
63
                           '-w', '/home/ubuntu/magners-wifi',
 
64
                           '-o', results_dir])
 
65
    data = _get_dashboard_data(timings)
 
66
    with open(os.path.join(results_dir, 'boot.json'), 'w') as f:
 
67
        json.dump(data, f, indent=4)
 
68
 
 
69
if __name__ == '__main__':
 
70
    if os.path.exists('/tmp/results'):
 
71
        shutil.rmtree('/tmp/results')
 
72
    os.mkdir('/tmp/results')
 
73
    for x in range(3):
 
74
        chart('/tmp/results/%d' % (x + 1))