public static List<String> buildJavaArg() { List<String> command = new ArrayList<String>(); command.add(Utils.getCurrentJvm()); command.add("-cp"); if (Utils.isWindows()) { command.add('"' + System.getProperty("java.class.path") + '"'); } else { command.add(System.getProperty("java.class.path")); } command.add(MemoryTest.class.getName()); return command; }
private void profilerCommand(String command) { long pid = Utils.getPid(); ProcessBuilder processBuilder = new ProcessBuilder(jattach.toAbsolutePath().toString(), String.valueOf(pid), "load", profiler.toAbsolutePath().toString(), "true", command); if (verbose) { processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); } ProfilerUtils.startAndWait(processBuilder, verbose); }
@Override public void printError(String message, Throwable throwable) { printError(message + " " + Utils.throwableToString(throwable)); }
private static OutputFormat createOutputFormat(Options options) { // sadly required here as the check cannot be made before calling this method in // constructor if (options == null) { throw new IllegalArgumentException("Options not allowed to be null."); } PrintStream out; if (options.getOutput().hasValue()) { try { out = new PrintStream(options.getOutput().get()); } catch (FileNotFoundException ex) { throw new IllegalStateException(ex); } } else { // Protect the System.out from accidental closing try { out = new UnCloseablePrintStream(System.out, Utils.guessConsoleEncoding()); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } } return OutputFormatFactory.createFormatInstance(out, options.verbosity().orElse(Defaults.VERBOSITY)); }
public void run() throws Exception { List<String> args = new ArrayList<>(this.args); if (jvmArgs!=null) { args.addAll(1, this.jvmArgs); } args.add(args.size() - this.length, this.mainClass); if (progArgs!=null) { args.addAll(progArgs); } ProcessBuilder builder = new ProcessBuilder(args); builder.directory(home); builder.redirectErrorStream(true); customize(builder); if (!"false".equals(System.getProperty("debug", "false"))) { System.err.println("Running: " + Utils.join(args, " ")); } started = builder.start(); monitor(); }
public OutputFormat createOutputFormat(Options options) { // sadly required here as the check cannot be made before calling this method in // constructor if (options == null) { throw new IllegalArgumentException("Options not allowed to be null."); } PrintStream out; if (options.getOutput().hasValue()) { try { out = new PrintStream(options.getOutput().get()); } catch (FileNotFoundException ex) { throw new IllegalStateException(ex); } } else { // Protect the System.out from accidental closing try { out = new UnCloseablePrintStream(System.out, Utils.guessConsoleEncoding()); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } } return OutputFormatFactory.createFormatInstance(out, options.verbosity().orElse(Defaults.VERBOSITY)); } }
private void jcmd(String jvm, String command, List<String> options) { long pid = Utils.getPid(); ArrayList<String> args = new ArrayList<>(); Path jcmd = findJcmd(jvm); args.add(jcmd.toAbsolutePath().toString()); args.add(String.valueOf(pid)); args.add(command); args.addAll(options); ProcessBuilder processBuilder = new ProcessBuilder(args); if (verbose) { processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); } ProfilerUtils.startAndWait(processBuilder, verbose); }
@Override public void printWarning(String message, Throwable throwable) { printWarning(message + " " + Utils.throwableToString(throwable)); }