Debug tips

1 add log in third party code

you can create the same class with same package in your source code, then copy it's source to your class, and add log as you like, then compile it and run it, Tomcat will first load your modified class rather than the origin class which is in third party jar file.

2 run the suspicious code multi times to enlarge the different

sometime, the same statement run in one environment is less slower than run in another environment. we can run them in debug environment, but hardly compare them manually especially in debug environment. And no JProfile help, then we can using a For loop to run the statement multi times, e.g. 1000 times, then if in one environment it cost 1.5s, other cost 10s, it's easy for feel the difference.

Another reason for run the suspicious code multi times is to find the sub statement which cause downgrade.

e.g. now we know method A consume 1ms in one environment, and 10ms in other environment. And A contains statement A1-A5, we need deep into these A1-A5 to check which one cause downgrade again. then we can first try run A1 100 times in two environment, other code are same, then run A2 100 times and so on to find is there huge diffierence in two environment, for example, if we run A3 100 times and other code are same, then one environment is 70ms and 1000ms in another one. we can think A3 cause downgrade and deep into A3 again.

there are some limitation in this way: the method must be 1. can be run many time, 2. no side effect after running many times, 3. every time running consume same time, running same logic in the method.

Solving problem need try different ways and sometimes need some lucky, don't give up too early!

猜你喜欢

转载自andyjojo.iteye.com/blog/2285539