Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2291,15 +2291,16 @@ private[spark] object Utils extends Logging with SparkClassUtils {
def getHeapHistogram(): Array[String] = {
// From Java 9+, we can use 'ProcessHandle.current().pid()'
val pid = getProcessName().split("@").head
val builder = new ProcessBuilder("jmap", "-histo:live", pid)
builder.redirectErrorStream(true)
val jmap = System.getProperty("java.home") + "/bin/jmap"
val builder = new ProcessBuilder(jmap, "-histo:live", pid)
val p = builder.start()
val r = new BufferedReader(new InputStreamReader(p.getInputStream()))
val rows = ArrayBuffer.empty[String]
var line = ""
while (line != null) {
if (line.nonEmpty) rows += line
line = r.readLine()
Utils.tryWithResource(new BufferedReader(new InputStreamReader(p.getInputStream()))) { r =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mridulm . I'll make another PR to limit the number of results and to address your comment for readLine parts. In this PR, I just wrapped with tryWithResource.

var line = ""
while (line != null) {
if (line.nonEmpty) rows += line
line = r.readLine()
}
}
rows.toArray
}
Expand Down