Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

When tuning performance in a web application, I am looking for good and light-weight performance profiling tools to measure the execution time for each method. I know that the easiest profiling method is to log the start time and end time for each method, but I see more and more people using AOP to profile (add @profiled before each method).

What's the benefit of AOP profiling compared to the common "log" way?

Thanks in advance

Vance

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

There are three advantages:

  1. You don't have code duplication. Otherwise you'd have startTime := now() and log('method xyz took', now() - startTime, 'seconds'). Also, if you rename method xyz, you may have to update you log statements (unless you can find out the name of the currently called method in Java).
  2. You have centralized control. The methods may be marked for profiling (although I don't think that's a clean solution), but ultimately, you can decide, that you don't want to profile them or that you only want to profile specific classes.
  3. You have separation of concerns. A method's purpose is to carry out the task it is intended to and not to profile itself.
share|improve this answer
    
Does the aop will generate more overhead than the common log way? I mean if the aop profiling codes itself consume more time than the common log code, it won't be a good choice. –  Vance Jun 21 '11 at 11:28
1  
@Vance: To my knowledge in AspectJ uses compile time and bytecode weaving, so there should be no difference (it is as if the aspect code were written right there). Also, profiling always induces a performance hit. Measuring time does, logging the information does and so on. You wouldn't wanna ship a software that profiles itself. Therefore the possibility to turn of all profiling at once is important (see point 2). –  back2dos Jun 21 '11 at 12:16
    
@bac2dos: Thank you for the answer. Will try the AspectJ in my codes for the profiling purpose. –  Vance Jun 21 '11 at 14:51
add comment

When tuning performance in a web application ... easiest profiling method is to log the start time and end time for each method

Hold it right there :-)

Tuning (i.e. finding ways to make it faster) and measuring (seeing how long things take) are not the same thing.

What measuring is good for is quantifying the improvement you get after fixing something.

For finding out what to fix, the simplest technique is sampling the stack, because any line of code costing X% of time is on the stack during that time, whether it is a tight loop, a call for I/O, or a mid-level function/method call.

What's more, if X% is big enough to bother with, not many samples are needed to find it. (Notice, I said find, not measure.) As soon as any line of code appears a second time, if you can optimize it, you will get a good speedup, guaranteed.

The worse the problem is, the fewer samples you need. In the limit, you can diagnose an infinite loop in one sample.

There's plenty more discussion of this.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.