All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] support/script/pkg-stats: run the 3 `make` calls in parallel
@ 2019-07-11  9:54 Victor Huesca
  2019-07-11  9:54 ` [Buildroot] [PATCH 2/2] support/script/pkg-stats: run 'get latest version' in a process-pool Victor Huesca
  2019-07-11 13:08 ` [Buildroot] [PATCH 1/2] support/script/pkg-stats: run the 3 `make` calls in parallel Thomas Petazzoni
  0 siblings, 2 replies; 6+ messages in thread
From: Victor Huesca @ 2019-07-11  9:54 UTC (permalink / raw)
  To: buildroot

The pkg-stats calls 3 times `make` to get a bunch of variables. These
calls all takes about the same time -- 95% of the time is spent parsing
the makefile -- so running these subprocesses in parallel can save this
shared time.

The gain scale quite well since with only 3 subprocesses I achieve a
x2.5 ~ x3 speedup.

Signed-off-by: Victor Huesca <victor.huesca@bootlin.com>
---
 support/scripts/pkg-stats | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/support/scripts/pkg-stats b/support/scripts/pkg-stats
index 1ff3fb2bd1..2ed41dffa9 100755
--- a/support/scripts/pkg-stats
+++ b/support/scripts/pkg-stats
@@ -220,11 +220,30 @@ def get_pkglist(npackages, package_list):
     return packages
 
 
+def check_multiple_output(cmds, *popenargs, **kwargs):
+    '''
+    Run each `cmd` asynchronousely and return their respective output.
+    The execution time is the max of all subprocess execution time.
+    '''
+    processes = [subprocess.Popen(cmd, *popenargs,
+                                  stdout=subprocess.PIPE,
+                                  stderr=subprocess.PIPE,
+                                  **kwargs) for cmd in cmds]
+    for proc in processes:
+        out, err = proc.communicate()
+        yield out
+
+
 def package_init_make_info():
+    # Fetch all variables at once
+    licenses, files, versions = check_multiple_output([
+        ["make", "BR2_HAVE_DOT_CONFIG=y", "-s", "printvars", "VARS=%_LICENSE"],
+        ["make", "BR2_HAVE_DOT_CONFIG=y", "-s", "printvars", "VARS=%_LICENSE_FILES"],
+        ["make", "BR2_HAVE_DOT_CONFIG=y", "-s", "printvars", "VARS=%_VERSION"],
+    ])
+
     # Licenses
-    o = subprocess.check_output(["make", "BR2_HAVE_DOT_CONFIG=y",
-                                 "-s", "printvars", "VARS=%_LICENSE"])
-    for l in o.splitlines():
+    for l in licenses.splitlines():
         # Get variable name and value
         pkgvar, value = l.split("=")
 
@@ -241,9 +260,7 @@ def package_init_make_info():
         Package.all_licenses.append(pkgvar)
 
     # License files
-    o = subprocess.check_output(["make", "BR2_HAVE_DOT_CONFIG=y",
-                                 "-s", "printvars", "VARS=%_LICENSE_FILES"])
-    for l in o.splitlines():
+    for l in files.splitlines():
         # Get variable name and value
         pkgvar, value = l.split("=")
 
@@ -260,14 +277,12 @@ def package_init_make_info():
         Package.all_license_files.append(pkgvar)
 
     # Version
-    o = subprocess.check_output(["make", "BR2_HAVE_DOT_CONFIG=y",
-                                 "-s", "printvars", "VARS=%_VERSION"])
 
     # We process first the host package VERSION, and then the target
     # package VERSION. This means that if a package exists in both
     # target and host variants, with different version numbers
     # (unlikely), we'll report the target version number.
-    version_list = o.splitlines()
+    version_list = versions.splitlines()
     version_list = [x for x in version_list if x.startswith("HOST_")] + \
                    [x for x in version_list if not x.startswith("HOST_")]
     for l in version_list:
-- 
2.21.0

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

end of thread, other threads:[~2019-07-11 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-11  9:54 [Buildroot] [PATCH 1/2] support/script/pkg-stats: run the 3 `make` calls in parallel Victor Huesca
2019-07-11  9:54 ` [Buildroot] [PATCH 2/2] support/script/pkg-stats: run 'get latest version' in a process-pool Victor Huesca
2019-07-11 13:37   ` Arnout Vandecappelle
2019-07-11 13:08 ` [Buildroot] [PATCH 1/2] support/script/pkg-stats: run the 3 `make` calls in parallel Thomas Petazzoni
2019-07-11 13:17   ` Victor Huesca
2019-07-11 13:18   ` Arnout Vandecappelle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.