Merge "Do not hold synchronization locks if tracing is not enabled" into ub-launcher3-master
This commit is contained in:
commit
5115de8415
1 file changed
+32
-26
@@ -39,35 +39,39 @@ public class TraceHelper {
|
||||
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);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user