* @return true, if the queue is not emptied and there are events
* in it where the finalMoment is achieved.
*/
private boolean emptyQueue(long finalMoment)
{
StopWatch sw;
try
{
while( null != (sw = m_queue.poll(100, TimeUnit.MILLISECONDS)) )
{
if( sw.getCreationTime() > finalMoment )
{
// Return this one back in the queue; as it belongs to the
// next period already.
m_queue.addFirst(sw);
return true;
}
CollectedStatistics cs = m_stats.get(sw.getTag());
if( cs == null )
{
cs = new CollectedStatistics();
m_stats.put( sw.getTag(), cs );
}
cs.add( sw );
//
// Do the logging to the slowlog as well, if it's defined
// and we bypass the threshold.
//
// TODO: Using String.format to get the ISO date isn't very fast. Need to figure out a better method.
//
if( m_slowLogOn && m_slowLog != null )
{
Long threshold = m_slowThresholdMicros.get( sw.getTag() );
if( threshold != null && sw.getTimeMicros() > threshold )
{
m_slowLog.info( "{} {} \"{}\" \"{}\" {}", new Object[] {
String.format("%tFT%<tT.%<tL%<tz",new Date(sw.getCreationTime())),
saneDoubleToString( m_slowLogPercentile ),
sw.getTag(),
sw.getMessage() != null ? sw.getMessage() : "",
sw.getTimeMicros()/1000F } );
}
}
}
}
catch( InterruptedException e ) {} // Just return immediately