1 /*
2 * Copyright (c) 2013, 2014, 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.
8 *
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 */
82 * @param requestToCurrentProcess
83 * Defines if jcmd will send request to the current process
84 * @param vmArgs
85 * jcmd will be run with VM arguments specified,
86 * e.g. -XX:+UsePerfData
87 * @param jcmdArgs
88 * jcmd will be run with option or command and its arguments
89 * specified, e.g. VM.flags
90 * @return The output from {@link OutputAnalyzer} object
91 * @throws Exception
92 */
93 private static final OutputAnalyzer jcmd(boolean requestToCurrentProcess,
94 String[] vmArgs, String[] jcmdArgs) throws Exception {
95 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
96 if (vmArgs != null) {
97 for (String vmArg : vmArgs) {
98 launcher.addVMArg(vmArg);
99 }
100 }
101 if (requestToCurrentProcess) {
102 launcher.addToolArg(Integer.toString(ProcessTools.getProcessId()));
103 }
104 if (jcmdArgs != null) {
105 for (String toolArg : jcmdArgs) {
106 launcher.addToolArg(toolArg);
107 }
108 }
109 processBuilder.command(launcher.getCommand());
110 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
111 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
112 System.out.println(output.getOutput());
113
114 return output;
115 }
116
117 }
|
1 /*
2 * Copyright (c) 2013, 2015, 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.
8 *
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 */
82 * @param requestToCurrentProcess
83 * Defines if jcmd will send request to the current process
84 * @param vmArgs
85 * jcmd will be run with VM arguments specified,
86 * e.g. -XX:+UsePerfData
87 * @param jcmdArgs
88 * jcmd will be run with option or command and its arguments
89 * specified, e.g. VM.flags
90 * @return The output from {@link OutputAnalyzer} object
91 * @throws Exception
92 */
93 private static final OutputAnalyzer jcmd(boolean requestToCurrentProcess,
94 String[] vmArgs, String[] jcmdArgs) throws Exception {
95 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
96 if (vmArgs != null) {
97 for (String vmArg : vmArgs) {
98 launcher.addVMArg(vmArg);
99 }
100 }
101 if (requestToCurrentProcess) {
102 launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
103 }
104 if (jcmdArgs != null) {
105 for (String toolArg : jcmdArgs) {
106 launcher.addToolArg(toolArg);
107 }
108 }
109 processBuilder.command(launcher.getCommand());
110 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
111 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
112 System.out.println(output.getOutput());
113
114 return output;
115 }
116
117 }
|