Parcourir la source

objgraph command now accepts type argument

Ask Solem il y a 11 ans
Parent
commit
e41eef236f
3 fichiers modifiés avec 9 ajouts et 5 suppressions
  1. 2 2
      celery/app/control.py
  2. 4 1
      celery/bin/celery.py
  3. 3 2
      celery/worker/control.py

+ 2 - 2
celery/app/control.py

@@ -113,8 +113,8 @@ 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)
+    def objgraph(self, type='Request', n=200, max_depth=10):
+        return self._request('objgraph', num=n, max_depth=max_depth, type=type)
 
 
 class Control(object):

+ 4 - 1
celery/bin/celery.py

@@ -358,13 +358,16 @@ 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)'),
+        'objgraph': (60.0, 'create object graph (requires objgraph)'),
     }
 
     def call(self, method, *args, **options):
         i = self.app.control.inspect(**options)
         return getattr(i, method)(*args)
 
+    def objgraph(self, type_='Request', *args, **kwargs):
+        return self.call('objgraph', type_)
+
 
 class control(_RemoteControl):
     """Workers remote control.

+ 3 - 2
celery/worker/control.py

@@ -171,14 +171,15 @@ def stats(state, **kwargs):
 
 
 @Panel.register
-def objgraph(state, num=200, max_depth=10, ):  # pragma: no cover
+def objgraph(state, num=200, max_depth=10, type='Request'):  # pragma: no cover
     try:
         import objgraph
     except ImportError:
         raise ImportError('Requires the objgraph library')
+    print('Dumping graph for type %r' % (type, ))
     with tempfile.NamedTemporaryFile(prefix='cobjg',
                                      suffix='.png', delete=False) as fh:
-        objects = objgraph.by_type('Request')[:num]
+        objects = objgraph.by_type(type)[:num]
         objgraph.show_backrefs(
             objects,
             max_depth=max_depth, highlight=lambda v: v in objects,