test/jdk/jdk/jfr/startupargs/TestMultipleStartupRecordings.java
author mgronlun
Tue, 19 Jun 2018 19:16:08 +0200
changeset 50664 857ce291c70c
child 51214 67736b4846a0
permissions -rw-r--r--
8204571: Add support for launching multiple startup recordings Reviewed-by: egahlin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50664
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     1
/*
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     4
 *
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    10
 *
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    15
 * accompanied this code).
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    16
 *
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    20
 *
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    23
 * questions.
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    24
 */
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    25
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    26
package jdk.jfr.startupargs;
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    27
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    28
import jdk.test.lib.Asserts;
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    29
import jdk.test.lib.process.OutputAnalyzer;
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    30
import jdk.test.lib.process.ProcessTools;
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    31
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    32
/*
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    33
 * @test
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    34
 * @key jfr
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    35
 *
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    36
 * @library /test/lib
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    37
 *
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    38
 * @run main jdk.jfr.startupargs.TestMultipleStartupRecordings
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    39
 */
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    40
public class TestMultipleStartupRecordings {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    41
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    42
    private static final String START_FLIGHT_RECORDING = "-XX:StartFlightRecording";
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    43
    private static final String FLIGHT_RECORDER_OPTIONS = "-XX:FlightRecorderOptions";
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    44
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    45
    static class MainClass {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    46
        public static void main(String[] args) {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    47
        }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    48
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    49
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    50
    private static void test(ProcessBuilder pb, String... expectedOutputs) throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    51
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    52
        for (String s : expectedOutputs) {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    53
            output.shouldContain(s);
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    54
        }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    55
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    56
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    57
    private static void launchUnary(String options) throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    58
        String recording1 = START_FLIGHT_RECORDING + (options != null ? options : "");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    59
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, recording1, MainClass.class.getName());
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    60
        test(pb, "Started recording 1");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    61
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    62
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    63
    private static void launchBinary(String options1, String options2) throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    64
        String recording1 = START_FLIGHT_RECORDING + (options1 != null ? options1 : "");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    65
        String recording2 = START_FLIGHT_RECORDING + (options2 != null ? options2 : "");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    66
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, recording1, recording2, MainClass.class.getName());
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    67
        test(pb, "Started recording 1", "Started recording 2");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    68
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    69
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    70
    private static void launchTernary(String options1, String options2, String options3) throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    71
        String recording1 = START_FLIGHT_RECORDING + (options1 != null ? options1 : "");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    72
        String recording2 = START_FLIGHT_RECORDING + (options2 != null ? options2 : "");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    73
        String recording3 = START_FLIGHT_RECORDING + (options3 != null ? options3 : "");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    74
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, recording1, recording2, recording3, MainClass.class.getName());
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    75
        test(pb, "Started recording 1", "Started recording 2", "Started recording 3");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    76
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    77
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    78
    private static void testDefault() throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    79
        System.out.println("testDefault");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    80
        launchUnary(null);
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    81
        launchBinary(null, null);
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    82
        launchTernary(null, null, null);
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    83
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    84
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    85
    private static void testColonDelimited() throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    86
        launchBinary(":name=myrecording1,filename=myrecording1.jfr", ":filename=myrecording2.jfr,name=myrecording2");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    87
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    88
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    89
    private static void testMixed() throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    90
        launchTernary(":maxage=2d,maxsize=5GB", "=dumponexit=true,maxage=10m,", ":name=myrecording,maxage=10m,filename=myrecording.jfr,disk=false");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    91
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    92
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    93
    private static void testWithFlightRecorderOptions() throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    94
        System.out.println("testWithFlightRecorderOptions");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    95
        String flightRecorderOptions = FLIGHT_RECORDER_OPTIONS + "=maxchunksize=8m";
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    96
        String recording1 = START_FLIGHT_RECORDING + "=filename=recording1.jfr";
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    97
        String recording2 = START_FLIGHT_RECORDING + "=name=myrecording,filename=recording2.jfr";
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    98
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, flightRecorderOptions, recording1, recording2, MainClass.class.getName());
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
    99
        test(pb, "Started recording 1", "Started recording 2");
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   100
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   101
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   102
    public static void main(String[] args) throws Exception {
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   103
        testDefault();
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   104
        testColonDelimited();
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   105
        testMixed();
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   106
        testWithFlightRecorderOptions();
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   107
    }
857ce291c70c 8204571: Add support for launching multiple startup recordings
mgronlun
parents:
diff changeset
   108
}