Jelajahi Sumber

Bake in profiling capability.

Chris McDonough 17 tahun lalu
induk
melakukan
67a87c09b2
2 mengubah file dengan 17 tambahan dan 0 penghapusan
  1. 1 0
      setup.py
  2. 16 0
      src/supervisor/supervisord.py

+ 1 - 0
setup.py

@@ -86,6 +86,7 @@ dist = setup(
      'supervisor_rpc':['main = supervisor.rpcinterface:make_main_rpcinterface'],
      'console_scripts': [
          'supervisord = supervisor.supervisord:main',
+         'profile_supervisord = supervisor.supervisord:profile',
          'supervisorctl = supervisor.supervisorctl:main',
          ],
       },

+ 16 - 0
src/supervisor/supervisord.py

@@ -307,5 +307,21 @@ def main(test=False):
         if d.options.httpserver:
             d.options.httpserver.close()
 
+def profile(test=False):
+    import profile
+    import pstats
+    import tempfile
+    fd, fn = tempfile.mkstemp()
+    try:
+        profile.runctx('main(test)', globals(), locals(), fn)
+        stats = pstats.Stats(fn)
+        stats.strip_dirs()
+        #stats.sort_stats('calls', 'time', 'cumulative')
+        stats.sort_stats('cumulative', 'calls', 'time')
+        #stats.print_callers(.3)
+        stats.print_stats(.3)
+    finally:
+        os.remove(fn)
+
 if __name__ == "__main__":
     main()