private void process(final String msg) {
        final boolean isStart = msg.startsWith(">");
        if (isStart) {
            currStartTime = System.currentTimeMillis();
            currMsg = msg;
            totalMsgCount++;
            synchronized (collectedInfos) {
                collectedInfos.clear();
            }
            collectTraces.set(Log.isEnabled(Log.LogLevel.DEBUG));
        } else {
            collectTraces.set(false);
            final long duration = System.currentTimeMillis() - currStartTime;
            totalTime += duration;


            if (duration > 500) {
                final StringBuilder sb = new StringBuilder();
                synchronized (collectedInfos) {
                    sb.append("LooperLogger: long process time for ").append(currMsg).append(" (").append(duration).append("ms, ").append(getStats()).append("), ").append(collectedInfos.size()).append("traces:");
                    for (String info : collectedInfos) {
                        sb.append("\n   ").append(info);
                    }
                }
                Log.w(sb.toString());
            } else if (Log.isDebug() && totalMsgCount % 1000 == 0) {
                Log.d("LooperLogger: " + getStats());
            }
        }
    }
Helper class, gaining and logging statistics about a looper
main/src/main/java/cgeo/geocaching/LooperLogger.java