summaryrefslogtreecommitdiffstats
path: root/scripts/buildstats-diff
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/buildstats-diff')
-rwxr-xr-xscripts/buildstats-diff46
1 files changed, 36 insertions, 10 deletions
diff --git a/scripts/buildstats-diff b/scripts/buildstats-diff
index 05bf74c64d..3c894cbbe1 100755
--- a/scripts/buildstats-diff
+++ b/scripts/buildstats-diff
@@ -17,6 +17,7 @@ import argparse
17import glob 17import glob
18import json 18import json
19import logging 19import logging
20import math
20import os 21import os
21import re 22import re
22import sys 23import sys
@@ -77,6 +78,15 @@ class BSTask(dict):
77 return self['rusage']['ru_stime'] + self['rusage']['ru_utime'] + \ 78 return self['rusage']['ru_stime'] + self['rusage']['ru_utime'] + \
78 self['child_rusage']['ru_stime'] + self['child_rusage']['ru_utime'] 79 self['child_rusage']['ru_stime'] + self['child_rusage']['ru_utime']
79 80
81 @property
82 def read_bytes(self):
83 """Bytes read from the block layer"""
84 return self['iostat']['read_bytes']
85
86 @property
87 def write_bytes(self):
88 """Bytes written to the block layer"""
89 return self['iostat']['write_bytes']
80 90
81def read_buildstats_file(buildstat_file): 91def read_buildstats_file(buildstat_file):
82 """Convert buildstat text file into dict/json""" 92 """Convert buildstat text file into dict/json"""
@@ -290,8 +300,13 @@ def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absd
290 return hms_time(val) 300 return hms_time(val)
291 else: 301 else:
292 return "{:.1f}s".format(val) 302 return "{:.1f}s".format(val)
293 else: 303 elif 'bytes' in val_type and human_readable:
294 return str(val) 304 prefix = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi']
305 dec = int(math.log(val, 2) / 10)
306 prec = 1 if dec > 0 else 0
307 return "{:.{prec}f}{}B".format(val / (2 ** (10 * dec)),
308 prefix[dec], prec=prec)
309 return str(int(val))
295 310
296 def sum_vals(buildstats): 311 def sum_vals(buildstats):
297 """Get cumulative sum of all tasks""" 312 """Get cumulative sum of all tasks"""
@@ -323,16 +338,22 @@ def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absd
323 pkg_op = ' ' 338 pkg_op = ' '
324 339
325 for task in set(tasks1.keys()).union(set(tasks2.keys())): 340 for task in set(tasks1.keys()).union(set(tasks2.keys())):
326 val1 = getattr(bs1[pkg]['tasks'][task], val_type) if task in tasks1 else 0
327 val2 = getattr(bs2[pkg]['tasks'][task], val_type) if task in tasks2 else 0
328 task_op = ' ' 341 task_op = ' '
342 if task in tasks1:
343 val1 = getattr(bs1[pkg]['tasks'][task], val_type)
344 else:
345 task_op = '+ '
346 val1 = 0
347 if task in tasks2:
348 val2 = getattr(bs2[pkg]['tasks'][task], val_type)
349 else:
350 val2 = 0
351 task_op = '- '
352
329 if val1 == 0: 353 if val1 == 0:
330 reldiff = float('inf') 354 reldiff = float('inf')
331 task_op = '+ '
332 else: 355 else:
333 reldiff = 100 * (val2 - val1) / val1 356 reldiff = 100 * (val2 - val1) / val1
334 if val2 == 0:
335 task_op = '- '
336 357
337 if max(val1, val2) < min_val: 358 if max(val1, val2) < min_val:
338 log.debug("Filtering out %s:%s (%s)", pkg, task, 359 log.debug("Filtering out %s:%s (%s)", pkg, task,
@@ -395,14 +416,19 @@ Script for comparing buildstats of two separate builds."""
395 formatter_class=argparse.ArgumentDefaultsHelpFormatter, 416 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
396 description=description) 417 description=description)
397 418
398 min_val_defaults = {'cputime': 3.0} 419 min_val_defaults = {'cputime': 3.0,
399 min_absdiff_defaults = {'cputime': 1.0} 420 'read_bytes': 524288,
421 'write_bytes': 524288}
422 min_absdiff_defaults = {'cputime': 1.0,
423 'read_bytes': 131072,
424 'write_bytes': 131072}
400 425
401 parser.add_argument('--debug', '-d', action='store_true', 426 parser.add_argument('--debug', '-d', action='store_true',
402 help="Verbose logging") 427 help="Verbose logging")
403 parser.add_argument('--ver-diff', action='store_true', 428 parser.add_argument('--ver-diff', action='store_true',
404 help="Show package version differences and exit") 429 help="Show package version differences and exit")
405 parser.add_argument('--diff-attr', default='cputime', choices=('cputime',), 430 parser.add_argument('--diff-attr', default='cputime',
431 choices=('cputime', 'read_bytes', 'write_bytes'),
406 help="Buildstat attribute which to compare") 432 help="Buildstat attribute which to compare")
407 parser.add_argument('--min-val', default=min_val_defaults, type=float, 433 parser.add_argument('--min-val', default=min_val_defaults, type=float,
408 help="Filter out tasks less than MIN_VAL. " 434 help="Filter out tasks less than MIN_VAL. "