How to find out how many times a particular method is called in java

Is there a way to find out how many times an instance of a class called its member method.

I think (not sure), one way is to have a dedicated member variable for the method, but that will not be possible if we have so many methods.

For instance:

class A{
        public void someMethod(){   
        }
}

and I have an example:

A a = new A();

So, I want to know how many times I acalled someMethodin the program. We can have any number of methods.

+3
source share
7 answers

, , . AspectJ, . Spring AOP, , .

+5

, , , :

  • , ; , ,
  • - , , , " "; - . (new Exception()). getStackTrace() - , .
  • ,
  • ASM .
  • Java " " ; - , , , , , - , , .
+4

, . NetBeans YourKit ..

+2
+1

JProbe, , .

, MAT , , .

+1

java.lang.reflect.Proxy. " Java". ' .

+1

Source: https://habr.com/ru/post/1729899/


All Articles