Do not hold synchronization locks if tracing is not enabled
Change-Id: Ia17e2269d088da472dce2e248fc9f85877be5d77
diff --git a/src/com/android/launcher3/util/TraceHelper.java b/src/com/android/launcher3/util/TraceHelper.java
index a321bcc..4fea2e9 100644
--- a/src/com/android/launcher3/util/TraceHelper.java
+++ b/src/com/android/launcher3/util/TraceHelper.java
@@ -39,35 +39,39 @@
private static final boolean SYSTEM_TRACE = false;
private static final ArrayMap<String, MutableLong> 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);
}
- time.value = SystemClock.uptimeMillis();
+ if (time.value >= 0) {
+ if (SYSTEM_TRACE) {
+ Trace.beginSection(sectionName);
+ }
+ 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 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));
}
}
}