From 4538896850ca71ae9c1d5c8827f8d418be67bdfd Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 15:56:43 +0530 Subject: [PATCH 1/8] Added object size to show_most_common_types --- objgraph.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/objgraph.py b/objgraph.py index 6c2c941..9b55815 100755 --- a/objgraph.py +++ b/objgraph.py @@ -184,7 +184,8 @@ def typestats(objects=None, shortnames=True, filter=None): if filter and not filter(o): continue n = typename(o) - stats[n] = stats.get(n, 0) + 1 + val = stats.get(n, (0, sys.getsizeof(o))) + stats[n] = (val[0] + 1, sys.getsizeof(o)) return stats finally: del objects # clear cyclic references to frame @@ -273,7 +274,7 @@ def show_most_common_types( filter=filter) width = max(len(name) for name, count in stats) for name, count in stats: - file.write('%-*s %i\n' % (width, name, count)) + file.write('%-*s - %i - %i - %i\n' % (width, name, count[0], count[1], count[0]*count[1])) def growth(limit=10, peak_stats={}, shortnames=True, filter=None): From 196d4c22f0cbdff00fa15c74a012602c42547ccc Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:09:43 +0530 Subject: [PATCH 2/8] Added object size to show_most_common_types --- objgraph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/objgraph.py b/objgraph.py index 9b55815..d8acce8 100755 --- a/objgraph.py +++ b/objgraph.py @@ -309,9 +309,9 @@ def growth(limit=10, peak_stats={}, shortnames=True, filter=None): deltas = {} for name, count in iteritems(stats): old_count = peak_stats.get(name, 0) - if count > old_count: - deltas[name] = count - old_count - peak_stats[name] = count + if count[0] > old_count: + deltas[name] = count[0] - old_count + peak_stats[name] = count[0] deltas = sorted(deltas.items(), key=operator.itemgetter(1), reverse=True) if limit: From 628b51ff652541a2c51061e8a6e685d3a3766935 Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:16:22 +0530 Subject: [PATCH 3/8] Added object size to show_most_common_types --- objgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objgraph.py b/objgraph.py index d8acce8..3198def 100755 --- a/objgraph.py +++ b/objgraph.py @@ -359,7 +359,7 @@ def show_growth(limit=10, peak_stats=None, shortnames=True, file=None, file = sys.stdout width = max(len(name) for name, _, _ in result) for name, count, delta in result: - file.write('%-*s%9d %+9d\n' % (width, name, count, delta)) + file.write('%-*s%9d %+9d\n' % (width, name, count[0], delta)) def get_new_ids(skip_update=False, limit=10, sortby='deltas', From a14b8d71e149e1be145ca0e6e437cb281eccc82d Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:22:03 +0530 Subject: [PATCH 4/8] Added object size to show_most_common_types --- tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 27a325a..3de280f 100755 --- a/tests.py +++ b/tests.py @@ -292,7 +292,7 @@ class TypestatsTest(GarbageCollectedMixin, unittest.TestCase): def test_long_type_names(self): x = type('MyClass', (), {'__module__': 'mymodule'})() # noqa stats = objgraph.typestats(shortnames=False) - self.assertEqual(1, stats['mymodule.MyClass']) + self.assertEqual(1, stats['mymodule.MyClass'][0]) def test_no_new_reference_cycles(self): # Similar to https://github.com/mgedmin/objgraph/pull/22 but for @@ -315,7 +315,7 @@ def test_without_filter(self): x.magic_attr = True y.magic_attr = False stats = objgraph.typestats(shortnames=False) - self.assertEqual(2, stats['mymodule.MyClass']) + self.assertEqual(2, stats['mymodule.MyClass'][0]) def test_with_filter(self): MyClass = type('MyClass', (), {'__module__': 'mymodule'}) # noqa @@ -325,7 +325,7 @@ def test_with_filter(self): stats = objgraph.typestats( shortnames=False, filter=lambda e: isinstance(e, MyClass) and e.magic_attr) - self.assertEqual(1, stats['mymodule.MyClass']) + self.assertEqual(1, stats['mymodule.MyClass'][0]) class GrowthTest(GarbageCollectedMixin, unittest.TestCase): From bcd6cd29054e356b0f2640d86092d2ac7c93e61e Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:26:30 +0530 Subject: [PATCH 5/8] Added object size to show_most_common_types --- objgraph.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/objgraph.py b/objgraph.py index 3198def..b531a59 100755 --- a/objgraph.py +++ b/objgraph.py @@ -274,7 +274,8 @@ def show_most_common_types( filter=filter) width = max(len(name) for name, count in stats) for name, count in stats: - file.write('%-*s - %i - %i - %i\n' % (width, name, count[0], count[1], count[0]*count[1])) + file.write('%-*s - %i - %i - %i\n' % + (width, name, count[0], count[1], count[0]*count[1])) def growth(limit=10, peak_stats={}, shortnames=True, filter=None): From 0cbc7f65da1ad7139c0bca4bc5e04d0a184e9b74 Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:30:27 +0530 Subject: [PATCH 6/8] Added object size to show_most_common_types --- objgraph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/objgraph.py b/objgraph.py index b531a59..08c7832 100755 --- a/objgraph.py +++ b/objgraph.py @@ -274,8 +274,8 @@ def show_most_common_types( filter=filter) width = max(len(name) for name, count in stats) for name, count in stats: - file.write('%-*s - %i - %i - %i\n' % - (width, name, count[0], count[1], count[0]*count[1])) + file.write('%-*s - %i - %i - %i\n' % + (width, name, count[0], count[1], count[0]*count[1])) def growth(limit=10, peak_stats={}, shortnames=True, filter=None): From fb189f27e74609461c67dfbdc0f48c48e161f1db Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:34:07 +0530 Subject: [PATCH 7/8] Added object size to show_most_common_types --- objgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objgraph.py b/objgraph.py index 08c7832..f438b27 100755 --- a/objgraph.py +++ b/objgraph.py @@ -275,7 +275,7 @@ def show_most_common_types( width = max(len(name) for name, count in stats) for name, count in stats: file.write('%-*s - %i - %i - %i\n' % - (width, name, count[0], count[1], count[0]*count[1])) + (width, name, count[0], count[1], count[0]*count[1])) def growth(limit=10, peak_stats={}, shortnames=True, filter=None): From 929c7bf71ab82cb55dd6fa24cc0e7e5d779b9435 Mon Sep 17 00:00:00 2001 From: Salil GK Date: Fri, 5 Mar 2021 16:37:56 +0530 Subject: [PATCH 8/8] Added object size to show_most_common_types --- objgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objgraph.py b/objgraph.py index f438b27..bc03b6c 100755 --- a/objgraph.py +++ b/objgraph.py @@ -275,7 +275,7 @@ def show_most_common_types( width = max(len(name) for name, count in stats) for name, count in stats: file.write('%-*s - %i - %i - %i\n' % - (width, name, count[0], count[1], count[0]*count[1])) + (width, name, count[0], count[1], count[0]*count[1])) def growth(limit=10, peak_stats={}, shortnames=True, filter=None):