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 |
| 7 | tr = tracker.SummaryTracker() |
| 8 | |
| 9 | """ |
| 10 | Internal debug module |
| 11 | |
| 12 | The module provides functions for debugging test framework |
| 13 | """ |
| 14 | |
| 15 | |
| 16 | def 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)) |