def _api_debug(stream, request, query): ''' Implements /api/debug URI ''' response = Message() debuginfo = {} NOTIFIER.snap(debuginfo) POLLER.snap(debuginfo) debuginfo["queue_history"] = QUEUE_HISTORY debuginfo["WWWDIR"] = utils_hier.WWWDIR gc.collect() debuginfo['typestats'] = objgraph.typestats() body = pprint.pformat(debuginfo) response.compose(code="200", reason="Ok", body=body, mimetype="text/plain") stream.send_response(request, response)
def _api_debug(self, stream, request, query): response = Message() debuginfo = {} NOTIFIER.snap(debuginfo) POLLER.snap(debuginfo) debuginfo["queue_history"] = QUEUE_HISTORY debuginfo["WWW"] = WWW gc.collect() debuginfo['typestats'] = objgraph.typestats() stringio = StringIO.StringIO() pprint.pprint(debuginfo, stringio) stringio.seek(0) response.compose(code="200", reason="Ok", body=stringio, mimetype="text/plain") stream.send_response(request, response)
def process_request(self, stream, request): ''' Process HTTP request and return response ''' response = Message() if request.uri == '/debugmem/collect': body = gc.collect(2) elif request.uri == '/debugmem/count': counts = gc.get_count() body = { 'len_gc_objects': len(gc.get_objects()), 'len_gc_garbage': len(gc.garbage), 'gc_count0': counts[0], 'gc_count1': counts[1], 'gc_count2': counts[2], # Add the length of the most relevant globals 'NEGOTIATE_SERVER.queue': len(NEGOTIATE_SERVER.queue), 'NEGOTIATE_SERVER.known': len(NEGOTIATE_SERVER.known), 'NEGOTIATE_SERVER_BITTORRENT.peers': \ len(NEGOTIATE_SERVER_BITTORRENT.peers), 'NEGOTIATE_SERVER_SPEEDTEST.clients': \ len(NEGOTIATE_SERVER_SPEEDTEST.clients), 'POLLER.readset': len(POLLER.readset), 'POLLER.writeset': len(POLLER.writeset), 'LOG._queue': len(LOG._queue), 'CONFIG.conf': len(CONFIG.conf), 'NOTIFIER._timestamps': len(NOTIFIER._timestamps), 'NOTIFIER._subscribers': len(NOTIFIER._subscribers), 'NOTIFIER._tofire': len(NOTIFIER._tofire), } elif request.uri == '/debugmem/garbage': body = [str(obj) for obj in gc.garbage] elif request.uri == '/debugmem/saveall': enable = json.load(request.body) flags = gc.get_debug() if enable: flags |= gc.DEBUG_SAVEALL else: flags &= ~gc.DEBUG_SAVEALL gc.set_debug(flags) body = enable elif request.uri.startswith('/debugmem/types'): if request.uri.startswith('/debugmem/types/'): typename = request.uri.replace('/debugmem/types/', '') objects = objgraph.by_type(typename) body = [str(obj) for obj in objects] else: body = objgraph.typestats() else: body = None if body is not None: body = json.dumps(body, indent=4, sort_keys=True) response.compose(code="200", reason="Ok", body=body, mimetype="application/json") else: response.compose(code="404", reason="Not Found") stream.send_response(request, response)