1 package leakcanary 2 3 import shark.HeapAnalysis 4 5 /** 6 * A [HeapAnalysisJob] represents a single prepared request to analyze the heap. It cannot be 7 * executed twice. 8 */ 9 interface HeapAnalysisJob { 10 11 /** 12 * In memory store, mutable and thread safe. This allows passing data to interceptors. 13 */ 14 val context: JobContext 15 16 /** 17 * true if [execute] has been called. It is an 18 * error to call [execute] more than once. 19 */ 20 val executed: Boolean 21 22 /** 23 * true of [cancel] has been called or if an [HeapAnalysisInterceptor] has returned 24 * [Result.Canceled] from [HeapAnalysisInterceptor.intercept]. 25 */ 26 val canceled: Boolean 27 28 /** 29 * Starts the analysis job immediately, and blocks until a result is available. 30 * 31 * @return Either [Result.Done] if the analysis was attempted or [Result.Canceled] 32 */ executenull33 fun execute(): Result 34 35 /** Cancels the job, if possible. Jobs that are already complete cannot be canceled. */ 36 fun cancel(cancelReason: String) 37 38 sealed class Result { 39 40 data class Done( 41 val analysis: HeapAnalysis, 42 /** 43 * The time spent stripping the hprof of any data if [HeapAnalysisConfig.stripHeapDump] is 44 * true, null otherwise. 45 */ 46 val stripHeapDumpDurationMillis: Long? = null 47 ) : Result() 48 49 data class Canceled(val cancelReason: String) : Result() 50 } 51 }