diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2017-09-15 16:04:39 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-09-18 11:07:30 +0100 |
commit | a80f5e761cf1c0ac1b5d457ec5284f601c60f459 (patch) | |
tree | b85f3b9abc60fe78008da1ae94b39fb785ae7364 | |
parent | 81aef784fdbd2e8a543475b1892c3d6a1fe97872 (diff) | |
download | poky-a80f5e761cf1c0ac1b5d457ec5284f601c60f459.tar.gz |
scripts/buildstats-diff: move more code to lib/buildstats.py
More refactoring of buildstats-diff script. Move recipe version
comparison functionality to scripts/lib/buildstats.py. This patch also
compasses some wording changes, i.e. changing 'package' to 'recipe'.
[YOCTO #11382]
(From OE-Core rev: 2f8942d6830258fcbe1925f12ba1516def32d132)
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>
-rwxr-xr-x | scripts/buildstats-diff | 86 | ||||
-rw-r--r-- | scripts/lib/buildstats.py | 31 |
2 files changed, 61 insertions, 56 deletions
diff --git a/scripts/buildstats-diff b/scripts/buildstats-diff index ce82dabee9..a128dd324f 100755 --- a/scripts/buildstats-diff +++ b/scripts/buildstats-diff | |||
@@ -24,7 +24,7 @@ from operator import attrgetter | |||
24 | # Import oe libs | 24 | # Import oe libs |
25 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | 25 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
26 | sys.path.append(os.path.join(scripts_path, 'lib')) | 26 | sys.path.append(os.path.join(scripts_path, 'lib')) |
27 | from buildstats import BuildStats, diff_buildstats, taskdiff_fields | 27 | from buildstats import BuildStats, diff_buildstats, taskdiff_fields, BSVerDiff |
28 | 28 | ||
29 | 29 | ||
30 | # Setup logging | 30 | # Setup logging |
@@ -76,72 +76,48 @@ def read_buildstats(path, multi): | |||
76 | 76 | ||
77 | def print_ver_diff(bs1, bs2): | 77 | def print_ver_diff(bs1, bs2): |
78 | """Print package version differences""" | 78 | """Print package version differences""" |
79 | pkgs1 = set(bs1.keys()) | ||
80 | pkgs2 = set(bs2.keys()) | ||
81 | new_pkgs = pkgs2 - pkgs1 | ||
82 | deleted_pkgs = pkgs1 - pkgs2 | ||
83 | |||
84 | echanged = [] | ||
85 | vchanged = [] | ||
86 | rchanged = [] | ||
87 | unchanged = [] | ||
88 | common_pkgs = pkgs2.intersection(pkgs1) | ||
89 | if common_pkgs: | ||
90 | for pkg in common_pkgs: | ||
91 | if bs1[pkg].epoch != bs2[pkg].epoch: | ||
92 | echanged.append(pkg) | ||
93 | elif bs1[pkg].version != bs2[pkg].version: | ||
94 | vchanged.append(pkg) | ||
95 | elif bs1[pkg].revision != bs2[pkg].revision: | ||
96 | rchanged.append(pkg) | ||
97 | else: | ||
98 | unchanged.append(pkg) | ||
99 | 79 | ||
100 | maxlen = max([len(pkg) for pkg in pkgs1.union(pkgs2)]) | 80 | diff = BSVerDiff(bs1, bs2) |
81 | |||
82 | maxlen = max([len(r) for r in set(bs1.keys()).union(set(bs2.keys()))]) | ||
101 | fmt_str = " {:{maxlen}} ({})" | 83 | fmt_str = " {:{maxlen}} ({})" |
102 | # if unchanged: | 84 | |
103 | # print("\nUNCHANGED PACKAGES:") | 85 | if diff.new: |
104 | # print("-------------------") | 86 | print("\nNEW RECIPES:") |
105 | # maxlen = max([len(pkg) for pkg in unchanged]) | 87 | print("------------") |
106 | # for pkg in sorted(unchanged): | 88 | for name, val in sorted(diff.new.items()): |
107 | # print(fmt_str.format(pkg, bs2[pkg]['nevr'], maxlen=maxlen)) | 89 | print(fmt_str.format(name, val.nevr, maxlen=maxlen)) |
108 | 90 | ||
109 | if new_pkgs: | 91 | if diff.dropped: |
110 | print("\nNEW PACKAGES:") | 92 | print("\nDROPPED RECIPES:") |
111 | print("-------------") | 93 | print("----------------") |
112 | for pkg in sorted(new_pkgs): | 94 | for name, val in sorted(diff.dropped.items()): |
113 | print(fmt_str.format(pkg, bs2[pkg].nevr, maxlen=maxlen)) | 95 | print(fmt_str.format(name, val.nevr, maxlen=maxlen)) |
114 | |||
115 | if deleted_pkgs: | ||
116 | print("\nDELETED PACKAGES:") | ||
117 | print("-----------------") | ||
118 | for pkg in sorted(deleted_pkgs): | ||
119 | print(fmt_str.format(pkg, bs1[pkg].nevr, maxlen=maxlen)) | ||
120 | 96 | ||
121 | fmt_str = " {0:{maxlen}} {1:<20} ({2})" | 97 | fmt_str = " {0:{maxlen}} {1:<20} ({2})" |
122 | if rchanged: | 98 | if diff.rchanged: |
123 | print("\nREVISION CHANGED:") | 99 | print("\nREVISION CHANGED:") |
124 | print("-----------------") | 100 | print("-----------------") |
125 | for pkg in sorted(rchanged): | 101 | for name, val in sorted(diff.rchanged.items()): |
126 | field1 = "{} -> {}".format(pkg, bs1[pkg].revision, bs2[pkg].revision) | 102 | field1 = "{} -> {}".format(val.left.revision, val.right.revision) |
127 | field2 = "{} -> {}".format(bs1[pkg].nevr, bs2[pkg].nevr) | 103 | field2 = "{} -> {}".format(val.left.nevr, val.right.nevr) |
128 | print(fmt_str.format(pkg, field1, field2, maxlen=maxlen)) | 104 | print(fmt_str.format(name, field1, field2, maxlen=maxlen)) |
129 | 105 | ||
130 | if vchanged: | 106 | if diff.vchanged: |
131 | print("\nVERSION CHANGED:") | 107 | print("\nVERSION CHANGED:") |
132 | print("----------------") | 108 | print("----------------") |
133 | for pkg in sorted(vchanged): | 109 | for name, val in sorted(diff.vchanged.items()): |
134 | field1 = "{} -> {}".format(bs1[pkg].version, bs2[pkg].version) | 110 | field1 = "{} -> {}".format(val.left.version, val.right.version) |
135 | field2 = "{} -> {}".format(bs1[pkg].nevr, bs2[pkg].nevr) | 111 | field2 = "{} -> {}".format(val.left.nevr, val.right.nevr) |
136 | print(fmt_str.format(pkg, field1, field2, maxlen=maxlen)) | 112 | print(fmt_str.format(name, field1, field2, maxlen=maxlen)) |
137 | 113 | ||
138 | if echanged: | 114 | if diff.echanged: |
139 | print("\nEPOCH CHANGED:") | 115 | print("\nEPOCH CHANGED:") |
140 | print("--------------") | 116 | print("--------------") |
141 | for pkg in sorted(echanged): | 117 | for name, val in sorted(diff.echanged.items()): |
142 | field1 = "{} -> {}".format(bs1[pkg].epoch, bs2[pkg].epoch) | 118 | field1 = "{} -> {}".format(val.left.epoch, val.right.epoch) |
143 | field2 = "{} -> {}".format(bs1[pkg].nevr, bs2[pkg].nevr) | 119 | field2 = "{} -> {}".format(val.left.nevr, val.right.nevr) |
144 | print(fmt_str.format(pkg, field1, field2, maxlen=maxlen)) | 120 | print(fmt_str.format(name, field1, field2, maxlen=maxlen)) |
145 | 121 | ||
146 | 122 | ||
147 | def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absdiff',)): | 123 | def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absdiff',)): |
diff --git a/scripts/lib/buildstats.py b/scripts/lib/buildstats.py index bd6332176a..b1c9e617c6 100644 --- a/scripts/lib/buildstats.py +++ b/scripts/lib/buildstats.py | |||
@@ -15,7 +15,7 @@ import json | |||
15 | import logging | 15 | import logging |
16 | import os | 16 | import os |
17 | import re | 17 | import re |
18 | from collections import namedtuple | 18 | from collections import namedtuple,OrderedDict |
19 | from statistics import mean | 19 | from statistics import mean |
20 | 20 | ||
21 | 21 | ||
@@ -307,3 +307,32 @@ def diff_buildstats(bs1, bs2, stat_attr, min_val=None, min_absdiff=None): | |||
307 | tasks_diff.append(TaskDiff(pkg, pkg_op, task, task_op, val1, val2, | 307 | tasks_diff.append(TaskDiff(pkg, pkg_op, task, task_op, val1, val2, |
308 | val2-val1, reldiff)) | 308 | val2-val1, reldiff)) |
309 | return tasks_diff | 309 | return tasks_diff |
310 | |||
311 | |||
312 | class BSVerDiff(object): | ||
313 | """Class representing recipe version differences between two buildstats""" | ||
314 | def __init__(self, bs1, bs2): | ||
315 | RecipeVerDiff = namedtuple('RecipeVerDiff', 'left right') | ||
316 | |||
317 | recipes1 = set(bs1.keys()) | ||
318 | recipes2 = set(bs2.keys()) | ||
319 | |||
320 | self.new = dict([(r, bs2[r]) for r in sorted(recipes2 - recipes1)]) | ||
321 | self.dropped = dict([(r, bs1[r]) for r in sorted(recipes1 - recipes2)]) | ||
322 | self.echanged = {} | ||
323 | self.vchanged = {} | ||
324 | self.rchanged = {} | ||
325 | self.unchanged = {} | ||
326 | |||
327 | common = recipes2.intersection(recipes1) | ||
328 | if common: | ||
329 | for recipe in common: | ||
330 | rdiff = RecipeVerDiff(bs1[recipe], bs2[recipe]) | ||
331 | if bs1[recipe].epoch != bs2[recipe].epoch: | ||
332 | self.echanged[recipe] = rdiff | ||
333 | elif bs1[recipe].version != bs2[recipe].version: | ||
334 | self.vchanged[recipe] = rdiff | ||
335 | elif bs1[recipe].revision != bs2[recipe].revision: | ||
336 | self.rchanged[recipe] = rdiff | ||
337 | else: | ||
338 | self.unchanged[recipe] = rdiff | ||