support/graphs: speedup graph-depends (branch yem/graphs-from-make-2)
v3 cover support/graphs: speedup graph-depends (branch yem/graphs-from-make-2)
Hello All!
This two-patch series bring tremendous speedups to graph-depends (and to -rdepends as well) by using the newly-introduced show-dependency-tree.
The first patch is a cleanup in the PHONY rules.
The second patch is a preparatory fixup for the mandatory-deps removal.
The third patch is the actual speedup.
Changes v2 -> v3:
- fix the %-graph-rdepends (Thomas P.)
- simplify by using defaultdicts() (Thomas P.)
- return the deps and rdeps
Regards,
Yann E. MORIN.
The following changes since commit f4f7dd9557cf139f6014ada77e947152d5a82fb3
package/libssh2: security bump to latest git (2019-03-21 00:00:54 +0100)
are available in the git repository at:
git://git.buildroot.org/~ymorin/git/buildroot.git
for you to fetch changes up to e26ba891857584eb10bbfbe76ec45be8eb2551b8
support/graph-depends: use the new make-based dependency tree (2019-03-22 21:49:53 +0100)
----------------------------------------------------------------
Yann E. MORIN (3):
package/pkg-generic: mark some rule PHONY support/graph-depends: don't eliminate mandatory deps for reverse graphs support/graph-depends: use the new make-based dependency tree
package/pkg-generic.mk | 3 + support/scripts/brpkgutil.py | 97 ++++++++++++----------------- support/scripts/graph-depends | 138 +++++++++--------------------------------- 3 files changed, 70 insertions(+), 168 deletions(-)
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH v3 1/3 package/pkg-generic: mark some rule PHONY
The %-graph-rdepends should be marked PHONY, as the %-graph-depends is.
The %-show-dependency-tree should also be a PHONY rule, because it does not actually create a file. Furthermore, to avoid the "Nothing to be done for .." message, give that rule an actual recipe that just does nothing.
--- package/pkg-generic.mk | 3 +++ 1 file changed, 3 insertions(+)
package/pkg-generic.mk +3 -0
@@ -859,6 +859,7 @@ $(1)-show-build-order: $$(patsubst %,%-show-build-order,$$($(2)_FINAL_ALL_DEPEND $$(info $(1)) $(1)-show-dependency-tree: $$(patsubst %,%-show-dependency-tree,$$($(2)_FINAL_ALL_DEPENDENCIES)) + @: $$(info $(1): $(4) $$(if $$($(2)_IS_VIRTUAL),virtual,$$($(2)_DL_VERSION))) $$(info $(1) -> $$(foreach d,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(d)))
@@ -1079,6 +1080,7 @@ DL_TOOLS_DEPENDENCIES += $$(call extractor-dependency,$$($(2)_SOURCE)) $(1)-external-deps \ $(1)-extract \ $(1)-graph-depends \ + $(1)-graph-rdepends \ $(1)-install \ $(1)-install-host \ $(1)-install-images \
@@ -1091,6 +1093,7 @@ DL_TOOLS_DEPENDENCIES += $$(call extractor-dependency,$$($(2)_SOURCE)) $(1)-reconfigure \ $(1)-reinstall \ $(1)-rsync \ + $(1)-show-dependency-tree \ $(1)-show-depends \ $(1)-show-version \ $(1)-source
Signature · 1 line
2.14.1
Thomas Petazzoni
AppliedPATCH v3 1/3 package/pkg-generic: mark some rule PHONY
Quoted 7 lines · On Fri, 22 Mar 2019 22:07:05 +0100 "Yann E. MORIN" <[email protected]>…
The %-graph-rdepends should be marked PHONY, as the %-graph-depends is.
The %-show-dependency-tree should also be a PHONY rule, because it does not actually create a file. Furthermore, to avoid the "Nothing to be done for .." message, give that rule an actual recipe that just does nothing.
Quoted 5 lines
Signed-off-by "Yann E. MORIN" <[email protected]>Cc Thomas Petazzoni <[email protected]>--- package/pkg-generic.mk | 3 +++ 1 file changed, 3 insertions(+)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v3 2/3 support/graph-depends: don't eliminate mandatory deps for reverse graphs
In reply to Yann E. MORINWe we simplify the dependency graph, we try to remove so-called mandatory dependencies from each package, and for each mandatory that was thus removed, reattach it to the root-package of the graph.
This was made so that mandatory dependencies (which are dependencies of all packages, or at least of a lot of packages) do not clutter the dependency graph, but that they are still shown in the graph, as dependencies of the root package.
However, these mandatory dependencies are only _direct_ dependencies. As such, it does not make sense to reattach a mandatory dependency when doing a reverse graph. Worse, it can actually be incorrect.
For example, 'skeleton' is a mandatory dependency, and as such is removed from all packages. But when doing a reverse graph, skeleton is now in the dependency chain of, e.g. skeleton-init-none; it should then not be removed.
In short: the notion of mandatory dependencies does not make sense in the case of a reverse graph.
Consequently, skip over the mandatory dependency removal when doing a reverse graph.
--- support/scripts/graph-depends | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
support/scripts/graph-depends +12 -8
@@ -216,13 +216,17 @@ def check_circular_deps(deps): # This functions trims down the dependency list of all packages. # It applies in sequence all the dependency-elimination methods. -def remove_extra_deps(deps, rootpkg, transitive): - for pkg in list(deps.keys()): - if not pkg == rootpkg: - for d in get_mandatory_deps(pkg, deps): - if d not in deps[rootpkg]: - deps[rootpkg].append(d) - deps[pkg] = remove_mandatory_deps(pkg, deps) +def remove_extra_deps(deps, rootpkg, transitive, arrow_dir): + # For the direct dependencies, find and eliminate mandatory + # deps, and add them to the root package. Don't do it for a + # reverse graph, because mandatory deps are only direct deps. + if arrow_dir == "forward": + for pkg in list(deps.keys()): + if not pkg == rootpkg: + for d in get_mandatory_deps(pkg, deps): + if d not in deps[rootpkg]: + deps[rootpkg].append(d) + deps[pkg] = remove_mandatory_deps(pkg, deps) for pkg in list(deps.keys()): if not transitive or pkg == rootpkg: deps[pkg] = remove_transitive_deps(pkg, deps)
@@ -420,7 +424,7 @@ def main(): if check_only: sys.exit(0) - dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive) + dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, arrow_dir) dict_version = brpkgutil.get_version([pkg for pkg in allpkgs if pkg != "all" and not pkg.startswith("root")])
Signature · 1 line
2.14.1
Thomas Petazzoni
AppliedPATCH v3 2/3 support/graph-depends: don't eliminate mandatory deps for reverse graphs
Quoted 21 lines · On Fri, 22 Mar 2019 22:07:06 +0100 "Yann E. MORIN" <[email protected]>…
We we simplify the dependency graph, we try to remove so-called mandatory dependencies from each package, and for each mandatory that was thus removed, reattach it to the root-package of the graph.
This was made so that mandatory dependencies (which are dependencies of all packages, or at least of a lot of packages) do not clutter the dependency graph, but that they are still shown in the graph, as dependencies of the root package.
However, these mandatory dependencies are only _direct_ dependencies. As such, it does not make sense to reattach a mandatory dependency when doing a reverse graph. Worse, it can actually be incorrect.
For example, 'skeleton' is a mandatory dependency, and as such is removed from all packages. But when doing a reverse graph, skeleton is now in the dependency chain of, e.g. skeleton-init-none; it should then not be removed.
In short: the notion of mandatory dependencies does not make sense in the case of a reverse graph.
Quoted 8 lines
Consequently, skip over the mandatory dependency removal when doing a reverse graph.
Signed-off-by "Yann E. MORIN" <[email protected]>Cc Thomas Petazzoni <[email protected]>--- support/scripts/graph-depends | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v3 3/3 support/graph-depends: use the new make-based dependency tree
In reply to Yann E. MORINNow that we can get the whole dependency tree from make, use it to speed up things considerably.
So far, we had three functions to get the dependencies information:get_depends(), get_rdepends(), and, somehow unrelated, get_version().
Because of the way %-show-{,r}depends works, getting the dependency tree was expensive, the three functions all took a set of packages for which to get the dependencies, in an attempt to limit the time it took to get that tree, but we still had to call these functions iteratively, until they returned no new dependency. This was pretty costly.
Now, getting the tree is much, much less costly, and we can get the whole tree as cheaply as we previously got only the first-level dependencies.
Furthermore, we can now also get the version information at the same time, and that also brings in whether the package is virtual or not, target or host.
So, we drop all three helper functions, and replace them with a single one that returns all that information in one go: full dependency trees (direct and reverse), per-package type, and per-package version.
Note: since commit 2d29fd96a (pkg-virtual: remove VERSION/SOURCE), virtual packages are no longer reported as having a 'virtual' version, so have since been displayed as regular packages in the graphs. Although noone complained, this patch incidentally restores the initial behaviour, and virtual packages are now correctly displayed as such again.
---
Changes v2 -> v3:
- use defaultdict() (Thomas P.)
- also return the rdeps while at it
---
Note: as I rewrote brpkgutil.py almost entirely now, and as I also substantially modified graph-depends, I added my (C) to them. We don't usually have copyright information in our files (no .mk or no Config.in and such have that), so I think it would be OK to just drop the (C) in there as well, especially since the Berne convention does not require it for a work to be protected and recognised anyway:
https://en.wikipedia.org/wiki/Copyright_symbol
Beside, the authorship information is already present in the git log, and it is much more accurate in there than it is in the files themselves.
--- support/scripts/brpkgutil.py | 97 ++++++++++++++-------------------- support/scripts/graph-depends | 118 ++++++------------------------------------ 2 files changed, 55 insertions(+), 160 deletions(-)
support/scripts/brpkgutil.py +40 -57
@@ -1,67 +1,50 @@ # Copyright (C) 2010-2013 Thomas Petazzoni <[email protected]> +# Copyright (C) 2019 Yann E. MORIN <[email protected]> import logging -import sys +import os import subprocess +from collections import defaultdict -# Execute the "make <pkg>-show-version" command to get the version of a given -# list of packages, and return the version formatted as a Python dictionary. -def get_version(pkgs): - logging.info("Getting version for %s" % pkgs) - cmd = ["make", "-s", "--no-print-directory"] - for pkg in pkgs: - cmd.append("%s-show-version" % pkg) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) - output = p.communicate()[0] - if p.returncode != 0: - logging.error("Error getting version %s" % pkgs) - sys.exit(1) - output = output.split("\n") - if len(output) != len(pkgs) + 1: - logging.error("Error getting version") - sys.exit(1) - version = {} - for i in range(0, len(pkgs)): - pkg = pkgs[i] - version[pkg] = output[i] - return version +# This function returns a tuple of four dictionaries, all using package +# names as keys: +# - a dictionary which values are the lists of packages that are the +# dependencies of the package used as key; +# - a dictionary which values are the lists of packages that are the +# reverse dependencies of the package used as key; +# - a dictionary which values are the type of the package used as key; +# - a dictionary which values are the version of the package used as key, +# 'virtual' for a virtual package, or the empty string for a rootfs. +def get_dependency_tree(): + logging.info("Getting dependency tree...") + deps = defaultdict(list) + rdeps = defaultdict(list) + types = {} + versions = {} -def _get_depends(pkgs, rule): - logging.info("Getting dependencies for %s" % pkgs) - cmd = ["make", "-s", "--no-print-directory"] - for pkg in pkgs: - cmd.append("%s-%s" % (pkg, rule)) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) - output = p.communicate()[0] - if p.returncode != 0: - logging.error("Error getting dependencies %s\n" % pkgs) - sys.exit(1) - output = output.split("\n") - if len(output) != len(pkgs) + 1: - logging.error("Error getting dependencies") - sys.exit(1) - deps = {} - for i in range(0, len(pkgs)): - pkg = pkgs[i] - pkg_deps = output[i].split(" ") - if pkg_deps == ['']: - deps[pkg] = [] + # Special case for the 'all' top-level fake package + deps['all'] = [] + types['all'] = 'target' + versions['all'] = '' + + cmd = ["make", "-s", "--no-print-directory", "show-dependency-tree"] + with open(os.devnull, 'wb') as devnull: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull, universal_newlines=True) + output = p.communicate()[0] + + for l in output.splitlines(): + if " -> " in l: + pkg = l.split(" -> ")[0] + deps[pkg] += l.split(" -> ")[1].split() + for p in l.split(" -> ")[1].split(): + rdeps[p].append(pkg) else: - deps[pkg] = pkg_deps - return deps + pkg, type_version = l.split(": ", 1) + t, v = "{} -".format(type_version).split(None, 2)[:2] + deps['all'].append(pkg) + types[pkg] = t + versions[pkg] = v - -# Execute the "make <pkg>-show-depends" command to get the list of -# dependencies of a given list of packages, and return the list of -# dependencies formatted as a Python dictionary. -def get_depends(pkgs): - return _get_depends(pkgs, 'show-depends') - - -# Execute the "make <pkg>-show-rdepends" command to get the list of -# reverse dependencies of a given list of packages, and return the -# list of dependencies formatted as a Python dictionary. -def get_rdepends(pkgs): - return _get_depends(pkgs, 'show-rdepends') + return (deps, rdeps, types, versions)
support/scripts/graph-depends +15 -103
210 lines not on this page · raw message
Signature · 1 line
2.14.1
Thomas Petazzoni
AppliedPATCH v3 3/3 support/graph-depends: use the new make-based dependency tree
Quoted 31 lines · On Fri, 22 Mar 2019 22:07:07 +0100 "Yann E. MORIN" <[email protected]>…
Now that we can get the whole dependency tree from make, use it to speed up things considerably.
So far, we had three functions to get the dependencies information:
get_depends(),get_rdepends(), and, somehow unrelated,get_version().Because of the way %-show-{,r}depends works, getting the dependency tree was expensive, the three functions all took a set of packages for which to get the dependencies, in an attempt to limit the time it took to get that tree, but we still had to call these functions iteratively, until they returned no new dependency. This was pretty costly.
Now, getting the tree is much, much less costly, and we can get the whole tree as cheaply as we previously got only the first-level dependencies.
Furthermore, we can now also get the version information at the same time, and that also brings in whether the package is virtual or not, target or host.
So, we drop all three helper functions, and replace them with a single one that returns all that information in one go: full dependency trees (direct and reverse), per-package type, and per-package version.
Note: since commit
2d29fd96a(pkg-virtual: remove VERSION/SOURCE), virtual packages are no longer reported as having a 'virtual' version, so have since been displayed as regular packages in the graphs. Although noone complained, this patch incidentally restores the initial behaviour, and virtual packages are now correctly displayed as such again.
Quoted 8 lines
Signed-off-by "Yann E. MORIN" <[email protected]>Cc Thomas Petazzoni <[email protected]>Cc Thomas De Schampheleire <[email protected]>---
Changes v2 -> v3:
- usedefaultdict()(Thomas P.)
- also return the rdeps while at it
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com