forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RELNOTES: Refactor system suspend event handling.
We are looking to add more build anomaly reporting, so refactor the current system suspend handling to match the new model where we have a module and an event that we can record. Note this deprecates the AnomalyRecord out of BES for the time being. PiperOrigin-RevId: 409502784
- Loading branch information
1 parent
72428ec
commit 286fb80
Showing
27 changed files
with
414 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/com/google/devtools/build/lib/buildtool/buildevent/SystemSuspensionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.buildtool.buildevent; | ||
|
||
import com.google.devtools.build.lib.events.ExtendedEventHandler; | ||
|
||
/** | ||
* This event is fired from {@link | ||
* com.google.devtools.build.lib.platform.SystemSuspensionModule#suspendCallback} to indicate that | ||
* the user either suspended the build with a signal or put their computer to sleep. | ||
*/ | ||
public class SystemSuspensionEvent implements ExtendedEventHandler.Postable { | ||
|
||
/** The possible reasons a system could be suspended. */ | ||
public enum Reason { | ||
SIGTSTP("Signal SIGTSTP"), | ||
SIGCONT("Signal SIGCONT"), | ||
SLEEP("Computer put to sleep"), | ||
WAKE("Computer woken up"); | ||
|
||
private final String logString; | ||
|
||
Reason(String logString) { | ||
this.logString = logString; | ||
} | ||
|
||
public String logString() { | ||
return logString; | ||
} | ||
|
||
static Reason fromInt(int number) { | ||
switch (number) { | ||
case 0: | ||
return SIGTSTP; | ||
case 1: | ||
return SIGCONT; | ||
case 2: | ||
return SLEEP; | ||
case 3: | ||
return WAKE; | ||
default: | ||
throw new IllegalStateException("Unknown suspension reason: " + number); | ||
} | ||
} | ||
}; | ||
|
||
/** These constants are mapped to enum in third_party/bazel/src/main/native/unix_jni.h. */ | ||
private final Reason reason; | ||
|
||
public SystemSuspensionEvent(int reason) { | ||
this.reason = Reason.fromInt(reason); | ||
} | ||
|
||
public Reason getReason() { | ||
return reason; | ||
} | ||
|
||
public String logString() { | ||
return "SystemSuspensionEvent: " + reason.logString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
src/main/java/com/google/devtools/build/lib/platform/SuspendCounter.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/main/java/com/google/devtools/build/lib/platform/SystemSuspensionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2019 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.platform; | ||
|
||
import com.google.common.flogger.GoogleLogger; | ||
import com.google.devtools.build.lib.buildtool.buildevent.SystemSuspensionEvent; | ||
import com.google.devtools.build.lib.events.Event; | ||
import com.google.devtools.build.lib.events.Reporter; | ||
import com.google.devtools.build.lib.jni.JniLoader; | ||
import com.google.devtools.build.lib.runtime.BlazeModule; | ||
import com.google.devtools.build.lib.runtime.CommandEnvironment; | ||
import javax.annotation.concurrent.GuardedBy; | ||
|
||
/** Detects suspension events. */ | ||
public final class SystemSuspensionModule extends BlazeModule { | ||
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); | ||
|
||
static { | ||
JniLoader.loadJni(); | ||
} | ||
|
||
@GuardedBy("this") | ||
private Reporter reporter; | ||
|
||
private native void registerJNI(); | ||
|
||
public SystemSuspensionModule() { | ||
if (JniLoader.isJniAvailable()) { | ||
registerJNI(); | ||
} | ||
} | ||
|
||
@Override | ||
public synchronized void beforeCommand(CommandEnvironment env) { | ||
this.reporter = env.getReporter(); | ||
} | ||
|
||
@Override | ||
public synchronized void afterCommand() { | ||
this.reporter = null; | ||
} | ||
|
||
/** Callback method called from JNI whenever a suspension event occurs. */ | ||
synchronized void suspendCallback(int reason) { | ||
if (reporter != null) { | ||
SystemSuspensionEvent event = new SystemSuspensionEvent(reason); | ||
String logString = event.logString(); | ||
reporter.handle(Event.info(logString)); | ||
reporter.post(event); | ||
logger.atInfo().log(logString); | ||
} | ||
} | ||
} |
Oops, something went wrong.