-
Notifications
You must be signed in to change notification settings - Fork 1
/
profile_simulation.py
63 lines (52 loc) · 1.71 KB
/
profile_simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import logging
log = logging.getLogger("main")
from optparse import OptionParser
import sys
from yeasty import config, script, context
cfg = config.Configuration(True)
def configure_options():
usage = """usage: python %prog [options] <foldername>"""
parser = OptionParser(usage)
parser.add_option(
"-v", "--verbose",
action="store_true", dest="verbose",
help="show verbose (debug) output")
parser.add_option(
"-c", "--clean",
action="store_true", dest="clean",
help="Clean any previous output")
parser.add_option(
"-g", "--graphics=",
type="int", dest="graphics", default=0, metavar="N",
help="show graphics every N steps")
return parser
def configure_logging():
# TODO Add additional logger in the output folder
handler = logging.StreamHandler(sys.stdout)
# format = "%(name)-15s | %(levelname)-8s | %(asctime)s | %(message)s"
format = "%(name)-15s | %(levelname)-8s | %(message)s"
formatter = logging.Formatter(format)
handler.setFormatter(formatter)
root = logging.getLogger("")
root.addHandler(handler)
root.setLevel(logging.INFO)
def load():
global cfg
configure_logging()
parser = configure_options()
options, args = parser.parse_args()
ctx = context.Context(cfg)
sct = script.Script(ctx)
sct.load(args[0])
def run():
global cfg
cfg.experiment.run(None)
if __name__ == "__main__":
import cProfile
import pstats
# Well behaved unix programs exits with 0 on success...
load()
cProfile.run('run()', 'profile.output')
p = pstats.Stats('profile.output')
p.sort_stats('time').print_stats(20)
# p.strip_dirs().sort_stats(-1).print_stats()