6760477: Update SA to include stack traces in the heap dump
Update SA to include HPROF_TRACE and HPROF_FRAME records in the heap dump Reviewed-by: dsamersoff
This commit is contained in:
parent
a449b10079
commit
5a215fce15
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -35,6 +35,7 @@ package jdk.test.lib.hprof.parser;
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import jdk.test.lib.hprof.model.ArrayTypeCodes;
|
||||
import jdk.test.lib.hprof.model.*;
|
||||
|
||||
@ -357,6 +358,22 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
public String printStackTraces() {
|
||||
StringBuffer output = new StringBuffer();
|
||||
for (Map.Entry<Integer, StackTrace> entry : stackTraces.entrySet()) {
|
||||
StackFrame[] frames = entry.getValue().getFrames();
|
||||
output.append("SerialNo " + entry.getKey() + "\n");
|
||||
for (int i = 0; i < frames.length; i++) {
|
||||
output.append(" " + frames[i].getClassName() + "." + frames[i].getMethodName()
|
||||
+ frames[i].getMethodSignature() + " (" + frames[i].getSourceFileName()
|
||||
+ ":" + frames[i].getLineNumber() + ")" + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(output);
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void skipBytes(long length) throws IOException {
|
||||
while (length > 0) {
|
||||
long skipped = in.skip(length);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -94,4 +94,42 @@ public abstract class Reader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Stack Traces from a Hprof file.
|
||||
*
|
||||
* @param heapFile The name of a file containing a heap dump
|
||||
*/
|
||||
public static String getStack(String heapFile, int debugLevel)
|
||||
throws IOException {
|
||||
int dumpNumber = 1;
|
||||
int pos = heapFile.lastIndexOf('#');
|
||||
if (pos > -1) {
|
||||
String num = heapFile.substring(pos+1, heapFile.length());
|
||||
try {
|
||||
dumpNumber = Integer.parseInt(num, 10);
|
||||
} catch (java.lang.NumberFormatException ex) {
|
||||
String msg = "In file name \"" + heapFile
|
||||
+ "\", a dump number was "
|
||||
+ "expected after the :, but \""
|
||||
+ num + "\" was found instead.";
|
||||
System.err.println(msg);
|
||||
throw new IOException(msg);
|
||||
}
|
||||
heapFile = heapFile.substring(0, pos);
|
||||
}
|
||||
try (PositionDataInputStream in = new PositionDataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(heapFile)))) {
|
||||
int i = in.readInt();
|
||||
if (i == HprofReader.MAGIC_NUMBER) {
|
||||
HprofReader r
|
||||
= new HprofReader(heapFile, in, dumpNumber,
|
||||
true, debugLevel);
|
||||
r.read();
|
||||
return r.printStackTraces();
|
||||
} else {
|
||||
throw new IOException("Unrecognized magic number: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user