[Yt-svn] commit/yt: MatthewTurk: Adding a ProfilingController object. See
Bitbucket
commits-noreply at bitbucket.org
Thu Mar 10 11:57:01 PST 2011
1 new changeset in yt:
http://bitbucket.org/yt_analysis/yt/changeset/c4f0e119b2c4/
changeset: r3807:c4f0e119b2c4
branch: yt
user: MatthewTurk
date: 2011-03-10 20:56:50
summary: Adding a ProfilingController object. See
http://paste.enzotools.org/show/1527/
for an example of how to use it. This is parallel-aware, and it will include
the processor information in the output filenames.
affected #: 1 file (1.1 KB)
--- a/yt/utilities/performance_counters.py Wed Mar 09 07:38:54 2011 -0800
+++ b/yt/utilities/performance_counters.py Thu Mar 10 11:56:50 2011 -0800
@@ -100,3 +100,36 @@
yt_counters = PerformanceCounters()
time_function = yt_counters.call_func
+
+
+class ProfilingController(object):
+ def __init__(self):
+ self.profilers = {}
+
+ def profile_function(self, function_name):
+ def wrapper(func):
+ try:
+ import cProfile
+ except ImportError:
+ return func
+ my_prof = cProfile.Profile()
+ self.profilers[function_name] = my_prof
+ @wraps(func)
+ def run_in_profiler(*args, **kwargs):
+ my_prof.enable()
+ func(*args, **kwargs)
+ my_prof.disable()
+ return run_in_profiler
+ return wrapper
+
+ def write_out(self, filename_prefix):
+ if ytcfg.getboolean("yt","__parallel"):
+ pfn = "%s_%03i_%03i" % (filename_prefix,
+ ytcfg.getint("yt", "__parallel_rank"),
+ ytcfg.getint("yt", "__parallel_size"))
+ else:
+ pfn = "%s" % (filename_prefix)
+ for n, p in sorted(self.profilers.items()):
+ fn = "%s_%s.cprof" % (pfn, n)
+ mylog.info("Dumping %s into %s", n, fn)
+ p.dump_stats(fn)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list