summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-12-17 12:50:44 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-18 16:07:28 -0800
commit0e9c8d236cc4b75e929d6212245a517d3847dc5d (patch)
tree97120c4d3833184fac26d1b829f0ebe5018fca00 /lib
parentf73cdac731a0f5955c1843535b21ce1101d897c3 (diff)
downloadspack-0e9c8d236cc4b75e929d6212245a517d3847dc5d.tar.gz
spack-0e9c8d236cc4b75e929d6212245a517d3847dc5d.tar.bz2
spack-0e9c8d236cc4b75e929d6212245a517d3847dc5d.tar.xz
spack-0e9c8d236cc4b75e929d6212245a517d3847dc5d.zip
performance: `spack spec` should use a read transacction with -I
`spack spec -I` queries the database for installation status and should use a read transaction around calls to `Spec.tree()`.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/spec.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/spec.py b/lib/spack/spack/cmd/spec.py
index f63ac638c4..f10eef9c73 100644
--- a/lib/spack/spack/cmd/spec.py
+++ b/lib/spack/spack/cmd/spec.py
@@ -6,6 +6,7 @@
from __future__ import print_function
import argparse
+import contextlib
import sys
import llnl.util.tty as tty
@@ -14,6 +15,7 @@ import spack
import spack.cmd
import spack.cmd.common.arguments as arguments
import spack.spec
+import spack.store
import spack.hash_types as ht
description = "show what would be installed, given a spec"
@@ -45,6 +47,14 @@ def setup_parser(subparser):
'specs', nargs=argparse.REMAINDER, help="specs of packages")
+@contextlib.contextmanager
+def nullcontext():
+ """Empty context manager.
+ TODO: replace with contextlib.nullcontext() if we ever require python 3.7.
+ """
+ yield
+
+
def spec(parser, args):
name_fmt = '{namespace}.{name}' if args.namespaces else '{name}'
fmt = '{@version}{%compiler}{compiler_flags}{variants}{arch=architecture}'
@@ -57,6 +67,12 @@ def spec(parser, args):
'status_fn': install_status_fn if args.install_status else None
}
+ # use a read transaction if we are getting install status for every
+ # spec in the DAG. This avoids repeatedly querying the DB.
+ tree_context = nullcontext
+ if args.install_status:
+ tree_context = spack.store.db.read_transaction
+
if not args.specs:
tty.die("spack spec requires at least one spec")
@@ -73,13 +89,14 @@ def spec(parser, args):
print(spec.to_json(hash=ht.build_hash))
continue
- kwargs['hashes'] = False # Always False for input spec
- print("Input spec")
- print("--------------------------------")
- print(spec.tree(**kwargs))
+ with tree_context():
+ kwargs['hashes'] = False # Always False for input spec
+ print("Input spec")
+ print("--------------------------------")
+ print(spec.tree(**kwargs))
- kwargs['hashes'] = args.long or args.very_long
- print("Concretized")
- print("--------------------------------")
- spec.concretize()
- print(spec.tree(**kwargs))
+ kwargs['hashes'] = args.long or args.very_long
+ print("Concretized")
+ print("--------------------------------")
+ spec.concretize()
+ print(spec.tree(**kwargs))