Commits

Matthew Turk  committed e990695

Initial import

  • Participants

Comments (0)

Files changed (2)

File profile_support.py

+import time
+import cProfile
+
+import numpy as na
+import yt.utilities.command_line as cl
+import pkg_resources, os, sys, time
+
+def get_version_string():
+    yt_provider = pkg_resources.get_provider("yt")
+    path = os.path.dirname(yt_provider.module_path)
+    vc_type = cl._get_vcs_type(path)
+    vstring = cl._vcs_identifier[vc_type](path)
+    my_version = vstring.replace("(", "").replace(")","").replace(" ", "_")
+    return my_version
+
+_my_version = get_version_string()
+
+functions_to_profile = {}
+
+def profile_test(func):
+    functions_to_profile[func.func_name] = func
+    return func
+
+def run_all_tests(pf, ntimes = 1):
+    from mpi4py import MPI
+    rank = MPI.COMM_WORLD.rank
+    size = MPI.COMM_WORLD.size
+    results = {}
+    for fname in sorted(functions_to_profile):
+        print "HANDLING %s on %S / %s" % (
+            fname, rank, size)
+        ofn = "%s_%s_%03i_%03i" % (
+            fname, _my_version, size, rank)
+        times = []
+        for n in xrange(ntimes):
+            MPI.COMM_WORLD.Barrier()
+            t1 = time.time()
+            cProfile.run("fname(pf)", ofn)
+            MPI.COMM_WORLD.Barrier()
+            t2 = time.time()
+            times.append(t2-t1)
+        results[fname] = (na.min(times), na.max(times), na.average(times))
+    return results

File run_profiling.py

+from yt.config import ytcfg
+ytcfg["yt","loglevel"] = "20"
+ytcfg["yt","serialize"] = "False"
+
+from yt.mods import *
+from profile_support import profile_test, run_all_tests
+
+@profile_test
+def aaa_hierarchy(pf):
+    pf.h
+
+@profile_test
+def projection_density(pf):
+    proj = pf.h.proj(0, "Density")
+
+@profile_test
+def projection_ones(pf):
+    proj = pf.h.proj(0, "Ones")
+
+@profile_test
+def projection_velmag(pf):
+    proj = pf.h.proj(0, "VelocityMagnitude", "Density")
+
+@profile_test
+def quantities_extrema(pf):
+    dd = pf.h.all_data()
+    ex = dd.quantities["Extrema"](["Density", "Temperature"])
+    print "QUANTITIES", ex
+
+#@profile_test
+def profile_2d(pf):
+    dd = pf.h.all_data()
+    prof = BinnedProfile2D(dd,
+                128, "Density", min_rho, max_rho, True,
+                128, "Temperature", min_T, max_T, True,
+                           lazy_reader = True)
+    prof.add_fields(["CellMassMsun"], weight=None)
+
+pf = load("../DD0083/DD0083")
+
+run_all_tests(pf, 1)