Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] Filter feature for graph-tool
@ 2020-06-15  4:48 Paul Eggleton
  2020-06-15  4:48 ` [PATCH 1/2] graph-tool: switch to argparse Paul Eggleton
  2020-06-15  4:48 ` [PATCH 2/2] graph-tool: add filter subcommand Paul Eggleton
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Eggleton @ 2020-06-15  4:48 UTC (permalink / raw)
  To: openembedded-core

Add a subcommand to scripts/contrib/graph-tool to filter down .dot
task graphs produced by bitbake -g to something manageable when you
know what you're looking for.


The following changes since commit 49d0f822618890b61d2498b07dda6418f885321e:

  Revert "bitbake.conf: Remove unused DEPLOY_DIR_TOOLS variable" (2020-06-12 08:25:00 +0100)

are available in the git repository at:

  git://git.openembedded.org/openembedded-core-contrib paule/graph-tool
  http://cgit.openembedded.org/openembedded-core-contrib/log/?h=paule/graph-tool

Paul Eggleton (2):
  graph-tool: switch to argparse
  graph-tool: add filter subcommand

 scripts/contrib/graph-tool | 100 +++++++++++++++++++++++++++++++--------------
 1 file changed, 69 insertions(+), 31 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] graph-tool: switch to argparse
  2020-06-15  4:48 [PATCH 0/2] Filter feature for graph-tool Paul Eggleton
@ 2020-06-15  4:48 ` Paul Eggleton
  2020-06-15  4:48 ` [PATCH 2/2] graph-tool: add filter subcommand Paul Eggleton
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Eggleton @ 2020-06-15  4:48 UTC (permalink / raw)
  To: openembedded-core

argparse makes this a lot easier to extend.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.microsoft.com>
---
 scripts/contrib/graph-tool | 59 +++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/scripts/contrib/graph-tool b/scripts/contrib/graph-tool
index 6d2e68b..9402e61 100755
--- a/scripts/contrib/graph-tool
+++ b/scripts/contrib/graph-tool
@@ -11,6 +11,13 @@
 #
 
 import sys
+import os
+import argparse
+
+scripts_lib_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'lib'))
+sys.path.insert(0, scripts_lib_path)
+import argparse_oe
+
 
 def get_path_networkx(dotfile, fromnode, tonode):
     try:
@@ -34,47 +41,35 @@ def get_path_networkx(dotfile, fromnode, tonode):
     return networkx.all_simple_paths(graph, source=fromnode, target=tonode)
 
 
-def find_paths(args, usage):
-    if len(args) < 3:
-        usage()
-        sys.exit(1)
-
-    fromnode = args[1]
-    tonode = args[2]
-
+def find_paths(args):
     path = None
-    for path in get_path_networkx(args[0], fromnode, tonode):
+    for path in get_path_networkx(args.dotfile, args.fromnode, args.tonode):
         print(" -> ".join(map(str, path)))
     if not path:
-        print("ERROR: no path from %s to %s in graph" % (fromnode, tonode))
-        sys.exit(1)
+        print("ERROR: no path from %s to %s in graph" % (args.fromnode, args.tonode))
+        return 1
+
 
 def main():
-    import optparse
-    parser = optparse.OptionParser(
-        usage = '''%prog [options] <command> <arguments>
+    parser = argparse_oe.ArgumentParser(description='Small utility for working with .dot graph files')
 
-Available commands:
-    find-paths <dotfile> <from> <to>
-        Find all of the paths between two nodes in a dot graph''')
+    subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
+    subparsers.required = True
 
-    #parser.add_option("-d", "--debug",
-    #        help = "Report all SRCREV values, not just ones where AUTOREV has been used",
-    #        action="store_true", dest="debug", default=False)
+    parser_find_paths = subparsers.add_parser('find-paths',
+                                              help='Find all of the paths between two nodes in a dot graph',
+                                              description='Finds all of the paths between two nodes in a dot graph')
+    parser_find_paths.add_argument('dotfile', help='.dot graph to search in')
+    parser_find_paths.add_argument('fromnode', help='starting node name')
+    parser_find_paths.add_argument('tonode', help='ending node name')
+    parser_find_paths.set_defaults(func=find_paths)
 
-    options, args = parser.parse_args(sys.argv)
-    args = args[1:]
+    args = parser.parse_args()
 
-    if len(args) < 1:
-        parser.print_help()
-        sys.exit(1)
-
-    if args[0] == "find-paths":
-        find_paths(args[1:], parser.print_help)
-    else:
-        parser.print_help()
-        sys.exit(1)
+    ret = args.func(args)
+    return ret
 
 
 if __name__ == "__main__":
-    main()
+    ret = main()
+    sys.exit(ret)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] graph-tool: add filter subcommand
  2020-06-15  4:48 [PATCH 0/2] Filter feature for graph-tool Paul Eggleton
  2020-06-15  4:48 ` [PATCH 1/2] graph-tool: switch to argparse Paul Eggleton
@ 2020-06-15  4:48 ` Paul Eggleton
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Eggleton @ 2020-06-15  4:48 UTC (permalink / raw)
  To: openembedded-core

Add a filter subcommand to filter a task-depends.dot graph produced by
bitbake -g down to just a subset of targets/tasks.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.microsoft.com>
---
 scripts/contrib/graph-tool | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/scripts/contrib/graph-tool b/scripts/contrib/graph-tool
index 9402e61..2648893 100755
--- a/scripts/contrib/graph-tool
+++ b/scripts/contrib/graph-tool
@@ -50,6 +50,40 @@ def find_paths(args):
         return 1
 
 
+def filter_graph(args):
+    import fnmatch
+
+    exclude_tasks = []
+    if args.exclude_tasks:
+        for task in args.exclude_tasks.split(','):
+            if not task.startswith('do_'):
+                task = 'do_%s' % task
+            exclude_tasks.append(task)
+
+    def checkref(strval):
+        strval = strval.strip().strip('"')
+        target, taskname = strval.rsplit('.', 1)
+        if exclude_tasks:
+            for extask in exclude_tasks:
+                if fnmatch.fnmatch(taskname, extask):
+                    return False
+        if strval in args.ref or target in args.ref:
+            return True
+        return False
+
+    with open(args.infile, 'r') as f:
+        for line in f:
+            line = line.rstrip()
+            if line.startswith(('digraph', '}')):
+                print(line)
+            elif '->' in line:
+                linesplit = line.split('->')
+                if checkref(linesplit[0]) and checkref(linesplit[1]):
+                    print(line)
+            elif (not args.no_nodes) and checkref(line.split()[0]):
+                print(line)
+
+
 def main():
     parser = argparse_oe.ArgumentParser(description='Small utility for working with .dot graph files')
 
@@ -64,6 +98,15 @@ def main():
     parser_find_paths.add_argument('tonode', help='ending node name')
     parser_find_paths.set_defaults(func=find_paths)
 
+    parser_filter = subparsers.add_parser('filter',
+                                           help='Pare down a task graph to contain only the specified references',
+                                           description='Pares down a task-depends.dot graph produced by bitbake -g to contain only the specified references')
+    parser_filter.add_argument('infile', help='Input file')
+    parser_filter.add_argument('ref', nargs='+', help='Reference to include (either recipe/target name or full target.taskname specification)')
+    parser_filter.add_argument('-n', '--no-nodes', action='store_true', help='Skip node formatting lines')
+    parser_filter.add_argument('-x', '--exclude-tasks', help='Comma-separated list of tasks to exclude (do_ prefix optional, wildcards allowed)')
+    parser_filter.set_defaults(func=filter_graph)
+
     args = parser.parse_args()
 
     ret = args.func(args)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-15  4:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-15  4:48 [PATCH 0/2] Filter feature for graph-tool Paul Eggleton
2020-06-15  4:48 ` [PATCH 1/2] graph-tool: switch to argparse Paul Eggleton
2020-06-15  4:48 ` [PATCH 2/2] graph-tool: add filter subcommand Paul Eggleton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox