diff --git a/src/com/android/launcher3/util/TraceHelper.java b/src/com/android/launcher3/util/TraceHelper.java index a321bcc205..4fea2e92ae 100644 --- a/src/com/android/launcher3/util/TraceHelper.java +++ b/src/com/android/launcher3/util/TraceHelper.java @@ -39,35 +39,39 @@ public class TraceHelper { private static final boolean SYSTEM_TRACE = false; private static final ArrayMap sUpTimes = ENABLED ? new ArrayMap<>() : null; - public static synchronized void beginSection(String sectionName) { + public static void beginSection(String sectionName) { if (ENABLED) { - MutableLong time = sUpTimes.get(sectionName); - if (time == null) { - time = new MutableLong(isLoggable(sectionName, VERBOSE) ? 0 : -1); - sUpTimes.put(sectionName, time); - } - if (time.value >= 0) { - if (SYSTEM_TRACE) { - Trace.beginSection(sectionName); + synchronized (sUpTimes) { + MutableLong time = sUpTimes.get(sectionName); + if (time == null) { + time = new MutableLong(isLoggable(sectionName, VERBOSE) ? 0 : -1); + sUpTimes.put(sectionName, time); + } + if (time.value >= 0) { + if (SYSTEM_TRACE) { + Trace.beginSection(sectionName); + } + time.value = SystemClock.uptimeMillis(); } - time.value = SystemClock.uptimeMillis(); } } } - public static synchronized void partitionSection(String sectionName, String partition) { + public static void partitionSection(String sectionName, String partition) { if (ENABLED) { - MutableLong time = sUpTimes.get(sectionName); - if (time != null && time.value >= 0) { + synchronized (sUpTimes) { + MutableLong time = sUpTimes.get(sectionName); + if (time != null && time.value >= 0) { - if (SYSTEM_TRACE) { - Trace.endSection(); - Trace.beginSection(sectionName); + if (SYSTEM_TRACE) { + Trace.endSection(); + Trace.beginSection(sectionName); + } + + long now = SystemClock.uptimeMillis(); + Log.d(sectionName, partition + " : " + (now - time.value)); + time.value = now; } - - long now = SystemClock.uptimeMillis(); - Log.d(sectionName, partition + " : " + (now - time.value)); - time.value = now; } } } @@ -78,14 +82,16 @@ public class TraceHelper { } } - public static synchronized void endSection(String sectionName, String msg) { + public static void endSection(String sectionName, String msg) { if (ENABLED) { - MutableLong time = sUpTimes.get(sectionName); - if (time != null && time.value >= 0) { - if (SYSTEM_TRACE) { - Trace.endSection(); + synchronized (sUpTimes) { + MutableLong time = sUpTimes.get(sectionName); + if (time != null && time.value >= 0) { + if (SYSTEM_TRACE) { + Trace.endSection(); + } + Log.d(sectionName, msg + " : " + (SystemClock.uptimeMillis() - time.value)); } - Log.d(sectionName, msg + " : " + (SystemClock.uptimeMillis() - time.value)); } } }