I’m looking for a feature or software, who will allow me to easily profile my method execution time and choose what to profile by package filter.
I know, it’s profiler 101.
I use the TPTP profiler. But I’m not happy with it. To be frank I just don’t understand how it works, and when I profile my application (launch the server in profiling mode), it takes forever to do nothing. (well, not what I expect: a simple output of execution time)
So I do the profiling myself with system time (add a line at beginning and at ending of methods). It’s not so bad.
My question is : I want to measure system time before and after a method call with Spring AOP, can you give me direction? It’s a good / bad idea ? The code base is pretty large, and we don’t have many unit tests, can’t it be “dangerous” ?
I’m not asking for code, I think I can do it myself with this kind of link :
http://static.springsource.org/spring/docs/2.5.x/reference/aop.html
But if you have a nice tutorial ( never done AOP before, just know the concept), I take it.
There is a built in support for that in Spring.
I tried to look for tutorial but surprisingly I have not found one so I will try to explain it here. (EDIT: I added this example to my blog here)
Basically what you need is to extend CustomizableTraceInterceptor class like this:
This class wraps around your beans and outputs method call information, including parameters, return values and execution time to a log. By changing
writeToLog()method you control where you want to output the data and at what severity.Now you need some XML to actually select which beans you are going to wrap:
Basically you define the beans you want to wrap with a wildcard in “beanNames” and “order” controls the ordering of wrapping – if you don’t have other AOP classes you can remove it. You can also change the format of output if you change enterMessage and exitMessage properties.
That should be enough to get you started. If you need clarifications don’t hesitate to ask.