<lambda>null1 package shark
2
3 import java.util.Locale
4
5 /**
6 * Reports progress from the [HeapAnalyzer] as they occur, as [Step] values.
7 *
8 * This is a functional interface with which you can create a [OnAnalysisProgressListener] from a lambda.
9 */
10 fun interface OnAnalysisProgressListener {
11
12 // These steps are defined in the order in which they occur.
13 enum class Step {
14 PARSING_HEAP_DUMP,
15 EXTRACTING_METADATA,
16 FINDING_RETAINED_OBJECTS,
17 FINDING_PATHS_TO_RETAINED_OBJECTS,
18 FINDING_DOMINATORS,
19 INSPECTING_OBJECTS,
20 COMPUTING_NATIVE_RETAINED_SIZE,
21 COMPUTING_RETAINED_SIZE,
22 BUILDING_LEAK_TRACES,
23 REPORTING_HEAP_ANALYSIS;
24
25 val humanReadableName: String
26
27 init {
28 val lowercaseName = name.replace("_", " ")
29 .toLowerCase(Locale.US)
30 humanReadableName =
31 lowercaseName.substring(0, 1).toUpperCase(Locale.US) + lowercaseName.substring(1)
32 }
33 }
34
35 fun onAnalysisProgress(step: Step)
36
37 companion object {
38
39 /**
40 * A no-op [OnAnalysisProgressListener]
41 */
42 val NO_OP = OnAnalysisProgressListener {}
43
44 /**
45 * Utility function to create a [OnAnalysisProgressListener] from the passed in [block] lambda
46 * instead of using the anonymous `object : OnAnalysisProgressListener` syntax.
47 *
48 * Usage:
49 *
50 * ```kotlin
51 * val listener = OnAnalysisProgressListener {
52 *
53 * }
54 * ```
55 */
56 inline operator fun invoke(crossinline block: (Step) -> Unit): OnAnalysisProgressListener =
57 OnAnalysisProgressListener { step -> block(step) }
58 }
59 }
60