# HG changeset patch # User Tom Rodriguez # Date 1403036660 25200 # Node ID 66e3fc56e85f46fbfd835d684300b2bcf9bf88b4 # Parent 7c9cf1697845e4f7c98415a77e5c9610cf8c1292 support adding pid to LogFile name diff -r 7c9cf1697845 -r 66e3fc56e85f graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Jun 17 12:50:22 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Jun 17 13:24:20 2014 -0700 @@ -169,7 +169,7 @@ @Option(help = "The runtime configuration to use") static final OptionValue GraalRuntime = new OptionValue<>(""); - @Option(help = "File to which logging is sent") + @Option(help = "File to which logging is sent. %p in the name will be replaced with a string the process, usually the process id.") public static final PrintStreamOption LogFile = new PrintStreamOption(); // @formatter:on } diff -r 7c9cf1697845 -r 66e3fc56e85f graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java Tue Jun 17 12:50:22 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java Tue Jun 17 13:24:20 2014 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot; import java.io.*; +import java.lang.management.*; import com.oracle.graal.options.*; @@ -44,6 +45,30 @@ private volatile PrintStream ps; /** + * Replace any instance of %p with a an identifying name. Try to get it from the RuntimeMXBean + * name. + * + * @return the name of the file to log to + */ + private String getFilename() { + String name = getValue(); + if (name.contains("%p")) { + String runtimeName = ManagementFactory.getRuntimeMXBean().getName(); + try { + int index = runtimeName.indexOf('@'); + if (index != -1) { + long pid = Long.parseLong(runtimeName.substring(0, index)); + runtimeName = Long.toString(pid); + } + name = name.replaceAll("%p", runtimeName); + } catch (NumberFormatException e) { + + } + } + return name; + } + + /** * Gets the print stream configured by this option. */ public PrintStream getStream() { @@ -53,7 +78,7 @@ if (ps == null) { try { final boolean enableAutoflush = true; - ps = new PrintStream(new FileOutputStream(getValue()), enableAutoflush); + ps = new PrintStream(new FileOutputStream(getFilename()), enableAutoflush); } catch (FileNotFoundException e) { throw new RuntimeException("couldn't open file: " + getValue(), e); }