diff options
author | 2017-03-28 20:18:21 +0000 | |
---|---|---|
committer | 2017-03-29 14:21:50 +0200 | |
commit | 1cb9a012a73d6adfc0027099b5f3bd94784cc300 (patch) | |
tree | f340e1c11c149fb7d58357894d88bde79326fa20 /src/main/java/com/google | |
parent | 94c150073762c72d5af86fdf93c4deb03fd95dc1 (diff) |
Log the server pid to java logging.
PiperOrigin-RevId: 151489034
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 368b66bd89..270d89f8f7 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -559,7 +559,11 @@ public final class BlazeRuntime { // Run Blaze in batch mode. System.exit(batchMain(modules, args)); } - LOG.info("Starting Blaze server with args " + Arrays.toString(args)); + LOG.info( + "Starting Blaze server with pid " + + maybeGetPidString() + + " and args " + + Arrays.toString(args)); try { // Run Blaze in server mode. System.exit(serverMain(modules, OutErr.SYSTEM_OUT_ERR, args)); @@ -736,8 +740,11 @@ public final class BlazeRuntime { private static int batchMain(Iterable<BlazeModule> modules, String[] args) { captureSigint(); CommandLineOptions commandLineOptions = splitStartupOptions(modules, args); - LOG.info("Running Blaze in batch mode with startup args " - + commandLineOptions.getStartupArgs()); + LOG.info( + "Running Blaze in batch mode with " + + maybeGetPidString() + + "startup args " + + commandLineOptions.getStartupArgs()); BlazeRuntime runtime; try { @@ -933,7 +940,7 @@ public final class BlazeRuntime { PathFragment installBase = startupOptions.installBase; PathFragment outputBase = startupOptions.outputBase; - maybeForceJNI(installBase); // Must be before first use of JNI. + maybeForceJNIByGettingPid(installBase); // Must be before first use of JNI. // From the point of view of the Java program --install_base and --output_base // are mandatory options, despite the comment in their declarations. @@ -1017,13 +1024,15 @@ public final class BlazeRuntime { return runtime; } - /** - * Loads JNI libraries, if necessary under the current platform. - */ - public static void maybeForceJNI(PathFragment installBase) { - if (jniLibsAvailable()) { - forceJNI(installBase); - } + private static String maybeGetPidString() { + Integer pid = maybeForceJNIByGettingPid(null); + return pid == null ? "" : "pid " + pid + " and "; + } + + /** Loads JNI libraries, if necessary under the current platform. */ + @Nullable + private static Integer maybeForceJNIByGettingPid(@Nullable PathFragment installBase) { + return jniLibsAvailable() ? getPidUsingJNI(installBase) : null; } private static boolean jniLibsAvailable() { @@ -1032,13 +1041,19 @@ public final class BlazeRuntime { // Force JNI linking at a moment when we have 'installBase' handy, and print // an informative error if it fails. - private static void forceJNI(PathFragment installBase) { + private static int getPidUsingJNI(@Nullable PathFragment installBase) { try { - ProcessUtils.getpid(); // force JNI initialization + return ProcessUtils.getpid(); // force JNI initialization } catch (UnsatisfiedLinkError t) { - System.err.println("JNI initialization failed: " + t.getMessage() + ". " - + "Possibly your installation has been corrupted; " - + "if this problem persists, try 'rm -fr " + installBase + "'."); + System.err.println( + "JNI initialization failed: " + + t.getMessage() + + ". " + + "Possibly your installation has been corrupted" + + (installBase == null + ? "" + : "; if this problem persists, try 'rm -fr " + installBase + "'") + + "."); throw t; } } |