diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-12-03 22:01:25 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-12-06 14:39:29 +0000 |
commit | ccd7f12b1c95b546ef79204ad0832b88a595d0ea (patch) | |
tree | 04cd240e7ca62459392b8483ba3f631574524fc2 /bitbake/lib/bb/ui | |
parent | 109ef2e5c4161a2c0ac58bede3daa48c7b4881ec (diff) | |
download | poky-ccd7f12b1c95b546ef79204ad0832b88a595d0ea.tar.gz |
bitbake: knotty/uihelper: Switch from pids to tids for Task event management
We've seen cases where a task can execute with a given pid, complete
and a new task can start using the same pid before the UI handler has
had time to adapt.
Traceback (most recent call last):
File "/home/pokybuild/yocto-worker/qemux86-alt/build/bitbake/lib/bb/ui/knotty.py", line 484, in main
helper.eventHandler(event)
File "/home/pokybuild/yocto-worker/qemux86-alt/build/bitbake/lib/bb/ui/uihelper.py", line 30, in eventHandler
del self.running_tasks[event.pid]
KeyError: 13490
This means using pids to match up events on the UI side is a bad
idea. Change the code to use task ids instead. There is a small
amount of fuzzy matching for the progress information since there
is no task information there and we don't want the overhead of a task
ID in every event, however since pid reuse is unlikely, we can live
with a progress bar not quite working properly in a corner case like
this.
[YOCTO #13667]
(Bitbake rev: e427eafa1bb04008d12100ccc5c862122bba53e0)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui')
-rw-r--r-- | bitbake/lib/bb/ui/knotty.py | 12 | ||||
-rw-r--r-- | bitbake/lib/bb/ui/uihelper.py | 39 |
2 files changed, 30 insertions, 21 deletions
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py index 35736ade03..bd9911cf6f 100644 --- a/bitbake/lib/bb/ui/knotty.py +++ b/bitbake/lib/bb/ui/knotty.py | |||
@@ -255,19 +255,19 @@ class TerminalFilter(object): | |||
255 | start_time = activetasks[t].get("starttime", None) | 255 | start_time = activetasks[t].get("starttime", None) |
256 | if not pbar or pbar.bouncing != (progress < 0): | 256 | if not pbar or pbar.bouncing != (progress < 0): |
257 | if progress < 0: | 257 | if progress < 0: |
258 | pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.BouncingSlider(), ''], extrapos=2, resize_handler=self.sigwinch_handle) | 258 | pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], activetasks[t]["pid"]), 100, widgets=[progressbar.BouncingSlider(), ''], extrapos=2, resize_handler=self.sigwinch_handle) |
259 | pbar.bouncing = True | 259 | pbar.bouncing = True |
260 | else: | 260 | else: |
261 | pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=4, resize_handler=self.sigwinch_handle) | 261 | pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], activetasks[t]["pid"]), 100, widgets=[progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=4, resize_handler=self.sigwinch_handle) |
262 | pbar.bouncing = False | 262 | pbar.bouncing = False |
263 | activetasks[t]["progressbar"] = pbar | 263 | activetasks[t]["progressbar"] = pbar |
264 | tasks.append((pbar, progress, rate, start_time)) | 264 | tasks.append((pbar, progress, rate, start_time)) |
265 | else: | 265 | else: |
266 | start_time = activetasks[t].get("starttime", None) | 266 | start_time = activetasks[t].get("starttime", None) |
267 | if start_time: | 267 | if start_time: |
268 | tasks.append("%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), t)) | 268 | tasks.append("%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), activetasks[t]["pid"])) |
269 | else: | 269 | else: |
270 | tasks.append("%s (pid %s)" % (activetasks[t]["title"], t)) | 270 | tasks.append("%s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"])) |
271 | 271 | ||
272 | if self.main.shutdown: | 272 | if self.main.shutdown: |
273 | content = "Waiting for %s running tasks to finish:" % len(activetasks) | 273 | content = "Waiting for %s running tasks to finish:" % len(activetasks) |
@@ -517,8 +517,8 @@ def main(server, eventHandler, params, tf = TerminalFilter): | |||
517 | continue | 517 | continue |
518 | 518 | ||
519 | # Prefix task messages with recipe/task | 519 | # Prefix task messages with recipe/task |
520 | if event.taskpid in helper.running_tasks and event.levelno != format.PLAIN: | 520 | if event.taskpid in helper.pidmap and event.levelno != format.PLAIN: |
521 | taskinfo = helper.running_tasks[event.taskpid] | 521 | taskinfo = helper.running_tasks[helper.pidmap[event.taskpid]] |
522 | event.msg = taskinfo['title'] + ': ' + event.msg | 522 | event.msg = taskinfo['title'] + ': ' + event.msg |
523 | if hasattr(event, 'fn'): | 523 | if hasattr(event, 'fn'): |
524 | event.msg = event.fn + ': ' + event.msg | 524 | event.msg = event.fn + ': ' + event.msg |
diff --git a/bitbake/lib/bb/ui/uihelper.py b/bitbake/lib/bb/ui/uihelper.py index c8dd7df087..48d808ae28 100644 --- a/bitbake/lib/bb/ui/uihelper.py +++ b/bitbake/lib/bb/ui/uihelper.py | |||
@@ -15,39 +15,48 @@ class BBUIHelper: | |||
15 | # Running PIDs preserves the order tasks were executed in | 15 | # Running PIDs preserves the order tasks were executed in |
16 | self.running_pids = [] | 16 | self.running_pids = [] |
17 | self.failed_tasks = [] | 17 | self.failed_tasks = [] |
18 | self.pidmap = {} | ||
18 | self.tasknumber_current = 0 | 19 | self.tasknumber_current = 0 |
19 | self.tasknumber_total = 0 | 20 | self.tasknumber_total = 0 |
20 | 21 | ||
21 | def eventHandler(self, event): | 22 | def eventHandler(self, event): |
23 | # PIDs are a bad idea as they can be reused before we process all UI events. | ||
24 | # We maintain a 'fuzzy' match for TaskProgress since there is no other way to match | ||
25 | def removetid(pid, tid): | ||
26 | self.running_pids.remove(tid) | ||
27 | del self.running_tasks[tid] | ||
28 | if self.pidmap[pid] == tid: | ||
29 | del self.pidmap[pid] | ||
30 | self.needUpdate = True | ||
31 | |||
22 | if isinstance(event, bb.build.TaskStarted): | 32 | if isinstance(event, bb.build.TaskStarted): |
33 | tid = event._fn + ":" + event._task | ||
23 | if event._mc != "default": | 34 | if event._mc != "default": |
24 | self.running_tasks[event.pid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time() } | 35 | self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid } |
25 | else: | 36 | else: |
26 | self.running_tasks[event.pid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time() } | 37 | self.running_tasks[tid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid } |
27 | self.running_pids.append(event.pid) | 38 | self.running_pids.append(tid) |
39 | self.pidmap[event.pid] = tid | ||
28 | self.needUpdate = True | 40 | self.needUpdate = True |
29 | elif isinstance(event, bb.build.TaskSucceeded): | 41 | elif isinstance(event, bb.build.TaskSucceeded): |
30 | del self.running_tasks[event.pid] | 42 | tid = event._fn + ":" + event._task |
31 | self.running_pids.remove(event.pid) | 43 | removetid(event.pid, tid) |
32 | self.needUpdate = True | ||
33 | elif isinstance(event, bb.build.TaskFailedSilent): | 44 | elif isinstance(event, bb.build.TaskFailedSilent): |
34 | del self.running_tasks[event.pid] | 45 | tid = event._fn + ":" + event._task |
35 | self.running_pids.remove(event.pid) | 46 | removetid(event.pid, tid) |
36 | # Don't add to the failed tasks list since this is e.g. a setscene task failure | 47 | # Don't add to the failed tasks list since this is e.g. a setscene task failure |
37 | self.needUpdate = True | ||
38 | elif isinstance(event, bb.build.TaskFailed): | 48 | elif isinstance(event, bb.build.TaskFailed): |
39 | del self.running_tasks[event.pid] | 49 | tid = event._fn + ":" + event._task |
40 | self.running_pids.remove(event.pid) | 50 | removetid(event.pid, tid) |
41 | self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)}) | 51 | self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)}) |
42 | self.needUpdate = True | ||
43 | elif isinstance(event, bb.runqueue.runQueueTaskStarted): | 52 | elif isinstance(event, bb.runqueue.runQueueTaskStarted): |
44 | self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + 1 | 53 | self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + 1 |
45 | self.tasknumber_total = event.stats.total | 54 | self.tasknumber_total = event.stats.total |
46 | self.needUpdate = True | 55 | self.needUpdate = True |
47 | elif isinstance(event, bb.build.TaskProgress): | 56 | elif isinstance(event, bb.build.TaskProgress): |
48 | if event.pid > 0: | 57 | if event.pid > 0 and event.pid in self.pidmap: |
49 | self.running_tasks[event.pid]['progress'] = event.progress | 58 | self.running_tasks[self.pidmap[event.pid]]['progress'] = event.progress |
50 | self.running_tasks[event.pid]['rate'] = event.rate | 59 | self.running_tasks[self.pidmap[event.pid]]['rate'] = event.rate |
51 | self.needUpdate = True | 60 | self.needUpdate = True |
52 | else: | 61 | else: |
53 | return False | 62 | return False |