Skip to content
Snippets Groups Projects
Unverified Commit 5bdba988 authored by Todd Gamblin's avatar Todd Gamblin
Browse files

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()`.
parent cbf85534
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import contextlib
import sys import sys
import llnl.util.tty as tty import llnl.util.tty as tty
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
import spack.cmd import spack.cmd
import spack.cmd.common.arguments as arguments import spack.cmd.common.arguments as arguments
import spack.spec import spack.spec
import spack.store
import spack.hash_types as ht import spack.hash_types as ht
description = "show what would be installed, given a spec" description = "show what would be installed, given a spec"
...@@ -45,6 +47,14 @@ def setup_parser(subparser): ...@@ -45,6 +47,14 @@ def setup_parser(subparser):
'specs', nargs=argparse.REMAINDER, help="specs of packages") '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): def spec(parser, args):
name_fmt = '{namespace}.{name}' if args.namespaces else '{name}' name_fmt = '{namespace}.{name}' if args.namespaces else '{name}'
fmt = '{@version}{%compiler}{compiler_flags}{variants}{arch=architecture}' fmt = '{@version}{%compiler}{compiler_flags}{variants}{arch=architecture}'
...@@ -57,6 +67,12 @@ def spec(parser, args): ...@@ -57,6 +67,12 @@ def spec(parser, args):
'status_fn': install_status_fn if args.install_status else None '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: if not args.specs:
tty.die("spack spec requires at least one spec") tty.die("spack spec requires at least one spec")
...@@ -73,13 +89,14 @@ def spec(parser, args): ...@@ -73,13 +89,14 @@ def spec(parser, args):
print(spec.to_json(hash=ht.build_hash)) print(spec.to_json(hash=ht.build_hash))
continue continue
kwargs['hashes'] = False # Always False for input spec with tree_context():
print("Input spec") kwargs['hashes'] = False # Always False for input spec
print("--------------------------------") print("Input spec")
print(spec.tree(**kwargs)) print("--------------------------------")
print(spec.tree(**kwargs))
kwargs['hashes'] = args.long or args.very_long kwargs['hashes'] = args.long or args.very_long
print("Concretized") print("Concretized")
print("--------------------------------") print("--------------------------------")
spec.concretize() spec.concretize()
print(spec.tree(**kwargs)) print(spec.tree(**kwargs))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment