All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.leakcanary.RepeatingScenario.kt Maven / Gradle / Ivy

There is a newer version: 3.0-alpha-8
Show newest version
package leakcanary

import shark.HeapDiff
import shark.ObjectGrowthDetector
import shark.RepeatingHeapGraphObjectGrowthDetector
import shark.RepeatingScenarioObjectGrowthDetector

/**
 * Creates a [RepeatingScenarioObjectGrowthDetector] suitable for junit based automated tests that
 * can dump the heap.
 *
 * @see [RepeatingScenarioObjectGrowthDetector.findRepeatedlyGrowingObjects]
 */
fun HeapDiff.Companion.repeatingDumpingTestScenario(
  objectGrowthDetector: ObjectGrowthDetector,
  heapDumpDirectoryProvider: HeapDumpDirectoryProvider,
  heapDumper: HeapDumper,
  heapDumpStorageStrategy: HeapDumpStorageStrategy,
): RepeatingScenarioObjectGrowthDetector {
  return RepeatingScenarioObjectGrowthDetector(
    heapGraphProvider = DumpingHeapGraphProvider(
      heapDumpFileProvider = DatetimeFormattedHeapDumpFileProvider(
        heapDumpDirectoryProvider = heapDumpDirectoryProvider,
        suffixProvider = {
              TestNameProvider.currentTestName()?.run {
                // JVM test method names can have spaces.
                val escapedMethodName = methodName.replace(' ', '-')
                "_${classSimpleName}-${escapedMethodName}"
              } ?: ""
            }
      ),
      heapDumper = heapDumper,
      heapDumpClosedListener = heapDumpStorageStrategy
    ),
    repeatingHeapGraphDetector = RepeatingHeapGraphObjectGrowthDetector(
      objectGrowthDetector = objectGrowthDetector,
      completionListener = heapDumpStorageStrategy
    ),
  )
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy