concretizer: add timers around phases
This commit is contained in:
parent
5185ed1d28
commit
7a1b5ca65e
@ -55,6 +55,9 @@ def setup_parser(subparser):
|
|||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-t', '--types', action='store_true', default=False,
|
'-t', '--types', action='store_true', default=False,
|
||||||
help='show dependency types')
|
help='show dependency types')
|
||||||
|
subparser.add_argument(
|
||||||
|
'--timers', action='store_true', default=False,
|
||||||
|
help='print out timers for different solve phases')
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'specs', nargs=argparse.REMAINDER, help="specs of packages")
|
'specs', nargs=argparse.REMAINDER, help="specs of packages")
|
||||||
|
|
||||||
@ -90,7 +93,7 @@ def solve(parser, args):
|
|||||||
specs = spack.cmd.parse_specs(args.specs)
|
specs = spack.cmd.parse_specs(args.specs)
|
||||||
|
|
||||||
# dump generated ASP program
|
# dump generated ASP program
|
||||||
result = asp.solve(specs, dump=dump, models=models)
|
result = asp.solve(specs, dump=dump, models=models, timers=args.timers)
|
||||||
if 'solutions' not in dump:
|
if 'solutions' not in dump:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import time
|
||||||
import types
|
import types
|
||||||
from six import string_types
|
from six import string_types
|
||||||
|
|
||||||
@ -861,10 +862,30 @@ def highlight(string):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
class Timer(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.start = time.time()
|
||||||
|
self.last = self.start
|
||||||
|
self.phases = {}
|
||||||
|
|
||||||
|
def phase(self, name):
|
||||||
|
last = self.last
|
||||||
|
now = time.time()
|
||||||
|
self.phases[name] = now - last
|
||||||
|
self.last = now
|
||||||
|
|
||||||
|
def write(self, out=sys.stdout):
|
||||||
|
now = time.time()
|
||||||
|
out.write("Time:\n")
|
||||||
|
for phase, t in self.phases.items():
|
||||||
|
out.write(" %-15s%.4f\n" % (phase + ":", t))
|
||||||
|
out.write("Total: %.4f\n" % (now - self.start))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# These are handwritten parts for the Spack ASP model.
|
# These are handwritten parts for the Spack ASP model.
|
||||||
#
|
#
|
||||||
def solve(specs, dump=None, models=0):
|
def solve(specs, dump=None, models=0, timers=False):
|
||||||
"""Solve for a stable model of specs.
|
"""Solve for a stable model of specs.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -878,15 +899,17 @@ def solve(specs, dump=None, models=0):
|
|||||||
def colorize(string):
|
def colorize(string):
|
||||||
color.cprint(highlight(color.cescape(string)))
|
color.cprint(highlight(color.cescape(string)))
|
||||||
|
|
||||||
|
timer = Timer()
|
||||||
with tempfile.TemporaryFile("w+") as program:
|
with tempfile.TemporaryFile("w+") as program:
|
||||||
generator = AspGenerator(program)
|
generator = AspGenerator(program)
|
||||||
generator.generate_asp_program(specs)
|
generator.generate_asp_program(specs)
|
||||||
|
timer.phase("generate")
|
||||||
program.seek(0)
|
program.seek(0)
|
||||||
|
|
||||||
result = Result(program.read())
|
result = Result(program.read())
|
||||||
program.seek(0)
|
program.seek(0)
|
||||||
|
|
||||||
if 'asp' in dump:
|
if dump and 'asp' in dump:
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
tty.msg('ASP program:')
|
tty.msg('ASP program:')
|
||||||
|
|
||||||
@ -895,6 +918,7 @@ def colorize(string):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
colorize(result.asp)
|
colorize(result.asp)
|
||||||
|
timer.phase("dump")
|
||||||
|
|
||||||
with tempfile.TemporaryFile("w+") as output:
|
with tempfile.TemporaryFile("w+") as output:
|
||||||
with tempfile.TemporaryFile() as warnings:
|
with tempfile.TemporaryFile() as warnings:
|
||||||
@ -915,6 +939,7 @@ def colorize(string):
|
|||||||
output=output,
|
output=output,
|
||||||
error=warnings,
|
error=warnings,
|
||||||
fail_on_error=False)
|
fail_on_error=False)
|
||||||
|
timer.phase("solve")
|
||||||
|
|
||||||
warnings.seek(0)
|
warnings.seek(0)
|
||||||
result.warnings = warnings.read().decode("utf-8")
|
result.warnings = warnings.read().decode("utf-8")
|
||||||
@ -927,9 +952,10 @@ def colorize(string):
|
|||||||
|
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
result.output = output.read()
|
result.output = output.read()
|
||||||
|
timer.phase("read")
|
||||||
|
|
||||||
# dump the raw output of the solver
|
# dump the raw output of the solver
|
||||||
if 'output' in dump:
|
if dump and 'output' in dump:
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
tty.msg('Clingo output:')
|
tty.msg('Clingo output:')
|
||||||
print(result.output)
|
print(result.output)
|
||||||
@ -939,5 +965,10 @@ def colorize(string):
|
|||||||
|
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
parser.parse_best(output, result)
|
parser.parse_best(output, result)
|
||||||
|
timer.phase("parse")
|
||||||
|
|
||||||
|
if timers:
|
||||||
|
timer.write()
|
||||||
|
print()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user