Commits

Geoffrey Sneddon committed 7281ef5

Use either cProfile or hotshot depending on what is available.

  • Participants
  • Parent commits d0260be

Comments (0)

Files changed (2)

                       dest="w3c_compat_crazy_substitutions",
                       help="Do crazy W3C specific substitutions, which may cause unexpected behaviour (i.e., replacing random strings within the document with no special marker).")
 
+    profile = True
     try:
-        import hotshot
-        import hotshot.stats
+        import cProfile
+        import pstats
+    except ImportError:
+        try:
+            import hotshot
+            import hotshot.stats
+        except ImportError:
+            profile = False
+    
+    if profile:
         parser.add_option("", "--profile", action="store_true",
             dest="profile", help=SUPPRESS_HELP)
-    except ImportError:
-        pass
 
     parser.add_option("", "--inject-meta-charset", action="store_true",
                       dest="inject_meta_charset", help=SUPPRESS_HELP)

File anolislib/generator.py

 
     # Run the generator, and profile, or not, as the case may be
     if profile:
-        import hotshot
-        import hotshot.stats
         import os
         import tempfile
         statfile = tempfile.mkstemp()[1]
-        prof = hotshot.Profile(statfile)
-        prof.runcall(process, tree, processes, **kwargs)
-        prof.close()
-        stats = hotshot.stats.load(statfile)
+        try:
+            import cProfile
+            import pstats
+            cProfile.run("process(tree, processes, **kwargs)", statfile)
+            stats = pstats.Stats(statfile)
+        except None:
+            import hotshot
+            import hotshot.stats
+            prof = hotshot.Profile(statfile)
+            prof.runcall(process, tree, processes, **kwargs)
+            prof.close()
+            stats = hotshot.stats.load(statfile)
         stats.strip_dirs()
         stats.sort_stats('time')
         stats.print_stats()