summaryrefslogtreecommitdiffstats
path: root/meta/classes/toaster.bbclass
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-03-08 11:27:24 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-03-09 16:58:13 +0000
commit6d89b5201b1db5ea527e1253c26e1592e3c5077f (patch)
tree1959a693b8025f845a97a94a11ab41e68874321f /meta/classes/toaster.bbclass
parent4dd3e40ed67aabe37016f4827b203a2b74983a70 (diff)
downloadpoky-6d89b5201b1db5ea527e1253c26e1592e3c5077f.tar.gz
toaster.bbclass: improve how we gather buildstats for Toaster
Clean up the code which gathers buildstats for Toaster, and modify the field names so that the correct parts of the buildstats files are used to derive the CPU usage values. Also derive elapsed time for the build here, rather than in Toaster, as we have ready access to the data in the correct format. [YOCTO #8842] (From OE-Core rev: c145624ccc77ffd07a0b4c368c0dfce525e17eac) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/toaster.bbclass')
-rw-r--r--meta/classes/toaster.bbclass70
1 files changed, 45 insertions, 25 deletions
diff --git a/meta/classes/toaster.bbclass b/meta/classes/toaster.bbclass
index 51a4c74e5b..a17501e03e 100644
--- a/meta/classes/toaster.bbclass
+++ b/meta/classes/toaster.bbclass
@@ -202,25 +202,37 @@ python toaster_collect_task_stats() {
202 import bb.utils 202 import bb.utils
203 import os 203 import os
204 204
205 toaster_statlist_file = os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist")
206
205 if not e.data.getVar('BUILDSTATS_BASE', True): 207 if not e.data.getVar('BUILDSTATS_BASE', True):
206 return # if we don't have buildstats, we cannot collect stats 208 return # if we don't have buildstats, we cannot collect stats
207 209
210 def stat_to_float(value):
211 return float(value.strip('% \n\r'))
212
208 def _append_read_list(v): 213 def _append_read_list(v):
209 lock = bb.utils.lockfile(e.data.expand("${TOPDIR}/toaster.lock"), False, True) 214 lock = bb.utils.lockfile(e.data.expand("${TOPDIR}/toaster.lock"), False, True)
210 215
211 with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "a") as fout: 216 with open(toaster_statlist_file, "a") as fout:
212 taskdir = e.data.expand("${BUILDSTATS_BASE}/${BUILDNAME}/${PF}") 217 taskdir = e.data.expand("${BUILDSTATS_BASE}/${BUILDNAME}/${PF}")
213 fout.write("%s::%s::%s::%s\n" % (e.taskfile, e.taskname, os.path.join(taskdir, e.task), e.data.expand("${PN}"))) 218 fout.write("%s::%s::%s::%s\n" % (e.taskfile, e.taskname, os.path.join(taskdir, e.task), e.data.expand("${PN}")))
214 219
215 bb.utils.unlockfile(lock) 220 bb.utils.unlockfile(lock)
216 221
217 def _read_stats(filename): 222 def _read_stats(filename):
218 cpu_usage = 0 223 # seconds
219 disk_io = 0 224 cpu_time_user = 0
220 started = '0' 225 cpu_time_system = 0
221 ended = '0' 226
222 pn = '' 227 # bytes
228 disk_io_read = 0
229 disk_io_write = 0
230
231 started = 0
232 ended = 0
233
223 taskname = '' 234 taskname = ''
235
224 statinfo = {} 236 statinfo = {}
225 237
226 with open(filename, 'r') as task_bs: 238 with open(filename, 'r') as task_bs:
@@ -228,41 +240,49 @@ python toaster_collect_task_stats() {
228 k,v = line.strip().split(": ", 1) 240 k,v = line.strip().split(": ", 1)
229 statinfo[k] = v 241 statinfo[k] = v
230 242
231 if "CPU usage" in statinfo:
232 cpu_usage = str(statinfo["CPU usage"]).strip('% \n\r')
233
234 if "IO write_bytes" in statinfo:
235 disk_io = disk_io + int(statinfo["IO write_bytes"].strip('% \n\r'))
236
237 if "IO read_bytes" in statinfo:
238 disk_io = disk_io + int(statinfo["IO read_bytes"].strip('% \n\r'))
239
240 if "Started" in statinfo: 243 if "Started" in statinfo:
241 started = str(statinfo["Started"]).strip('% \n\r') 244 started = stat_to_float(statinfo["Started"])
242 245
243 if "Ended" in statinfo: 246 if "Ended" in statinfo:
244 ended = str(statinfo["Ended"]).strip('% \n\r') 247 ended = stat_to_float(statinfo["Ended"])
245 248
246 elapsed_time = float(ended) - float(started) 249 if "Child rusage ru_utime" in statinfo:
250 cpu_time_user = cpu_time_user + stat_to_float(statinfo["Child rusage ru_utime"])
247 251
248 cpu_usage = float(cpu_usage) 252 if "Child rusage ru_stime" in statinfo:
253 cpu_time_system = cpu_time_system + stat_to_float(statinfo["Child rusage ru_stime"])
249 254
250 return {'cpu_usage': cpu_usage, 'disk_io': disk_io, 'elapsed_time': elapsed_time} 255 if "IO write_bytes" in statinfo:
256 write_bytes = int(statinfo["IO write_bytes"].strip('% \n\r'))
257 disk_io_write = disk_io_write + write_bytes
251 258
259 if "IO read_bytes" in statinfo:
260 read_bytes = int(statinfo["IO read_bytes"].strip('% \n\r'))
261 disk_io_read = disk_io_read + read_bytes
262
263 return {
264 'stat_file': filename,
265 'cpu_time_user': cpu_time_user,
266 'cpu_time_system': cpu_time_system,
267 'disk_io_read': disk_io_read,
268 'disk_io_write': disk_io_write,
269 'started': started,
270 'ended': ended
271 }
252 272
253 if isinstance(e, (bb.build.TaskSucceeded, bb.build.TaskFailed)): 273 if isinstance(e, (bb.build.TaskSucceeded, bb.build.TaskFailed)):
254 _append_read_list(e) 274 _append_read_list(e)
255 pass 275 pass
256 276
257 277 if isinstance(e, bb.event.BuildCompleted) and os.path.exists(toaster_statlist_file):
258 if isinstance(e, bb.event.BuildCompleted) and os.path.exists(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist")):
259 events = [] 278 events = []
260 with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "r") as fin: 279 with open(toaster_statlist_file, "r") as fin:
261 for line in fin: 280 for line in fin:
262 (taskfile, taskname, filename, recipename) = line.strip().split("::") 281 (taskfile, taskname, filename, recipename) = line.strip().split("::")
263 events.append((taskfile, taskname, _read_stats(filename), recipename)) 282 stats = _read_stats(filename)
283 events.append((taskfile, taskname, stats, recipename))
264 bb.event.fire(bb.event.MetadataEvent("BuildStatsList", events), e.data) 284 bb.event.fire(bb.event.MetadataEvent("BuildStatsList", events), e.data)
265 os.unlink(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist")) 285 os.unlink(toaster_statlist_file)
266} 286}
267 287
268# dump relevant build history data as an event when the build is completed 288# dump relevant build history data as an event when the build is completed