summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2013-11-27 16:21:00 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-12-10 11:16:10 +0000
commit5145b5a6c1a50df10006bb0100fbd0e890af15d9 (patch)
treec91e0b28bfc605bb3c377803f6a9b48d5669c8d1 /meta/classes
parent8ee7b080682e96a42c1cd8dfb299dbd997889a62 (diff)
downloadast2050-yocto-poky-5145b5a6c1a50df10006bb0100fbd0e890af15d9.zip
ast2050-yocto-poky-5145b5a6c1a50df10006bb0100fbd0e890af15d9.tar.gz
toaster.bbclass: read build stats
In the process of removing the local system accesses from toaster UI (which must be able to run remotely), the code to read build stats is moved from Bitbake Toaster UI to the server-side toaster.bbclass The code will accumulate a list of stat files to be read at build completion. When the build completes, the whole data list is read and sent through in a single event. [YOCTO #5604] (From OE-Core rev: 0c455c0708335eecd1e659680b6cddb4782e80fa) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-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 ec9b6c5..59c61c5 100644
--- a/meta/classes/toaster.bbclass
+++ b/meta/classes/toaster.bbclass
@@ -153,6 +153,79 @@ python toaster_image_dumpdata() {
}
+
+# collect list of buildstats files based on fired events; when the build completes, collect all stats and fire an event with collected data
+
+python toaster_collect_task_stats() {
+ import bb.build
+ import bb.event
+ import bb.data
+ import bb.utils
+ import os
+
+ def _append_read_list(v):
+ lock = bb.utils.lockfile(e.data.expand("${TOPDIR}/toaster.lock"), False, True)
+
+ with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "a") as fout:
+ bn = get_bn(e)
+ bsdir = os.path.join(e.data.getVar('BUILDSTATS_BASE', True), bn)
+ taskdir = os.path.join(bsdir, e.data.expand("${PF}"))
+ fout.write("%s:%s:%s\n" % (e.taskfile, e.taskname, os.path.join(taskdir, e.task)))
+
+ bb.utils.unlockfile(lock)
+
+ def _read_stats(filename):
+ cpu_usage = 0
+ disk_io = 0
+ startio = ''
+ endio = ''
+ pn = ''
+ taskname = ''
+ statinfo = {}
+
+ with open(filename, 'r') as task_bs:
+ for line in task_bs.readlines():
+ k,v = line.strip().split(": ", 1)
+ statinfo[k] = v
+
+ try:
+ cpu_usage = statinfo["CPU usage"]
+ endio = statinfo["EndTimeIO"]
+ startio = statinfo["StartTimeIO"]
+ except KeyError:
+ pass # we may have incomplete data here
+
+ if startio and endio:
+ disk_io = int(endio.strip('\n ')) - int(startio.strip('\n '))
+
+ if cpu_usage:
+ cpu_usage = float(cpu_usage.strip('% \n'))
+
+ return {'cpu_usage': cpu_usage, 'disk_io': disk_io}
+
+
+ if isinstance(e, (bb.build.TaskSucceeded, bb.build.TaskFailed)):
+ _append_read_list(e)
+ pass
+
+
+ if isinstance(e, bb.event.BuildCompleted):
+ events = []
+ with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "r") as fin:
+ for line in fin:
+ (taskfile, taskname, filename) = line.strip().split(":")
+ events.append((taskfile, taskname, _read_stats(filename)))
+ bb.event.fire(bb.event.MetadataEvent("BuildStatsList", events), e.data)
+ os.unlink(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"))
+}
+
+
+# set event handlers
+addhandler toaster_layerinfo_dumpdata
+toaster_layerinfo_dumpdata[eventmask] = "bb.event.TreeDataPreparationCompleted"
+
+addhandler toaster_collect_task_stats
+toaster_collect_task_stats[eventmask] = "bb.event.BuildCompleted bb.build.TaskSucceeded bb.build.TaskFailed"
do_package[postfuncs] += "toaster_package_dumpdata "
do_rootfs[postfuncs] += "toaster_image_dumpdata "
OpenPOWER on IntegriCloud