summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/buildstats.bbclass41
1 files changed, 20 insertions, 21 deletions
diff --git a/meta/classes/buildstats.bbclass b/meta/classes/buildstats.bbclass
index 73e0b2ab64..4fa6981dd6 100644
--- a/meta/classes/buildstats.bbclass
+++ b/meta/classes/buildstats.bbclass
@@ -20,7 +20,7 @@ def get_cputime():
20 fields = f.readline().rstrip().split()[1:] 20 fields = f.readline().rstrip().split()[1:]
21 return sum(int(field) for field in fields) 21 return sum(int(field) for field in fields)
22 22
23def set_timedata(var, data, server_time=None): 23def set_timedata(var, d, server_time=None):
24 import time 24 import time
25 if server_time: 25 if server_time:
26 time = server_time 26 time = server_time
@@ -28,11 +28,11 @@ def set_timedata(var, data, server_time=None):
28 time = time.time() 28 time = time.time()
29 cputime = get_cputime() 29 cputime = get_cputime()
30 proctime = get_process_cputime(os.getpid()) 30 proctime = get_process_cputime(os.getpid())
31 data.setVar(var, (time, cputime, proctime)) 31 d.setVar(var, (time, cputime, proctime))
32 32
33def get_timedata(var, data, server_time=None): 33def get_timedata(var, d, server_time=None):
34 import time 34 import time
35 timedata = data.getVar(var, False) 35 timedata = d.getVar(var, False)
36 if timedata is None: 36 if timedata is None:
37 return 37 return
38 oldtime, oldcpu, oldproc = timedata 38 oldtime, oldcpu, oldproc = timedata
@@ -49,15 +49,15 @@ def get_timedata(var, data, server_time=None):
49 cpuperc = None 49 cpuperc = None
50 return timediff, cpuperc 50 return timediff, cpuperc
51 51
52def write_task_data(status, logfile, e): 52def write_task_data(status, logfile, e, d):
53 bn = e.data.getVar('BUILDNAME', True) 53 bn = d.getVar('BUILDNAME', True)
54 bsdir = os.path.join(e.data.getVar('BUILDSTATS_BASE', True), bn) 54 bsdir = os.path.join(d.getVar('BUILDSTATS_BASE', True), bn)
55 with open(os.path.join(logfile), "a") as f: 55 with open(os.path.join(logfile), "a") as f:
56 timedata = get_timedata("__timedata_task", e.data, e.time) 56 timedata = get_timedata("__timedata_task", d, e.time)
57 if timedata: 57 if timedata:
58 elapsedtime, cpu = timedata 58 elapsedtime, cpu = timedata
59 f.write(bb.data.expand("${PF}: %s: Elapsed time: %0.2f seconds \n" % 59 f.write(d.expand("${PF}: %s: Elapsed time: %0.2f seconds \n" %
60 (e.task, elapsedtime), e.data)) 60 (e.task, elapsedtime)))
61 if cpu: 61 if cpu:
62 f.write("CPU usage: %0.1f%% \n" % cpu) 62 f.write("CPU usage: %0.1f%% \n" % cpu)
63 if status is "passed": 63 if status is "passed":
@@ -69,12 +69,11 @@ def write_task_data(status, logfile, e):
69python run_buildstats () { 69python run_buildstats () {
70 import bb.build 70 import bb.build
71 import bb.event 71 import bb.event
72 import bb.data
73 import time, subprocess, platform 72 import time, subprocess, platform
74 73
75 bn = e.data.getVar('BUILDNAME', True) 74 bn = d.getVar('BUILDNAME', True)
76 bsdir = os.path.join(e.data.getVar('BUILDSTATS_BASE', True), bn) 75 bsdir = os.path.join(d.getVar('BUILDSTATS_BASE', True), bn)
77 taskdir = os.path.join(bsdir, e.data.getVar('PF', True)) 76 taskdir = os.path.join(bsdir, d.getVar('PF', True))
78 77
79 if isinstance(e, bb.event.BuildStarted): 78 if isinstance(e, bb.event.BuildStarted):
80 ######################################################################## 79 ########################################################################
@@ -82,7 +81,7 @@ python run_buildstats () {
82 # set the buildname 81 # set the buildname
83 ######################################################################## 82 ########################################################################
84 bb.utils.mkdirhier(bsdir) 83 bb.utils.mkdirhier(bsdir)
85 set_timedata("__timedata_build", e.data) 84 set_timedata("__timedata_build", d)
86 build_time = os.path.join(bsdir, "build_stats") 85 build_time = os.path.join(bsdir, "build_stats")
87 # write start of build into build_time 86 # write start of build into build_time
88 with open(build_time, "a") as f: 87 with open(build_time, "a") as f:
@@ -100,7 +99,7 @@ python run_buildstats () {
100 ######################################################################## 99 ########################################################################
101 # Write build statistics for the build 100 # Write build statistics for the build
102 ######################################################################## 101 ########################################################################
103 timedata = get_timedata("__timedata_build", e.data) 102 timedata = get_timedata("__timedata_build", d)
104 if timedata: 103 if timedata:
105 time, cpu = timedata 104 time, cpu = timedata
106 # write end of build and cpu used into build_time 105 # write end of build and cpu used into build_time
@@ -109,7 +108,7 @@ python run_buildstats () {
109 f.write("CPU usage: %0.1f%% \n" % cpu) 108 f.write("CPU usage: %0.1f%% \n" % cpu)
110 109
111 if isinstance(e, bb.build.TaskStarted): 110 if isinstance(e, bb.build.TaskStarted):
112 set_timedata("__timedata_task", e.data, e.time) 111 set_timedata("__timedata_task", d, e.time)
113 bb.utils.mkdirhier(taskdir) 112 bb.utils.mkdirhier(taskdir)
114 # write into the task event file the name and start time 113 # write into the task event file the name and start time
115 with open(os.path.join(taskdir, e.task), "a") as f: 114 with open(os.path.join(taskdir, e.task), "a") as f:
@@ -117,16 +116,16 @@ python run_buildstats () {
117 f.write("Started: %0.2f \n" % e.time) 116 f.write("Started: %0.2f \n" % e.time)
118 117
119 elif isinstance(e, bb.build.TaskSucceeded): 118 elif isinstance(e, bb.build.TaskSucceeded):
120 write_task_data("passed", os.path.join(taskdir, e.task), e) 119 write_task_data("passed", os.path.join(taskdir, e.task), e, d)
121 if e.task == "do_rootfs": 120 if e.task == "do_rootfs":
122 bs = os.path.join(bsdir, "build_stats") 121 bs = os.path.join(bsdir, "build_stats")
123 with open(bs, "a") as f: 122 with open(bs, "a") as f:
124 rootfs = e.data.getVar('IMAGE_ROOTFS', True) 123 rootfs = d.getVar('IMAGE_ROOTFS', True)
125 rootfs_size = subprocess.Popen(["du", "-sh", rootfs], stdout=subprocess.PIPE).stdout.read() 124 rootfs_size = subprocess.Popen(["du", "-sh", rootfs], stdout=subprocess.PIPE).stdout.read()
126 f.write("Uncompressed Rootfs size: %s" % rootfs_size) 125 f.write("Uncompressed Rootfs size: %s" % rootfs_size)
127 126
128 elif isinstance(e, bb.build.TaskFailed): 127 elif isinstance(e, bb.build.TaskFailed):
129 write_task_data("failed", os.path.join(taskdir, e.task), e) 128 write_task_data("failed", os.path.join(taskdir, e.task), e, d)
130 ######################################################################## 129 ########################################################################
131 # Lets make things easier and tell people where the build failed in 130 # Lets make things easier and tell people where the build failed in
132 # build_status. We do this here because BuildCompleted triggers no 131 # build_status. We do this here because BuildCompleted triggers no
@@ -134,7 +133,7 @@ python run_buildstats () {
134 ######################################################################## 133 ########################################################################
135 build_status = os.path.join(bsdir, "build_stats") 134 build_status = os.path.join(bsdir, "build_stats")
136 with open(build_status, "a") as f: 135 with open(build_status, "a") as f:
137 f.write(e.data.expand("Failed at: ${PF} at task: %s \n" % e.task)) 136 f.write(d.expand("Failed at: ${PF} at task: %s \n" % e.task))
138} 137}
139 138
140addhandler run_buildstats 139addhandler run_buildstats