[OE-core] [PATCH] scripts/buildstats-diff: Add option to filter tasks

Joshua Watt jpewhacker at gmail.com
Mon Jul 15 15:47:33 UTC 2019


Adds a command line option to filter out the buildstats-diff report by
one more more tasks. e.g.:

 buildstats-diff --only-task do_compile A B

will only show the differences for do_compile tasks. The --only-task
option can be specified multiple times to filter out multiple tasks at
once.

Signed-off-by: Joshua Watt <JPEWhacker at gmail.com>
---
 scripts/buildstats-diff   | 14 ++++++++------
 scripts/lib/buildstats.py |  6 +++++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/scripts/buildstats-diff b/scripts/buildstats-diff
index c179c93528..2f6498ab67 100755
--- a/scripts/buildstats-diff
+++ b/scripts/buildstats-diff
@@ -114,7 +114,7 @@ def print_ver_diff(bs1, bs2):
             print(fmt_str.format(name, field1, field2, maxlen=maxlen))
 
 
-def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absdiff',)):
+def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absdiff',), only_tasks=[]):
     """Diff task execution times"""
     def val_to_str(val, human_readable=False):
         """Convert raw value to printable string"""
@@ -151,8 +151,9 @@ def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absd
         """Get cumulative sum of all tasks"""
         total = 0.0
         for recipe_data in buildstats.values():
-            for bs_task in recipe_data.tasks.values():
-                total += getattr(bs_task, val_type)
+            for name, bs_task in recipe_data.tasks.items():
+                if not only_tasks or name in only_tasks:
+                    total += getattr(bs_task, val_type)
         return total
 
     if min_val:
@@ -163,7 +164,7 @@ def print_task_diff(bs1, bs2, val_type, min_val=0, min_absdiff=0, sort_by=('absd
                 val_to_str(min_absdiff, True), val_to_str(min_absdiff)))
 
     # Prepare the data
-    tasks_diff = diff_buildstats(bs1, bs2, val_type, min_val, min_absdiff)
+    tasks_diff = diff_buildstats(bs1, bs2, val_type, min_val, min_absdiff, only_tasks)
 
     # Sort our list
     for field in reversed(sort_by):
@@ -248,6 +249,8 @@ Script for comparing buildstats of two separate builds."""
     parser.add_argument('--multi', action='store_true',
                         help="Read all buildstats from the given paths and "
                              "average over them")
+    parser.add_argument('--only-task', dest='only_tasks', metavar='TASK', action='append', default=[],
+                        help="Only include TASK in report. May be specified multiple times")
     parser.add_argument('buildstats1', metavar='BUILDSTATS1', help="'Left' buildstat")
     parser.add_argument('buildstats2', metavar='BUILDSTATS2', help="'Right' buildstat")
 
@@ -266,7 +269,6 @@ Script for comparing buildstats of two separate builds."""
 
     return args
 
-
 def main(argv=None):
     """Script entry point"""
     args = parse_args(argv)
@@ -290,7 +292,7 @@ def main(argv=None):
             print_ver_diff(bs1, bs2)
         else:
             print_task_diff(bs1, bs2, args.diff_attr, args.min_val,
-                            args.min_absdiff, sort_by)
+                            args.min_absdiff, sort_by, args.only_tasks)
     except ScriptError as err:
         log.error(str(err))
         return 1
diff --git a/scripts/lib/buildstats.py b/scripts/lib/buildstats.py
index 1adab06edf..c69b5bf4d7 100644
--- a/scripts/lib/buildstats.py
+++ b/scripts/lib/buildstats.py
@@ -261,13 +261,17 @@ class BuildStats(dict):
             self[pkg].aggregate(data)
 
 
-def diff_buildstats(bs1, bs2, stat_attr, min_val=None, min_absdiff=None):
+def diff_buildstats(bs1, bs2, stat_attr, min_val=None, min_absdiff=None, only_tasks=[]):
     """Compare the tasks of two buildstats"""
     tasks_diff = []
     pkgs = set(bs1.keys()).union(set(bs2.keys()))
     for pkg in pkgs:
         tasks1 = bs1[pkg].tasks if pkg in bs1 else {}
         tasks2 = bs2[pkg].tasks if pkg in bs2 else {}
+        if only_tasks:
+            tasks1 = {k: v for k, v in tasks1.items() if k in only_tasks}
+            tasks2 = {k: v for k, v in tasks2.items() if k in only_tasks}
+
         if not tasks1:
             pkg_op = '+'
         elif not tasks2:
-- 
2.21.0



More information about the Openembedded-core mailing list