From 6c1c0adadaf190e77dc017a8a40c90249f0a055b Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Wed, 25 May 2016 10:22:06 -0700 Subject: [PATCH] Remove unused trackrefs module --- CHANGES.txt | 3 + COPYRIGHT.txt | 9 --- supervisor/tests/trackrefs.py | 138 ---------------------------------- 3 files changed, 3 insertions(+), 147 deletions(-) delete mode 100644 supervisor/tests/trackrefs.py diff --git a/CHANGES.txt b/CHANGES.txt index 2681199c5..f1aa55e5e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -28,6 +28,9 @@ error condition occurs. Previous versions did not set the exit status so it was always zero. Patch by Luke Weber. +- Zope ``trackrefs``, a debugging tool that was included in the ``tests`` + directory but hadn't been used for years, has been removed. + 3.3.0 (2016-05-14) ------------------ diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index 382fc4d7a..20f4e35fc 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -9,15 +9,6 @@ Supervisor is Copyright (c) 2006-2015 Agendaless Consulting and Contributors. MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. -TrackRefs code Copyright (c) 2007 Zope Corporation and Contributors - - This software is subject to the provisions of the Zope Public License, - Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. - THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED - WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS - FOR A PARTICULAR PURPOSE. - medusa was (is?) Copyright (c) Sam Rushing. http_client.py code Copyright (c) by Daniel Krech, http://eikeon.com/. diff --git a/supervisor/tests/trackrefs.py b/supervisor/tests/trackrefs.py deleted file mode 100644 index c20231924..000000000 --- a/supervisor/tests/trackrefs.py +++ /dev/null @@ -1,138 +0,0 @@ -############################################################################## -# -# Copyright (c) 2007 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE -# -############################################################################## - -""" Code from the zope.testing module to help track down memory leaks - -TrackRefs works only in a python compiled with the --with-pydebug flag. -An example of how to use TrackRefs in a function is below. - -glen = 0 -rc = 0 - -def doit(): - newglen = gc.collect() - global glen - if newglen > glen: - print - print "-------------------------------------" - print "more garbage", newglen - glen - glen = newglen - print "-------------------------------------" - print - if refs: - newrc = sys.gettotalrefcount() - global rc - if newrc > rc: - refs.update() - refs.detailed_refcounts(newrc, rc) - rc = newrc -""" - -import sys -import gc - -class TrackRefs(object): - """Object to track reference counts across test runs.""" - - def __init__(self): - self.type2count = {} - self.type2all = {} - self.delta = None - self.n = 0 - self.update() - self.delta = None - - def update(self): - gc.collect() - obs = sys.getobjects(0) - type2count = {} - type2all = {} - n = 0 - for o in obs: - if type(o) is str and o == '': - # avoid dictionary madness - continue - - all = sys.getrefcount(o) - 3 - n += all - - typ = type(o) - try: - typ = o.__class__ - except Exception: - pass - - if typ in type2count: - type2count[typ] += 1 - type2all[typ] += all - else: - type2count[typ] = 1 - type2all[typ] = all - - ct = [( - type_or_class_title(t), - type2count[t] - self.type2count.get(t, 0), - type2all[t] - self.type2all.get(t, 0), - ) - for t in type2count.keys()] - ct += [( - type_or_class_title(t), - - self.type2count[t], - - self.type2all[t], - ) - for t in self.type2count.keys() - if t not in type2count] - ct.sort() - self.delta = ct - self.type2count = type2count - self.type2all = type2all - self.n = n - - - def output(self): - printed = False - s1 = s2 = 0 - for t, delta1, delta2 in self.delta: - if delta1 or delta2: - if not printed: - print ( - ' Leak details, changes in instances and refcounts' - ' by type/class:') - print(" %-55s %6s %6s" % ('type/class', 'insts', 'refs')) - print(" %-55s %6s %6s" % ('-' * 55, '-----', '----')) - printed = True - print(" %-55s %6d %6d" % (t, delta1, delta2)) - s1 += delta1 - s2 += delta2 - - if printed: - print(" %-55s %6s %6s" % ('-' * 55, '-----', '----')) - print(" %-55s %6s %6s" % ('total', s1, s2)) - - self.delta = None - - def detailed_refcounts(self, rc, prev): - """Report a change in reference counts, with extra detail.""" - print (" sum detail refcount=%-8d" - " sys refcount=%-8d" - " change=%-6d" - % (self.n, rc, rc - prev)) - self.output() - -def type_or_class_title(t): - module = getattr(t, '__module__', '__builtin__') - if module == '__builtin__': - return t.__name__ - return "%s.%s" % (module, t.__name__) -