1 /* 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. 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 it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.jfr.jcmd; 27 28 29 30 import java.io.IOException; 31 import java.nio.file.Files; 32 import java.nio.file.Paths; 33 import java.util.List; 34 35 import jdk.test.lib.dcmd.JcmdExecutor; 36 import jdk.test.lib.dcmd.PidJcmdExecutor; 37 38 /** 39 * @test TestJcmdLogLevelChange 40 * @key jfr 41 * @summary Test changing log level 42 * @requires vm.hasJFR 43 * 44 * @library /test/lib /test/jdk 45 * 46 * @run main/othervm -Xlog:jfr=info jdk.jfr.jcmd.TestJcmdChangeLogLevel 47 */ 48 public class TestJcmdChangeLogLevel { 49 public static void main(String[] args) throws Exception { 50 final String fileName = "jfr_trace.txt"; 51 final String findWhat = "[info][jfr] Flight Recorder initialized"; 52 boolean passed = false; 53 54 JcmdExecutor je = new PidJcmdExecutor(); 55 je.execute("VM.log output='file=" + fileName + "' what='jfr=info'"); 56 je.execute("JFR.start duration=1s"); 57 List<String> lines; 58 59 do { 60 try { 61 lines = Files.readAllLines(Paths.get(fileName)); 62 } catch (IOException e) { 63 throw new Error(e); 64 } 65 for (String l : lines) { 66 if (l.toString().contains(findWhat)) { 67 passed = true; 68 break; 69 } 70 } 71 if (lines.size() > 100) { 72 break; /* did not find it */ 73 } 74 } while(!passed); 75 76 if (!passed) { 77 throw new Error("Not found " + findWhat + " in stream" + lines); 78 } 79 80 System.out.println("PASSED"); 81 } 82 }