Commits

Matthew Turk committed b098c13

Drop the old stateful profile runner and instead use with parallel_profile.

  • Participants
  • Parent commits 21e1e70

Comments (0)

Files changed (2)

profile_support.py

 import time
 import cProfile
 import cProfile
+import pkg_resources, os, sys, time
+import numpy as na
 
-import numpy as na
+from yt.mods import *
 import yt.utilities.command_line as cl
-import pkg_resources, os, sys, time
 
 try:
     import pyprof2html.core
     functions_to_profile[func.func_name] = func
     return func
 
-class StatefulProfileRunner:
-    # Something about the way cProfile operates and interacts with globals and
-    # locals doesn't like the execution from within run_all_tests.  So we
-    # create this object, of which there will only be one, and it can have
-    # functions associated with it.
-    def __init__(self):
-        self.func = lambda a: None
-
-    def run(self, pf):
-        self.func(pf)
-
-profile_runner = StatefulProfileRunner()
-
-def run_all_tests(pf, ntimes = 1, output_html = True):
+def run_all_tests(pf, ntimes = 2, output_html = True):
     from mpi4py import MPI
     rank = MPI.COMM_WORLD.rank
     size = MPI.COMM_WORLD.size
     for fname in sorted(functions_to_profile):
         print "HANDLING %s on %s / %s" % (
             fname, rank, size)
-        ofn = "profiles/%s_%s_%03i_%03i.cprof" % (
-            fname, _my_version, size, rank)
+        fnprefix = "profiles/%s_%s" % (fname, _my_version)
         times = []
-        profile_runner.func = functions_to_profile[fname]
         for n in xrange(ntimes):
             def new_func():
                 func(pf)
             MPI.COMM_WORLD.Barrier()
             t1 = time.time()
-            hprof = cProfile.Profile()
-            hprof.runcall(profile_runner.run, pf)
-            hprof.dump_stats(ofn)
+            with parallel_profile(fnprefix) as ofn:
+                functions_to_profile[fname](pf)
             MPI.COMM_WORLD.Barrier()
             t2 = time.time()
             times.append(t2-t1)
             if rank == 0 and not os.path.exists(dname):
                 os.makedirs(dname)
             MPI.COMM_WORLD.Barrier()
+            # We assume that the final output is the only interesting one.
             ppw = pyprof2html.core.Converter(ofn)
             ppw.printout(filetype="html",
                   output_directory=dname,
 ytcfg["yt","serialize"] = "False"
 
 from yt.mods import *
-from profile_support import profile_test, run_all_tests, profile_runner
+from profile_support import profile_test, run_all_tests
 
 @profile_test
 def aaa_hierarchy(pf):
     proj = pf.h.proj(0, "DivV", "Density")
 
 @profile_test
+def projection_vort(pf):
+    proj = pf.h.proj(0, "VorticitySquared", "Density")
+
+@profile_test
+def profile_gzs(pf):
+    dd = pf.h.all_data()
+    (v_min, v_max), (div_min, div_max) = dd.quantities[
+        "Extrema"](["VorticitySquared", "DivV"])
+    prof = BinnedProfile2D(dd,
+                128, "VorticitySquared", v_min, v_max, True,
+                128, "DivV", div_min, div_max, False,
+                           lazy_reader = True)
+    prof.add_fields(["CellMassMsun"], weight=None)
+
+@profile_test
 def quantities_extrema(pf):
     dd = pf.h.all_data()
     ex = dd.quantities["Extrema"](["Density", "Temperature"])
                            lazy_reader = True)
     prof.add_fields(["CellMassMsun"], weight=None)
 
-pf = load("DD0087/DD0087", data_style="enzo_packed_3d")
+pf = load("DD0039/output_0039", data_style="enzo_packed_3d")
 
 run_all_tests(pf, 1, True)