Java, how to trace functions called

后端 未结 4 1051
执笔经年
执笔经年 2021-01-14 06:47

I want to trace the beginning [& ending] of functions called in Java, like the following code:

    public void foo() {
  System.out.println(\"begin of fo         


        
4条回答
  •  北海茫月
    2021-01-14 07:30

    The easiest approach is the one you've chose.

    An easy replacement for the System.out calls would be using a logging framework. Then you could switch the information on and off according to a selected "logging level"

    More sophisticated solutions would use aspect oriented programming techniques (provide by AspectJ, for instance), but this puts you on a steep learning curve.

    Maybe a tool-based a approach fits your needs: so called "profilers" can "instrument" your code and report exactly which method was called during a run.

提交回复
热议问题