No, Python decorators do not allow you to control all the code without changing anything. You should still put your decorator everywhere (and essentially wrap each of your functions in a function that does the counting).
I’m not sure how much I understand your requirements (you don’t say whether you need code for production or testing, also the requirement “do not import anything” is strange: are all your classes in the package by default? Did you allow to use IDE and compiler?) but I think the easiest way would be to use a Javassist (the second link kindly provided by cschooley is a great introduction), but do not use the agent: use CtClass # write () instead in the instrument class files and save them to disk (maybe in custom for Aceh ant). Thus, the final assembly does not need any special configuration.
source share