MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / actionListobj

Method actionListobj

plugins/Stats/StatsPlugin.py:415–480  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

413
414 @helper.encodeResponse
415 def actionListobj(self):
416
417 import gc
418 import sys
419
420 self.sendHeader()
421
422 if "Multiuser" in PluginManager.plugin_manager.plugin_names and not config.multiuser_local:
423 yield "This function is disabled on this proxy"
424 return
425
426 # No more if not in debug mode
427 if not config.debug:
428 yield "Not in debug mode"
429 return
430
431 type_filter = self.get.get("type")
432
433 yield """
434 <style>
435 * { font-family: monospace; white-space: pre }
436 table * { text-align: right; padding: 0px 10px }
437 </style>
438 """
439
440 yield "Listing all %s objects in memory...<br>" % html.escape(type_filter)
441
442 ref_count = {}
443 objs = gc.get_objects()
444 for obj in objs:
445 obj_type = str(type(obj))
446 if obj_type != type_filter:
447 continue
448 refs = [
449 ref for ref in gc.get_referrers(obj)
450 if hasattr(ref, "__class__") and
451 ref.__class__.__name__ not in ["list", "dict", "function", "type", "frame", "WeakSet", "tuple"]
452 ]
453 if not refs:
454 continue
455 try:
456 yield "%.1fkb <span title=\"%s\">%s</span>... " % (
457 float(sys.getsizeof(obj)) / 1024, html.escape(str(obj)), html.escape(str(obj)[0:100].ljust(100))
458 )
459 except:
460 continue
461 for ref in refs:
462 yield " ["
463 if "object at" in str(ref) or len(str(ref)) > 100:
464 yield str(ref.__class__.__name__)
465 else:
466 yield str(ref.__class__.__name__) + ":" + html.escape(str(ref))
467 yield "] "
468 ref_type = ref.__class__.__name__
469 if ref_type not in ref_count:
470 ref_count[ref_type] = [0, 0]
471 ref_count[ref_type][0] += 1 # Count
472 ref_count[ref_type][1] += float(sys.getsizeof(obj)) / 1024 # Size

Callers

nothing calls this directly

Calls 5

sumFunction · 0.85
sendHeaderMethod · 0.80
valuesMethod · 0.80
itemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected