Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more systrace markers and made LottieTrace multi-thread compati…
…ble (#2275)
- Loading branch information
Showing
5 changed files
with
79 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lottie/src/main/java/com/airbnb/lottie/utils/LottieTrace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.airbnb.lottie.utils; | ||
|
||
import androidx.core.os.TraceCompat; | ||
|
||
public class LottieTrace { | ||
private static final int MAX_DEPTH = 20; | ||
|
||
private final String[] sections = new String[MAX_DEPTH]; | ||
private final long[] startTimeNs = new long[MAX_DEPTH]; | ||
private int traceDepth = 0; | ||
private int depthPastMaxDepth = 0; | ||
|
||
public void beginSection(String section) { | ||
if (traceDepth == MAX_DEPTH) { | ||
depthPastMaxDepth++; | ||
return; | ||
} | ||
sections[traceDepth] = section; | ||
startTimeNs[traceDepth] = System.nanoTime(); | ||
//noinspection deprecation | ||
TraceCompat.beginSection(section); | ||
traceDepth++; | ||
} | ||
|
||
public float endSection(String section) { | ||
if (depthPastMaxDepth > 0) { | ||
depthPastMaxDepth--; | ||
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] + "."); | ||
} | ||
//noinspection deprecation | ||
TraceCompat.endSection(); | ||
return (System.nanoTime() - startTimeNs[traceDepth]) / 1000000f; | ||
} | ||
} |