diff options
| author | Benjamin Szőke <egyszeregy@freemail.hu> | 2025-01-25 13:27:50 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-08-19 11:33:23 +0100 |
| commit | c5977954a800957bae519d88b5af54578f93cfb4 (patch) | |
| tree | 73e87e22f8999a2addfb493aa08fd2ddadf1d952 /bitbake/lib/bb/ui | |
| parent | d23ce1b4dbf9a32e7a8c1380b57956b6b2ada514 (diff) | |
| download | poky-c5977954a800957bae519d88b5af54578f93cfb4.tar.gz | |
bitbake: knotty: Use a StringIO buffer for update footer.
Optimize printing in footer update with use a StringIO buffer and it
prints content to terminal in a single call in every cycle.
(Bitbake rev: 32ba622d78f20b231f30f848379b4bbc3d7414da)
Signed-off-by: Benjamin Szőke <egyszeregy@freemail.hu>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
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 | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py index 9a589a5c8e..c4ab553a3a 100644 --- a/bitbake/lib/bb/ui/knotty.py +++ b/bitbake/lib/bb/ui/knotty.py | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | from __future__ import division | 11 | from __future__ import division |
| 12 | 12 | ||
| 13 | import io | ||
| 13 | import os | 14 | import os |
| 14 | import sys | 15 | import sys |
| 15 | import logging | 16 | import logging |
| @@ -168,6 +169,9 @@ class TerminalFilter(object): | |||
| 168 | self.lasttime = None | 169 | self.lasttime = None |
| 169 | self.quiet = quiet | 170 | self.quiet = quiet |
| 170 | 171 | ||
| 172 | self._footer_buf = io.StringIO() | ||
| 173 | self._footer_lines = None | ||
| 174 | |||
| 171 | if not self.interactive: | 175 | if not self.interactive: |
| 172 | return | 176 | return |
| 173 | 177 | ||
| @@ -215,11 +219,11 @@ class TerminalFilter(object): | |||
| 215 | 219 | ||
| 216 | def clearFooter(self): | 220 | def clearFooter(self): |
| 217 | if self.footer_present: | 221 | if self.footer_present: |
| 218 | lines = self.footer_present | 222 | sys.stdout.buffer.write(self.curses.tparm(self.cuu, self._footer_lines)) |
| 219 | sys.stdout.buffer.write(self.curses.tparm(self.cuu, lines)) | ||
| 220 | sys.stdout.buffer.write(self.curses.tparm(self.ed)) | 223 | sys.stdout.buffer.write(self.curses.tparm(self.ed)) |
| 221 | sys.stdout.flush() | 224 | sys.stdout.flush() |
| 222 | self.footer_present = False | 225 | self.footer_present = False |
| 226 | self._footer_lines = None | ||
| 223 | 227 | ||
| 224 | def elapsed(self, sec): | 228 | def elapsed(self, sec): |
| 225 | hrs = int(sec / 3600.0) | 229 | hrs = int(sec / 3600.0) |
| @@ -253,10 +257,14 @@ class TerminalFilter(object): | |||
| 253 | if self.footer_present and not self.helper.needUpdate: | 257 | if self.footer_present and not self.helper.needUpdate: |
| 254 | return | 258 | return |
| 255 | self.helper.needUpdate = False | 259 | self.helper.needUpdate = False |
| 256 | if self.footer_present: | ||
| 257 | self.clearFooter() | ||
| 258 | if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks): | 260 | if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks): |
| 261 | self.clearFooter() | ||
| 259 | return | 262 | return |
| 263 | |||
| 264 | # Clear footer buffer. | ||
| 265 | self._footer_buf.truncate(0) | ||
| 266 | self._footer_buf.seek(0) | ||
| 267 | |||
| 260 | tasks = [] | 268 | tasks = [] |
| 261 | for t in runningpids: | 269 | for t in runningpids: |
| 262 | start_time = activetasks[t].get("starttime", None) | 270 | start_time = activetasks[t].get("starttime", None) |
| @@ -275,6 +283,7 @@ class TerminalFilter(object): | |||
| 275 | else: | 283 | else: |
| 276 | pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=5, resize_handler=self.sigwinch_handle) | 284 | pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=5, resize_handler=self.sigwinch_handle) |
| 277 | pbar.bouncing = False | 285 | pbar.bouncing = False |
| 286 | pbar.fd = self._footer_buf | ||
| 278 | activetasks[t]["progressbar"] = pbar | 287 | activetasks[t]["progressbar"] = pbar |
| 279 | tasks.append((pbar, msg, progress, rate, start_time)) | 288 | tasks.append((pbar, msg, progress, rate, start_time)) |
| 280 | else: | 289 | else: |
| @@ -285,7 +294,7 @@ class TerminalFilter(object): | |||
| 285 | "Waiting for %s running tasks to finish", len(activetasks)) | 294 | "Waiting for %s running tasks to finish", len(activetasks)) |
| 286 | if not self.quiet: | 295 | if not self.quiet: |
| 287 | content += ':' | 296 | content += ':' |
| 288 | print(content) | 297 | print(content, file=self._footer_buf) |
| 289 | else: | 298 | else: |
| 290 | scene_tasks = "%s of %s" % (self.helper.setscene_current, self.helper.setscene_total) | 299 | scene_tasks = "%s of %s" % (self.helper.setscene_current, self.helper.setscene_total) |
| 291 | cur_tasks = "%s of %s" % (self.helper.tasknumber_current, self.helper.tasknumber_total) | 300 | cur_tasks = "%s of %s" % (self.helper.tasknumber_current, self.helper.tasknumber_total) |
| @@ -294,7 +303,7 @@ class TerminalFilter(object): | |||
| 294 | if not self.quiet: | 303 | if not self.quiet: |
| 295 | msg = "Setscene tasks: %s" % scene_tasks | 304 | msg = "Setscene tasks: %s" % scene_tasks |
| 296 | content += msg + "\n" | 305 | content += msg + "\n" |
| 297 | print(msg) | 306 | print(msg, file=self._footer_buf) |
| 298 | 307 | ||
| 299 | if self.quiet: | 308 | if self.quiet: |
| 300 | msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks) | 309 | msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks) |
| @@ -306,11 +315,12 @@ class TerminalFilter(object): | |||
| 306 | if not self.main_progress or self.main_progress.maxval != maxtask: | 315 | if not self.main_progress or self.main_progress.maxval != maxtask: |
| 307 | widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()] | 316 | widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()] |
| 308 | self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle) | 317 | self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle) |
| 318 | self.main_progress.fd = self._footer_buf | ||
| 309 | self.main_progress.start(False) | 319 | self.main_progress.start(False) |
| 310 | self.main_progress.setmessage(msg) | 320 | self.main_progress.setmessage(msg) |
| 311 | progress = max(0, self.helper.tasknumber_current - 1) | 321 | progress = max(0, self.helper.tasknumber_current - 1) |
| 312 | content += self.main_progress.update(progress) | 322 | content += self.main_progress.update(progress) |
| 313 | print('') | 323 | print('', file=self._footer_buf) |
| 314 | lines = self.getlines(content) | 324 | lines = self.getlines(content) |
| 315 | if not self.quiet: | 325 | if not self.quiet: |
| 316 | for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]): | 326 | for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]): |
| @@ -326,15 +336,20 @@ class TerminalFilter(object): | |||
| 326 | content = pbar.update(progress) | 336 | content = pbar.update(progress) |
| 327 | else: | 337 | else: |
| 328 | content = pbar.update(1) | 338 | content = pbar.update(1) |
| 329 | print('') | 339 | print('', file=self._footer_buf) |
| 330 | else: | 340 | else: |
| 331 | content = "%s: %s" % (tasknum, task) | 341 | content = "%s: %s" % (tasknum, task) |
| 332 | print(content) | 342 | print(content, file=self._footer_buf) |
| 333 | lines = lines + self.getlines(content) | 343 | lines = lines + self.getlines(content) |
| 334 | self.footer_present = lines | ||
| 335 | self.lastpids = runningpids[:] | 344 | self.lastpids = runningpids[:] |
| 336 | self.lastcount = self.helper.tasknumber_current | 345 | self.lastcount = self.helper.tasknumber_current |
| 337 | 346 | ||
| 347 | # Clear footer and Print buffer. | ||
| 348 | self.clearFooter() | ||
| 349 | print(self._footer_buf.getvalue(), end='') | ||
| 350 | self._footer_lines = lines | ||
| 351 | self.footer_present = True | ||
| 352 | |||
| 338 | def getlines(self, content): | 353 | def getlines(self, content): |
| 339 | lines = 0 | 354 | lines = 0 |
| 340 | for line in content.split("\n"): | 355 | for line in content.split("\n"): |
| @@ -342,6 +357,7 @@ class TerminalFilter(object): | |||
| 342 | return lines | 357 | return lines |
| 343 | 358 | ||
| 344 | def finish(self): | 359 | def finish(self): |
| 360 | self._footer_buf.close() | ||
| 345 | if self.stdinbackup: | 361 | if self.stdinbackup: |
| 346 | fd = sys.stdin.fileno() | 362 | fd = sys.stdin.fileno() |
| 347 | self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup) | 363 | self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup) |
