Ver Fonte

Creates remote control command: objgraph

Ask Solem há 12 anos atrás
pai
commit
0976fbcbd1
3 ficheiros alterados com 22 adições e 0 exclusões
  1. 3 0
      celery/app/control.py
  2. 1 0
      celery/bin/celery.py
  3. 18 0
      celery/worker/control.py

+ 3 - 0
celery/app/control.py

@@ -97,6 +97,9 @@ class Inspect(object):
     def memdump(self, samples=10):
         return self._request('memdump', samples=samples)
 
+    def objgraph(self, n=200, max_depth=10):
+        return self._request('objgraph', num=n, max_depth=max_depth)
+
 
 class Control(object):
     Mailbox = Mailbox

+ 1 - 0
celery/bin/celery.py

@@ -368,6 +368,7 @@ class inspect(_RemoteControl):
         'report': (1.0, 'get bugreport info'),
         'memsample': (1.0, 'sample memory (requires psutil)'),
         'memdump': (1.0, 'dump memory samples (requires psutil)'),
+        'objgraph': (4.0, 'create object graph (requires objgraph)'),
     }
 
     def call(self, method, *args, **options):

+ 18 - 0
celery/worker/control.py

@@ -9,6 +9,7 @@
 from __future__ import absolute_import
 
 import logging
+import tempfile
 
 from kombu.utils.encoding import safe_repr
 
@@ -175,6 +176,23 @@ def stats(panel, **kwargs):
     return panel.consumer.controller.stats()
 
 
+@Panel.register
+def objgraph(panel, num=200, max_depth=10, ):
+    try:
+        import objgraph
+    except ImportError:
+        raise ImportError('Requires the objgraph library')
+    with tempfile.NamedTemporaryFile(prefix='cobjg',
+                                     suffix='.png', delete=False) as fh:
+        objects = objgraph.by_type('Request')[:num]
+        objgraph.show_backrefs(
+            objects,
+            max_depth=max_depth, highlight=lambda v: v in objects,
+            filename=fh.name,
+        )
+        return {'filename': fh.name}
+
+
 @Panel.register
 def memsample(panel, **kwargs):
     from celery.utils.debug import sample_mem