aboutsummaryrefslogtreecommitdiffstats
path: root/meta/classes/buildprogress.bbclass
blob: d11aac89d2aab05158d10f061c6c6a241d195b80 (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
BUILD_PROGRESS_THRESHOLD = "2"

def read_task_profile(d):
    if not d.getVar('BB_CURRENTTASK', False):
        return 0
    import errno
    profilefile = d.expand('${TMPDIR}/taskprofile/${PN}.do_${BB_CURRENTTASK}')
    #bb.warn('%s.%s: %s' % (d.getVar('PN', True),d.getVar('BB_CURRENTTASK', True), profilefile))
    linecount = 0
    try:
        with open(profilefile, 'r') as f:
            linecount = int(f.read())
        #bb.warn('%s.%s: %d' % (d.getVar('PN', True),d.getVar('BB_CURRENTTASK', True),linecount))
    except IOError as e:
        if e.errno != errno.ENOENT:
            raise
    return linecount


python() {
    tasks = filter(lambda k: d.getVarFlag(k, "task"), d.keys())
    for task in tasks:
        if task not in ['do_rootfs', 'do_fetch'] and not d.getVarFlag('progress', False):
            d.setVarFlag(task, 'progress', 'linecount:${@read_task_profile(d)}')
}


progress_profile_task() {
    import time

    taskfile = e.data.expand('${TMPDIR}/taskprofile/running/%s' % e.pid)

    rmtask = False

    if isinstance(e, bb.build.TaskStarted):
        bb.utils.mkdirhier(os.path.dirname(taskfile))
        with open(taskfile, 'w') as f:
            f.write('%f' % time.time())
    elif isinstance(e, bb.build.TaskSucceeded):
        with open(taskfile, 'r') as f:
            starttime = float(f.read())
        tasktime = time.time() - starttime
        if tasktime > float(d.getVar('BUILD_PROGRESS_THRESHOLD', True)):
            linecount = 0
            with open(e.logfile, 'r') as f:
                for line in f:
                    linecount += 1

            with open(e.data.expand('${TMPDIR}/taskprofile/${PN}.%s' % e.task), 'w') as f:
                f.write('%d' % linecount)
        rmtask = True
    elif isinstance(e, bb.build.TaskFailed):
        rmtask = True

    if rmtask:
        os.remove(taskfile)
}

addhandler progress_profile_task
progress_profile_task[eventmask] = "bb.build.TaskStarted bb.build.TaskSucceeded bb.build.TaskFailed"