blob: 2cbee27ec819d86bacce8e88483fef8f00c21dc9 [file] [log] [blame]
Klement Sekeraebbaf552018-02-17 13:41:33 +01001import gc
2import pprint
3import vpp_papi
4from vpp_papi_provider import VppPapiProvider
5import objgraph
6from pympler import tracker
7tr = tracker.SummaryTracker()
8
9"""
10 Internal debug module
11
12 The module provides functions for debugging test framework
13"""
14
15
16def on_tear_down_class(cls):
17 gc.collect()
18 tr.print_diff()
19 objects = gc.get_objects()
20 counter = 0
21 with open(cls.tempdir + '/python_objects.txt', 'w') as f:
22 interesting = [
23 o for o in objects
24 if isinstance(o, (VppPapiProvider, vpp_papi.VPP))]
25 del objects
26 gc.collect()
27 for o in interesting:
28 objgraph.show_backrefs([o], max_depth=5,
29 filename="%s/%s.png" %
30 (cls.tempdir, counter))
31 counter += 1
32 refs = gc.get_referrers(o)
33 pp = pprint.PrettyPrinter(indent=2)
34 f.write("%s\n" % pp.pformat(o))
35 for r in refs:
36 try:
37 f.write("%s\n" % pp.pformat(r))
38 except:
39 f.write("%s\n" % type(r))