提交 05a30361 authored 作者: carriepl's avatar carriepl

Merge pull request #2168 from aalmah/ticket_2125

fixing #2125: redirecting profiling output to a file
...@@ -338,6 +338,17 @@ import theano and print the config variable, as in: ...@@ -338,6 +338,17 @@ import theano and print the config variable, as in:
Do the memory profile print the min peak memory usage? Do the memory profile print the min peak memory usage?
It only works when profile=True, profile_memory=True It only works when profile=True, profile_memory=True
.. attribute:: profiling.destination
String value: 'stderr', 'stdout', or a name of a
file to be created
Default 'stderr'
Name of the destination file for the profiling output.
The profiling output can be either directed to stderr
(default), or stdout or an arbitrary file.
.. attribute:: config.lib.amdlibm .. attribute:: config.lib.amdlibm
Bool value: either True or False Bool value: either True or False
......
...@@ -25,14 +25,13 @@ import numpy ...@@ -25,14 +25,13 @@ import numpy
import theano import theano
from theano.gof import graph from theano.gof import graph
from theano.configparser import AddConfigVar, BoolParam, IntParam from theano.configparser import AddConfigVar, BoolParam, IntParam, StrParam
import_time = time.time() import_time = time.time()
config = theano.config config = theano.config
_atexit_print_list = [] _atexit_print_list = []
_atexit_print_file = sys.stderr
_atexit_registered = False _atexit_registered = False
AddConfigVar('profiling.time_thunks', AddConfigVar('profiling.time_thunks',
...@@ -66,14 +65,29 @@ AddConfigVar('profiling.min_peak_memory', ...@@ -66,14 +65,29 @@ AddConfigVar('profiling.min_peak_memory',
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
AddConfigVar('profiling.destination',
"""
File destination of the profiling output
""",
StrParam('stderr'),
in_c_key=False)
def _atexit_print_fn(): def _atexit_print_fn():
"""Print ProfileStat objects in _atexit_print_list to _atexit_print_file """Print ProfileStat objects in _atexit_print_list to _atexit_print_file
""" """
to_sum = [] to_sum = []
if config.profiling.destination == 'stderr':
destination_file = sys.stderr
elif config.profiling.destination == 'stdout':
destination_file = sys.stdout
else:
destination_file = open(config.profiling.destination, 'w')
for ps in _atexit_print_list: for ps in _atexit_print_list:
if ps.fct_callcount or ps.compile_time > 0: if ps.fct_callcount or ps.compile_time > 0:
ps.summary(file=_atexit_print_file, ps.summary(file=destination_file,
n_ops_to_print=config.profiling.n_ops, n_ops_to_print=config.profiling.n_ops,
n_apply_to_print=config.profiling.n_apply) n_apply_to_print=config.profiling.n_apply)
if not isinstance(ps, ScanProfileStats): if not isinstance(ps, ScanProfileStats):
...@@ -109,7 +123,7 @@ def _atexit_print_fn(): ...@@ -109,7 +123,7 @@ def _atexit_print_fn():
else: else:
cum.optimizer_profile = None cum.optimizer_profile = None
cum.summary(file=_atexit_print_file, cum.summary(file=destination_file,
n_ops_to_print=config.profiling.n_ops, n_ops_to_print=config.profiling.n_ops,
n_apply_to_print=config.profiling.n_apply) n_apply_to_print=config.profiling.n_apply)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论