summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2016-09-29 17:28:00 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-10-01 21:45:55 +0100
commit7113ac943920e61b9a8427410c8362cf9d33d19c (patch)
treec379126295423bcfe13b8f7faaa4e8ac16211f2a /scripts
parent4cc1c430cd8540598f8e3f2056637b50f3608f8a (diff)
downloadpoky-7113ac943920e61b9a8427410c8362cf9d33d19c.tar.gz
scripts/buildstats-diff: implement BSTask class
New class representing buildstats data of a single task. (From OE-Core rev: 472818a32f96699a6dc9c7c487f38d716678fd7a) 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')
-rwxr-xr-xscripts/buildstats-diff51
1 files changed, 32 insertions, 19 deletions
diff --git a/scripts/buildstats-diff b/scripts/buildstats-diff
index 7728b6d38d..22c44ff2bb 100755
--- a/scripts/buildstats-diff
+++ b/scripts/buildstats-diff
@@ -62,11 +62,26 @@ def to_datetime_obj(obj):
62 return datetime.utcfromtimestamp(obj).replace(tzinfo=TIMEZONES['UTC']) 62 return datetime.utcfromtimestamp(obj).replace(tzinfo=TIMEZONES['UTC'])
63 63
64 64
65class BSTask(dict):
66 def __init__(self, *args, **kwargs):
67 self['start_time'] = None
68 self['elapsed_time'] = None
69 self['status'] = None
70 self['iostat'] = {}
71 self['rusage'] = {}
72 self['child_rusage'] = {}
73 super(BSTask, self).__init__(*args, **kwargs)
74
75 @property
76 def cputime(self):
77 """Sum of user and system time taken by the task"""
78 return self['rusage']['ru_stime'] + self['rusage']['ru_utime'] + \
79 self['child_rusage']['ru_stime'] + self['child_rusage']['ru_utime']
80
81
65def read_buildstats_file(buildstat_file): 82def read_buildstats_file(buildstat_file):
66 """Convert buildstat text file into dict/json""" 83 """Convert buildstat text file into dict/json"""
67 bs_json = {'iostat': {}, 84 bs_task = BSTask()
68 'rusage': {},
69 'child_rusage': {}}
70 log.debug("Reading task buildstats from %s", buildstat_file) 85 log.debug("Reading task buildstats from %s", buildstat_file)
71 with open(buildstat_file) as fobj: 86 with open(buildstat_file) as fobj:
72 for line in fobj.readlines(): 87 for line in fobj.readlines():
@@ -74,12 +89,12 @@ def read_buildstats_file(buildstat_file):
74 val = val.strip() 89 val = val.strip()
75 if key == 'Started': 90 if key == 'Started':
76 start_time = to_datetime_obj(float(val)) 91 start_time = to_datetime_obj(float(val))
77 bs_json['start_time'] = start_time 92 bs_task['start_time'] = start_time
78 elif key == 'Ended': 93 elif key == 'Ended':
79 end_time = to_datetime_obj(float(val)) 94 end_time = to_datetime_obj(float(val))
80 elif key.startswith('IO '): 95 elif key.startswith('IO '):
81 split = key.split() 96 split = key.split()
82 bs_json['iostat'][split[1]] = int(val) 97 bs_task['iostat'][split[1]] = int(val)
83 elif key.find('rusage') >= 0: 98 elif key.find('rusage') >= 0:
84 split = key.split() 99 split = key.split()
85 ru_key = split[-1] 100 ru_key = split[-1]
@@ -89,11 +104,11 @@ def read_buildstats_file(buildstat_file):
89 val = int(val) 104 val = int(val)
90 ru_type = 'rusage' if split[0] == 'rusage' else \ 105 ru_type = 'rusage' if split[0] == 'rusage' else \
91 'child_rusage' 106 'child_rusage'
92 bs_json[ru_type][ru_key] = val 107 bs_task[ru_type][ru_key] = val
93 elif key == 'Status': 108 elif key == 'Status':
94 bs_json['status'] = val 109 bs_task['status'] = val
95 bs_json['elapsed_time'] = end_time - start_time 110 bs_task['elapsed_time'] = end_time - start_time
96 return bs_json 111 return bs_task
97 112
98 113
99def read_buildstats_dir(bs_dir): 114def read_buildstats_dir(bs_dir):
@@ -170,6 +185,10 @@ def read_buildstats_json(path):
170 recipe_bs['nevr'] = "{}-{}-{}".format(recipe_bs['name'], recipe_bs['version'], recipe_bs['revision']) 185 recipe_bs['nevr'] = "{}-{}-{}".format(recipe_bs['name'], recipe_bs['version'], recipe_bs['revision'])
171 else: 186 else:
172 recipe_bs['nevr'] = "{}-{}_{}-{}".format(recipe_bs['name'], recipe_bs['epoch'], recipe_bs['version'], recipe_bs['revision']) 187 recipe_bs['nevr'] = "{}-{}_{}-{}".format(recipe_bs['name'], recipe_bs['epoch'], recipe_bs['version'], recipe_bs['revision'])
188
189 for task, data in recipe_bs['tasks'].copy().items():
190 recipe_bs['tasks'][task] = BSTask(data)
191
173 buildstats[recipe_bs['name']] = recipe_bs 192 buildstats[recipe_bs['name']] = recipe_bs
174 193
175 return buildstats 194 return buildstats
@@ -253,12 +272,6 @@ def print_ver_diff(bs1, bs2):
253 print(fmt_str.format(pkg, field1, field2, maxlen=maxlen)) 272 print(fmt_str.format(pkg, field1, field2, maxlen=maxlen))
254 273
255 274
256def task_time(task):
257 """Calculate sum of user and system time taken by a task"""
258 cputime = task['rusage']['ru_stime'] + task['rusage']['ru_utime'] + \
259 task['child_rusage']['ru_stime'] + task['child_rusage']['ru_utime']
260 return cputime
261
262 275
263def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)): 276def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)):
264 """Diff task execution times""" 277 """Diff task execution times"""
@@ -283,8 +296,8 @@ def print_task_diff(bs1, bs2, min_val=0, min_absdiff=0, sort_by=('absdiff',)):
283 if len(task) > task_maxlen: 296 if len(task) > task_maxlen:
284 task_maxlen = len(task) 297 task_maxlen = len(task)
285 298
286 t1 = task_time(bs1[pkg]['tasks'][task]) if task in tasks1 else 0 299 t1 = bs1[pkg]['tasks'][task].cputime if task in tasks1 else 0
287 t2 = task_time(bs2[pkg]['tasks'][task]) if task in tasks2 else 0 300 t2 = bs2[pkg]['tasks'][task].cputime if task in tasks2 else 0
288 task_op = ' ' 301 task_op = ' '
289 if t1 == 0: 302 if t1 == 0:
290 reldiff = float('inf') 303 reldiff = float('inf')
@@ -334,8 +347,8 @@ def print_timediff_summary(bs1, bs2):
334 def total_cputime(buildstats): 347 def total_cputime(buildstats):
335 sum = 0.0 348 sum = 0.0
336 for recipe_data in buildstats.values(): 349 for recipe_data in buildstats.values():
337 for task_data in recipe_data['tasks'].values(): 350 for bs_task in recipe_data['tasks'].values():
338 sum += task_time(task_data) 351 sum += bs_task.cputime
339 return sum 352 return sum
340 353
341 def hms_time(secs): 354 def hms_time(secs):