0

I am looking to automatically instrument all bytecode that is executed from my initial Python script.

For instance, I'll have a directory setup like this:

+ main.py
+ file1.py
+----dir1/dir1_file2.py
+----dir1/dir1_file3.py

I've been looking over the equip package and it seems to fit my needs, however I am struggling to get all my bytecode files to be instrumented.

This example specifically seems to be what I need to do, but I am not certain the best way to get it to 'follow' the links.

For instance, if I have a class in dir1/dir1_file2.py that is imported into my main.py, how can I get that bytecode output instrumented? Do I need to essentially run a loop over all *.pyc files recursively in my directory structure, or is there a way to get it to follow the actions of the program?


Edit: I am specifically looking to instrument the code so that I can calculate metrics such as branch coverage, minimal CFGs, and so on. This is going to lead towards some software testing.

erik
  • 3,810
  • 6
  • 32
  • 63
  • Are you talking about debugging and/or profiling your code? What is the role of the bytecode in your problem? Or in other words: Please explain the root problem you are trying to solve with this! – Klaus D. May 31 '16 at 03:01
  • Still very vague. You are looking for test coverage reports? – Klaus D. May 31 '16 at 03:15
  • For starters, yes. To make the question easier just consider that I'm looking to do branch coverage of my code. (I'm going to significantly expand it beyond that point...I just need help figuring out *how* to instrument it) – erik May 31 '16 at 13:22
  • 1
    It might be helpful if you define what "instrument" means in your context. Instrumentation in development is a rather generic term, that refers to a set of different techniques. – Klaus D. May 31 '16 at 13:28
  • What I am trying to do is separate from what I am asking. All I want to do is insert statements into bytecode that I can act upon, where the bytecode can comprise several files in different directories. – erik May 31 '16 at 13:40
  • Possible duplicate of [Python memory debugging with GDB](http://stackoverflow.com/questions/273043/python-memory-debugging-with-gdb) – Paul Sweatte Aug 31 '16 at 19:31
  • I am looking for exactly the same thing. Did you come up with a solution or did you just do the recursive way? – Marco May 22 '20 at 10:14
  • Unfortunately no. Dropped the project as well so I never dug deeper into it, sorry! – erik May 26 '20 at 16:15

0 Answers0