summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/toaster.bbclass73
1 files changed, 73 insertions, 0 deletions
diff --git a/meta/classes/toaster.bbclass b/meta/classes/toaster.bbclass
index ec9b6c58b7..59c61c5cec 100644
--- a/meta/classes/toaster.bbclass
+++ b/meta/classes/toaster.bbclass
@@ -153,6 +153,79 @@ python toaster_image_dumpdata() {
153} 153}
154 154
155 155
156
157# collect list of buildstats files based on fired events; when the build completes, collect all stats and fire an event with collected data
158
159python toaster_collect_task_stats() {
160 import bb.build
161 import bb.event
162 import bb.data
163 import bb.utils
164 import os
165
166 def _append_read_list(v):
167 lock = bb.utils.lockfile(e.data.expand("${TOPDIR}/toaster.lock"), False, True)
168
169 with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "a") as fout:
170 bn = get_bn(e)
171 bsdir = os.path.join(e.data.getVar('BUILDSTATS_BASE', True), bn)
172 taskdir = os.path.join(bsdir, e.data.expand("${PF}"))
173 fout.write("%s:%s:%s\n" % (e.taskfile, e.taskname, os.path.join(taskdir, e.task)))
174
175 bb.utils.unlockfile(lock)
176
177 def _read_stats(filename):
178 cpu_usage = 0
179 disk_io = 0
180 startio = ''
181 endio = ''
182 pn = ''
183 taskname = ''
184 statinfo = {}
185
186 with open(filename, 'r') as task_bs:
187 for line in task_bs.readlines():
188 k,v = line.strip().split(": ", 1)
189 statinfo[k] = v
190
191 try:
192 cpu_usage = statinfo["CPU usage"]
193 endio = statinfo["EndTimeIO"]
194 startio = statinfo["StartTimeIO"]
195 except KeyError:
196 pass # we may have incomplete data here
197
198 if startio and endio:
199 disk_io = int(endio.strip('\n ')) - int(startio.strip('\n '))
200
201 if cpu_usage:
202 cpu_usage = float(cpu_usage.strip('% \n'))
203
204 return {'cpu_usage': cpu_usage, 'disk_io': disk_io}
205
206
207 if isinstance(e, (bb.build.TaskSucceeded, bb.build.TaskFailed)):
208 _append_read_list(e)
209 pass
210
211
212 if isinstance(e, bb.event.BuildCompleted):
213 events = []
214 with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "r") as fin:
215 for line in fin:
216 (taskfile, taskname, filename) = line.strip().split(":")
217 events.append((taskfile, taskname, _read_stats(filename)))
218 bb.event.fire(bb.event.MetadataEvent("BuildStatsList", events), e.data)
219 os.unlink(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"))
220}
221
222
223# set event handlers
224addhandler toaster_layerinfo_dumpdata
225toaster_layerinfo_dumpdata[eventmask] = "bb.event.TreeDataPreparationCompleted"
226
227addhandler toaster_collect_task_stats
228toaster_collect_task_stats[eventmask] = "bb.event.BuildCompleted bb.build.TaskSucceeded bb.build.TaskFailed"
156do_package[postfuncs] += "toaster_package_dumpdata " 229do_package[postfuncs] += "toaster_package_dumpdata "
157 230
158do_rootfs[postfuncs] += "toaster_image_dumpdata " 231do_rootfs[postfuncs] += "toaster_image_dumpdata "