<lambda>null1package leakcanary 2 3 import android.util.Log 4 import androidx.test.platform.app.InstrumentationRegistry 5 import java.io.File 6 import leakcanary.Profiler.runWithProfilerSampling 7 import org.junit.Ignore 8 import org.junit.Test 9 import shark.AndroidObjectInspectors 10 import shark.AndroidReferenceMatchers 11 import shark.HeapAnalyzer 12 import shark.KeyedWeakReferenceFinder 13 import shark.SharkLog 14 15 class ProfiledTest { 16 17 @Ignore 18 @Test fun analyzeLargeDump() { 19 profileAnalysis("large-dump.hprof") 20 } 21 22 private fun profileAnalysis(fileName: String) { 23 val instrumentation = InstrumentationRegistry.getInstrumentation() 24 val context = instrumentation.targetContext 25 26 val heapDumpFile = File(context.filesDir, "ProfiledTest.hprof") 27 context.assets.open(fileName) 28 .copyTo(heapDumpFile.outputStream()) 29 30 runWithProfilerSampling { 31 val analyzer = HeapAnalyzer { step -> Log.d("LeakCanary", step.name) } 32 val result = analyzer.analyze( 33 heapDumpFile = heapDumpFile, 34 leakingObjectFinder = KeyedWeakReferenceFinder, 35 referenceMatchers = AndroidReferenceMatchers.appDefaults, 36 objectInspectors = AndroidObjectInspectors.appDefaults, 37 computeRetainedHeapSize = true 38 ) 39 SharkLog.d { result.toString() } 40 } 41 } 42 } 43 44