-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2679 from square/py/fix_android_growth_crash
Fix warmup for Android heap growth
- Loading branch information
Showing
10 changed files
with
130 additions
and
24 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
8 changes: 8 additions & 0 deletions
8
leakcanary/leakcanary-android-test/src/androidTest/AndroidManifest.xml
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:name="androidx.multidex.MultiDexApplication" | ||
> | ||
</application> | ||
</manifest> |
38 changes: 38 additions & 0 deletions
38
...ary-android-test/src/androidTest/java/leakcanary/RepeatingAndroidInProcessScenarioTest.kt
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,38 @@ | ||
package leakcanary | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import shark.ObjectGrowthDetector | ||
import shark.RepeatingScenarioObjectGrowthDetector.Companion.DEFAULT_MAX_HEAP_DUMPS | ||
import shark.RepeatingScenarioObjectGrowthDetector.Companion.IN_PROCESS_SCENARIO_LOOPS_PER_DUMP | ||
import shark.forAndroidHeap | ||
|
||
class RepeatingAndroidInProcessScenarioTest { | ||
|
||
private val growingList = mutableListOf<String>() | ||
|
||
@Test fun failing_scenario_iterates_to_max_heap_dumps_times_loops_per_dump() { | ||
val detector = ObjectGrowthDetector.forAndroidHeap() | ||
.repeatingAndroidInProcessScenario() | ||
var iteration = 0 | ||
detector.findRepeatedlyGrowingObjects { | ||
growingList += "growth $iteration" | ||
iteration++ | ||
} | ||
|
||
assertThat(iteration).isEqualTo(DEFAULT_MAX_HEAP_DUMPS * IN_PROCESS_SCENARIO_LOOPS_PER_DUMP) | ||
} | ||
|
||
@Test fun failing_scenario_finds_expected_growing_object() { | ||
val detector = ObjectGrowthDetector.forAndroidHeap() | ||
.repeatingAndroidInProcessScenario() | ||
var iteration = 0 | ||
val heapGrowth = detector.findRepeatedlyGrowingObjects { | ||
growingList += "growth $iteration" | ||
iteration++ | ||
} | ||
|
||
val growingObject = heapGrowth.growingObjects.single() | ||
assertThat(growingObject.name).startsWith("INSTANCE_FIELD RepeatingAndroidInProcessScenarioTest.growingList") | ||
} | ||
} |
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
28 changes: 21 additions & 7 deletions
28
leakcanary/leakcanary-core/src/main/java/leakcanary/ObjectGrowthWarmupHeapDumper.kt
Large diffs are not rendered by default.
Oops, something went wrong.
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