How to debug a battery issue? I have HTC Sensation 4G. I have a very peculiar issue with the battery. I've been using the phone for just over one year now. There are some periods (about 7 to 15 days) when battery performance is absolutely fine. 

But then after certain days of good performance battery starts behaving weirdly: Phone gets switched off even at over 60% battery. Restarting it shows about 5% battery, again switches off, restart shows around 20% etc. 

So I guessed there is some calibration issue. Taking out the battery at the time of this erratic behavior makes it work fine for a little while (half an hour to a couple of hours) then again the stupidity starts. I have tried draining the battery to 0% and then a full charge, tried various usage models (not using wifi, disabling animations to reduce usage etc.) nothing seems to work. 

I can't properly debug this issue properly as connecting to computer starts charging and when its charging there are no such issues. This is REALLY frustrating, Any one has any idea how to debug it? 

(I have come to know that certain batch of HTC sensation has this issue, not everyone has experienced similar problems but there are people and no one has been able to point me in the right direction)
I have diagnosed several battery related anomalies with a combination of two apps: one called Diagnosis and the other GSam Battery Monitor Pro.  GSam isn't as robust but it offers a greater filtering options to sort the culprits by CPU usage, power usage, memory usage....  In every case it turned out to be a problem with an app or a setting or my current ROM but those apps helped me track down the problem.  

You may also want to check your device's logs for clues.  You can use aLogrec to record your logcat, then note the time of a spontaneous shutdown then check the log to see what events lead up to it.  I can barely understand what is contained in my logcat but this forum post may help you.