diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2016-09-29 17:28:01 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-10-01 21:45:55 +0100 |
commit | e05309194a962f817b043c8f1014886cfc324470 (patch) | |
tree | 40d20e878203ce997e7fe497fcea28582a81bb9b /scripts/buildstats-diff | |
parent | 7113ac943920e61b9a8427410c8362cf9d33d19c (diff) | |
download | poky-e05309194a962f817b043c8f1014886cfc324470.tar.gz |
scripts/buildstats-diff: do not hardcode field widths in output
Dynamically adjust the width of all fields in task diff output. Makes
it easier to print other units than cputime, too.
(From OE-Core rev: 559b858f2a3712ec21debb71681593bd7cf55041)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/buildstats-diff')
-rwxr-xr-x | scripts/buildstats-diff | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/scripts/buildstats-diff b/scripts/buildstats-diff index 22c44ff2bb..56ac840d51 100755 --- a/scripts/buildstats-diff +++ b/scripts/buildstats-diff | |||
@@ -276,13 +276,14 @@ def print_ver_diff(bs1, bs2): | |||
276 | def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)): | 276 | def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)): |
277 | """Diff task execution times""" | 277 | """Diff task execution times""" |
278 | tasks_diff = [] | 278 | tasks_diff = [] |
279 | pkg_maxlen = 0 | 279 | |
280 | task_maxlen = 0 | 280 | if min_val: |
281 | print("Ignoring tasks shorter than {}s".format(min_val)) | ||
282 | if min_absdiff: | ||
283 | print("Ignoring time differences shorter than {}s".format(min_absdiff)) | ||
281 | 284 | ||
282 | pkgs = set(bs1.keys()).union(set(bs2.keys())) | 285 | pkgs = set(bs1.keys()).union(set(bs2.keys())) |
283 | for pkg in pkgs: | 286 | for pkg in pkgs: |
284 | if len(pkg) > pkg_maxlen: | ||
285 | pkg_maxlen = len(pkg) | ||
286 | tasks1 = bs1[pkg]['tasks'] if pkg in bs1 else {} | 287 | tasks1 = bs1[pkg]['tasks'] if pkg in bs1 else {} |
287 | tasks2 = bs2[pkg]['tasks'] if pkg in bs2 else {} | 288 | tasks2 = bs2[pkg]['tasks'] if pkg in bs2 else {} |
288 | if not tasks1: | 289 | if not tasks1: |
@@ -293,9 +294,6 @@ def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)): | |||
293 | pkg_op = ' ' | 294 | pkg_op = ' ' |
294 | 295 | ||
295 | for task in set(tasks1.keys()).union(set(tasks2.keys())): | 296 | for task in set(tasks1.keys()).union(set(tasks2.keys())): |
296 | if len(task) > task_maxlen: | ||
297 | task_maxlen = len(task) | ||
298 | |||
299 | t1 = bs1[pkg]['tasks'][task].cputime if task in tasks1 else 0 | 297 | t1 = bs1[pkg]['tasks'][task].cputime if task in tasks1 else 0 |
300 | t2 = bs2[pkg]['tasks'][task].cputime if task in tasks2 else 0 | 298 | t2 = bs2[pkg]['tasks'][task].cputime if task in tasks2 else 0 |
301 | task_op = ' ' | 299 | task_op = ' ' |
@@ -307,18 +305,15 @@ def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)): | |||
307 | if t2 == 0: | 305 | if t2 == 0: |
308 | task_op = '- ' | 306 | task_op = '- ' |
309 | 307 | ||
308 | cputime = max(t1, t2) | ||
309 | if cputime < min_val: | ||
310 | log.debug("Filtering out %s:%s (%0.1fs)", pkg, task, cputime) | ||
311 | continue | ||
312 | if abs(t2-t1) < min_absdiff: | ||
313 | log.debug("Filtering out %s:%s (difference of %0.1fs)", pkg, task, t2-t1) | ||
314 | continue | ||
310 | tasks_diff.append(TaskDiff(pkg, pkg_op, task, task_op, t1, t2, t2-t1, reldiff)) | 315 | tasks_diff.append(TaskDiff(pkg, pkg_op, task, task_op, t1, t2, t2-t1, reldiff)) |
311 | 316 | ||
312 | if min_val: | ||
313 | print("Ignoring tasks shorter than {}s".format(min_val)) | ||
314 | if min_absdiff: | ||
315 | print("Ignoring time differences shorter than {}s".format(min_absdiff)) | ||
316 | |||
317 | print() | ||
318 | print(" {:{pkg_maxlen}} {:{task_maxlen}} {:>8} {:>10} {:>10} {}".format( | ||
319 | 'PKG', 'TASK', 'ABSDIFF', 'RELDIFF', 'CPUTIME1', 'CPUTIME2', | ||
320 | pkg_maxlen=pkg_maxlen, task_maxlen=task_maxlen)) | ||
321 | |||
322 | # Sort our list | 317 | # Sort our list |
323 | for field in reversed(sort_by): | 318 | for field in reversed(sort_by): |
324 | if field.startswith('-'): | 319 | if field.startswith('-'): |
@@ -328,18 +323,27 @@ def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)): | |||
328 | reverse = False | 323 | reverse = False |
329 | tasks_diff = sorted(tasks_diff, key=attrgetter(field), reverse=reverse) | 324 | tasks_diff = sorted(tasks_diff, key=attrgetter(field), reverse=reverse) |
330 | 325 | ||
326 | linedata = [(' ', 'PKG', ' ', 'TASK', 'ABSDIFF', 'RELDIFF', 'CPUTIME1', 'CPUTIME2')] | ||
327 | field_lens = dict([('len_{}'.format(i), len(f)) for i, f in enumerate(linedata[0])]) | ||
328 | |||
329 | # Prepare fields in string format and measure field lengths | ||
331 | for diff in tasks_diff: | 330 | for diff in tasks_diff: |
332 | cputime = max(diff.cputime1, diff.cputime2) | 331 | task_prefix = diff.task_op if diff.pkg_op == ' ' else ' ' |
333 | if cputime > min_val: | 332 | linedata.append((diff.pkg_op, diff.pkg, task_prefix, diff.task, |
334 | if abs(diff.absdiff) > min_absdiff: | 333 | '{:+.1f}'.format(diff.absdiff), |
335 | task_prefix = diff.task_op if diff.pkg_op == ' ' else ' ' | 334 | '{:+.1f}%'.format(diff.reldiff), |
336 | print("{}{:{pkg_maxlen}} {}{:{task_maxlen}} {:+7.1f}s {:+9.1f}% {:9.1f}s -> {:.1f}s".format( | 335 | '{:.1f}s'.format(diff.cputime1), |
337 | diff.pkg_op, diff.pkg, task_prefix, diff.task, diff.absdiff, diff.reldiff, diff.cputime1, diff.cputime2, | 336 | '{:.1f}s'.format(diff.cputime2))) |
338 | pkg_maxlen=pkg_maxlen, task_maxlen=task_maxlen)) | 337 | for i, field in enumerate(linedata[-1]): |
339 | else: | 338 | key = 'len_{}'.format(i) |
340 | log.debug("Filtering out %s (difference of %0.1fs)", task, diff.absdiff) | 339 | if len(field) > field_lens[key]: |
341 | else: | 340 | field_lens[key] = len(field) |
342 | log.debug("Filtering out %s (%0.1fs)", task, cputime) | 341 | |
342 | # Print data | ||
343 | print() | ||
344 | for fields in linedata: | ||
345 | print("{:{len_0}}{:{len_1}} {:{len_2}}{:{len_3}} {:>{len_4}} {:>{len_5}} {:>{len_6}} -> {:{len_7}}".format( | ||
346 | *fields, **field_lens)) | ||
343 | 347 | ||
344 | 348 | ||
345 | def print_timediff_summary(bs1, bs2): | 349 | def print_timediff_summary(bs1, bs2): |