Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/compiler/PerfMapTest.java
41153 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020, Arm Limited. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* @test PerfMapTest26* @bug 825472327* @requires os.family == "linux"28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.compiler31* java.management32* jdk.internal.jvmstat/sun.jvmstat.monitor33* @run testng/othervm PerfMapTest34* @summary Test of diagnostic command Compiler.perfmap35*/3637import org.testng.annotations.Test;38import org.testng.Assert;3940import jdk.test.lib.process.OutputAnalyzer;41import jdk.test.lib.dcmd.CommandExecutor;42import jdk.test.lib.dcmd.JMXExecutor;4344import java.io.IOException;45import java.nio.file.Files;46import java.nio.file.Path;47import java.nio.file.Paths;48import java.util.regex.Matcher;49import java.util.regex.Pattern;5051/**52* Call jcmd Compiler.perfmap and check the output file has the expected53* format.54*/55public class PerfMapTest {5657static final Pattern LINE_PATTERN =58Pattern.compile("^((?:0x)?\\p{XDigit}+)\\s+((?:0x)?\\p{XDigit}+)\\s+(.*)$");5960public void run(CommandExecutor executor) {61OutputAnalyzer output = executor.execute("Compiler.perfmap");6263output.stderrShouldBeEmpty();64output.stdoutShouldBeEmpty();6566final long pid = ProcessHandle.current().pid();67final Path path = Paths.get(String.format("/tmp/perf-%d.map", pid));6869Assert.assertTrue(Files.exists(path));7071// Sanity check the file contents72try {73for (String entry : Files.readAllLines(path)) {74Matcher m = LINE_PATTERN.matcher(entry);75Assert.assertTrue(m.matches(), "Invalid file format: " + entry);76}77} catch (IOException e) {78Assert.fail(e.toString());79}80}8182@Test83public void jmx() {84run(new JMXExecutor());85}86}878889