Klement Sekera | ebbaf55 | 2018-02-17 13:41:33 +0100 | [diff] [blame] | 1 | import gc |
| 2 | import pprint |
| 3 | import vpp_papi |
| 4 | from vpp_papi_provider import VppPapiProvider |
| 5 | import objgraph |
| 6 | from pympler import tracker |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 7 | |
Klement Sekera | ebbaf55 | 2018-02-17 13:41:33 +0100 | [diff] [blame] | 8 | tr = tracker.SummaryTracker() |
| 9 | |
| 10 | """ |
| 11 | Internal debug module |
| 12 | |
| 13 | The module provides functions for debugging test framework |
| 14 | """ |
| 15 | |
| 16 | |
| 17 | def on_tear_down_class(cls): |
| 18 | gc.collect() |
| 19 | tr.print_diff() |
| 20 | objects = gc.get_objects() |
| 21 | counter = 0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 22 | with open(cls.tempdir + "/python_objects.txt", "w") as f: |
Klement Sekera | ebbaf55 | 2018-02-17 13:41:33 +0100 | [diff] [blame] | 23 | interesting = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 24 | o for o in objects if isinstance(o, (VppPapiProvider, vpp_papi.VPP)) |
| 25 | ] |
Klement Sekera | ebbaf55 | 2018-02-17 13:41:33 +0100 | [diff] [blame] | 26 | del objects |
| 27 | gc.collect() |
| 28 | for o in interesting: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 29 | objgraph.show_backrefs( |
| 30 | [o], max_depth=5, filename="%s/%s.png" % (cls.tempdir, counter) |
| 31 | ) |
Klement Sekera | ebbaf55 | 2018-02-17 13:41:33 +0100 | [diff] [blame] | 32 | 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)) |