blob: fe10db7ee7f81e305771111977dd3dada6fe6c6e [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
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02007
Klement Sekeraebbaf552018-02-17 13:41:33 +01008tr = tracker.SummaryTracker()
9
10"""
11 Internal debug module
12
13 The module provides functions for debugging test framework
14"""
15
16
17def on_tear_down_class(cls):
18 gc.collect()
19 tr.print_diff()
20 objects = gc.get_objects()
21 counter = 0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 with open(cls.tempdir + "/python_objects.txt", "w") as f:
Klement Sekeraebbaf552018-02-17 13:41:33 +010023 interesting = [
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020024 o for o in objects if isinstance(o, (VppPapiProvider, vpp_papi.VPP))
25 ]
Klement Sekeraebbaf552018-02-17 13:41:33 +010026 del objects
27 gc.collect()
28 for o in interesting:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020029 objgraph.show_backrefs(
30 [o], max_depth=5, filename="%s/%s.png" % (cls.tempdir, counter)
31 )
Klement Sekeraebbaf552018-02-17 13:41:33 +010032 counter += 1
33 refs = gc.get_referrers(o)
34 pp = pprint.PrettyPrinter(indent=2)
35 f.write("%s\n" % pp.pformat(o))
36 for r in refs:
37 try:
38 f.write("%s\n" % pp.pformat(r))
39 except:
40 f.write("%s\n" % type(r))