Matthew Turk avatar Matthew Turk committed 536317b

Moving to hotshot, adding some support for direct output from pyprof2html

Comments (0)

Files changed (2)

profile_support.py

 import time
 import cProfile
+import hotshot
 
 import numpy as na
 import yt.utilities.command_line as cl
 import pkg_resources, os, sys, time
 
 try:
-    import pyprof2html
-    from pyprof2html.core import Converter
+    import pyprof2html.core
 except ImportError:
     pass
 
 
 profile_runner = StatefulProfileRunner()
 
-def run_all_tests(pf, ntimes = 1, output_html = False)
+def run_all_tests(pf, ntimes = 1, output_html = True):
     from mpi4py import MPI
     rank = MPI.COMM_WORLD.rank
     size = MPI.COMM_WORLD.size
+    td = None
+    if rank == 0:
+        td = time.strftime("%Y%m%d-%H%M")
+    td = MPI.COMM_WORLD.bcast(td, root = 0)
     results = {}
     for fname in sorted(functions_to_profile):
         print "HANDLING %s on %s / %s" % (
             fname, rank, size)
-        ofn = "%s_%s_%03i_%03i.cprof" % (
+        ofn = "profiles/%s_%s_%03i_%03i.hotshot" % (
             fname, _my_version, size, rank)
         times = []
         profile_runner.func = functions_to_profile[fname]
                 func(pf)
             MPI.COMM_WORLD.Barrier()
             t1 = time.time()
-            cProfile.run("profile_runner.run(pf)", ofn)
+            hprof = hotshot.Profile(ofn)
+            hprof.runcall(profile_runner.run, pf)
+            hprof.close()
             MPI.COMM_WORLD.Barrier()
             t2 = time.time()
             times.append(t2-t1)
             print "Results [%s]: %0.3e %0.3e %0.3e" % (
                 fname, results[fname][0], results[fname][1], results[fname][2])
         if output_html:
-            p2h = Converter(ofn)
-            odir = "html/%s/%s/%03i" % (_my_version, fname, size)
-            p2h.printout(filetype="html", output_directory=odir,
-                         output_htmlfile="index-%03i.html" % rank,
-                         functions_number=99999)
+            print "Writing output file on %03i / %03i" % (rank, size)
+            # We step through it
+            dname = "html/%s-%s/%s" % (td,_my_version, fname)
+            if rank == 0 and not os.path.exists(dname):
+                os.makedirs(dname)
+            MPI.COMM_WORLD.Barrier()
+            ppw = pyprof2html.core.Converter(ofn)
+            ppw.printout(filetype="html",
+                  output_directory=dname,
+                  output_htmlfile="index-%03i_%03i.html" % (size, rank),
+                  functions_number=99999)
     return results
                            lazy_reader = True)
     prof.add_fields(["CellMassMsun"], weight=None)
 
-#pf = load("../DD0083/DD0083", data_style="enzo_packed_3d")
-pf = load("/nics/d/home/davem/turk/tar1/DD0083/DD0083")
+pf = load("../RD0035/RD0035", data_style="enzo_packed_3d")
+#pf = load("/nics/d/home/davem/turk/tar1/DD0083/DD0083")
 
 run_all_tests(pf, 1, True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.