main

square/leakcanary

Last updated at: 29/12/2023 09:51

StripHprofCommand.kt

TLDR

This file contains the StripHprofCommand class, which is a command-line interface command that replaces all primitive arrays from a provided heap dump file with arrays of zeroes. It then generates a new "-stripped.hprof" file.

Classes

StripHprofCommand

The StripHprofCommand class is a command-line interface command that extends the CliktCommand class. It replaces all primitive arrays from a provided heap dump file with arrays of zeroes and generates a new "-stripped.hprof" file.

Methods

This file does not contain any additional methods.

package shark

import com.github.ajalt.clikt.core.CliktCommand
import shark.SharkCliCommand.Companion.retrieveHeapDumpFile
import shark.SharkCliCommand.Companion.sharkCliParams

class StripHprofCommand : CliktCommand(
  name = "strip-hprof",
  help = "Replace all primitive arrays from the provided heap dump with arrays of zeroes and generate a new \"-stripped.hprof\" file."
) {

  override fun run() {
    val heapDumpFile = retrieveHeapDumpFile(context.sharkCliParams)
    SharkLog.d { "Stripping primitive arrays in heap dump $heapDumpFile" }
    val stripper = HprofPrimitiveArrayStripper()
    val outputFile = stripper.stripPrimitiveArrays(heapDumpFile)
    echo("Created hprof with stripped primitive arrays to $outputFile")
  }
}