< prev index next >

test/serviceability/dcmd/gc/HeapDumpTest.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import org.testng.annotations.Test;
  25 import org.testng.Assert;
  26 
  27 import java.io.IOException;
  28 
  29 import com.oracle.java.testlibrary.JDKToolFinder;
  30 import com.oracle.java.testlibrary.OutputAnalyzer;
  31 import com.oracle.java.testlibrary.dcmd.CommandExecutor;
  32 import com.oracle.java.testlibrary.dcmd.PidJcmdExecutor;
  33 
  34 /*
  35  * @test
  36  * @summary Test of diagnostic command GC.heap_dump
  37  * @library /testlibrary
  38  * @modules java.base/sun.misc
  39  *          java.compiler
  40  *          java.management
  41  *          jdk.jvmstat/sun.jvmstat.monitor
  42  * @build com.oracle.java.testlibrary.*
  43  * @build com.oracle.java.testlibrary.dcmd.*
  44  * @run testng HeapDumpTest
  45  */
  46 public class HeapDumpTest {
  47     protected String heapDumpArgs = "";
  48 
  49     public void run(CommandExecutor executor) {
  50         String fileName = "jcmd.gc.heap_dump." + System.currentTimeMillis() + ".hprof";
  51         String cmd = "GC.heap_dump " + heapDumpArgs + " " + fileName;
  52         executor.execute(cmd);
  53 
  54         verifyHeapDump(fileName);
  55     }
  56 
  57     private void verifyHeapDump(String fileName) {
  58         String jhat = JDKToolFinder.getJDKTool("jhat");
  59         String[] cmd = { jhat, "-parseonly", "true", fileName };
  60 
  61         ProcessBuilder pb = new ProcessBuilder(cmd);
  62         pb.redirectErrorStream(true);
  63         Process p = null;




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import org.testng.annotations.Test;
  25 import org.testng.Assert;
  26 
  27 import java.io.IOException;
  28 
  29 import jdk.test.lib.JDKToolFinder;
  30 import jdk.test.lib.OutputAnalyzer;
  31 import jdk.test.lib.dcmd.CommandExecutor;
  32 import jdk.test.lib.dcmd.PidJcmdExecutor;
  33 
  34 /*
  35  * @test
  36  * @summary Test of diagnostic command GC.heap_dump
  37  * @library /testlibrary
  38  * @modules java.base/sun.misc
  39  *          java.compiler
  40  *          java.management
  41  *          jdk.jvmstat/sun.jvmstat.monitor
  42  * @build jdk.test.lib.*
  43  * @build jdk.test.lib.dcmd.*
  44  * @run testng HeapDumpTest
  45  */
  46 public class HeapDumpTest {
  47     protected String heapDumpArgs = "";
  48 
  49     public void run(CommandExecutor executor) {
  50         String fileName = "jcmd.gc.heap_dump." + System.currentTimeMillis() + ".hprof";
  51         String cmd = "GC.heap_dump " + heapDumpArgs + " " + fileName;
  52         executor.execute(cmd);
  53 
  54         verifyHeapDump(fileName);
  55     }
  56 
  57     private void verifyHeapDump(String fileName) {
  58         String jhat = JDKToolFinder.getJDKTool("jhat");
  59         String[] cmd = { jhat, "-parseonly", "true", fileName };
  60 
  61         ProcessBuilder pb = new ProcessBuilder(cmd);
  62         pb.redirectErrorStream(true);
  63         Process p = null;


< prev index next >