blob: 46b234d29b0adb28faf865a71e1f4fb25eff1292 [file] [log] [blame]
package com.airbnb.lottie;
import android.support.annotation.RestrictTo;
import android.support.v4.os.TraceCompat;
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class L {
public static boolean DBG = false;
public static final String TAG = "LOTTIE";
private static final int MAX_DEPTH = 20;
private static boolean traceEnabled = false;
private static String[] sections;
private static long[] startTimeNs;
private static int traceDepth = 0;
private static int depthPastMaxDepth = 0;
public static void setTraceEnabled(boolean enabled) {
if (traceEnabled == enabled) {
return;
}
traceEnabled = enabled;
if (traceEnabled) {
sections = new String[MAX_DEPTH];
startTimeNs = new long[MAX_DEPTH];
}
}
public static void beginSection(String section) {
if (!traceEnabled) {
return;
}
if (traceDepth == MAX_DEPTH) {
depthPastMaxDepth++;
return;
}
sections[traceDepth] = section;
startTimeNs[traceDepth] = System.nanoTime();
TraceCompat.beginSection(section);
traceDepth++;
}
public static float endSection(String section) {
if (depthPastMaxDepth > 0) {
depthPastMaxDepth--;
return 0;
}
if (!traceEnabled) {
return 0;
}
traceDepth--;
if (traceDepth == -1) {
throw new IllegalStateException("Can't end trace section. There are none.");
}
if (!section.equals(sections[traceDepth])) {
throw new IllegalStateException("Unbalanced trace call " + section +
". Expected " + sections[traceDepth] + ".");
}
TraceCompat.endSection();
return (System.nanoTime() - startTimeNs[traceDepth]) / 1000000f;
}
}