Skip to content

Commit f034685

Browse files
coeuvrecopybara-github
authored andcommitted
Dump virtual threads with ThreadDumper when interruption took too long.
PiperOrigin-RevId: 792107510 Change-Id: I0af3c73873b4313f92e26b064a455a2b2aadaa37
1 parent 471fb6e commit f034685

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/main/java/com/google/devtools/build/lib/util/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ java_library(
254254
":os",
255255
":shell_escaper",
256256
":string_encoding",
257+
":thread_dumper",
257258
"//src/main/java/com/google/devtools/build/lib/bugreport",
258259
"//src/main/java/com/google/devtools/build/lib/concurrent:thread_safety",
259260
"//src/main/java/com/google/devtools/build/lib/util/io",

src/main/java/com/google/devtools/build/lib/util/ThreadUtils.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.util;
1515

16+
import static java.nio.charset.StandardCharsets.UTF_8;
1617
import static java.util.stream.Collectors.toCollection;
1718

1819
import com.google.common.annotations.VisibleForTesting;
1920
import com.google.common.base.Joiner;
2021
import com.google.common.flogger.GoogleLogger;
2122
import com.google.devtools.build.lib.bugreport.BugReporter;
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.IOException;
2225
import java.util.ArrayList;
2326
import java.util.Arrays;
2427
import java.util.Comparator;
@@ -46,8 +49,7 @@ public class ThreadUtils {
4649
MAP_WITH_ARRAY_LIST_VALUES_COLLECTOR =
4750
Collectors.groupingBy(StackTraceAndState::new, toCollection(ArrayList::new));
4851

49-
private ThreadUtils() {
50-
}
52+
private ThreadUtils() {}
5153

5254
/** Write a thread dump to the blaze.INFO log if interrupt took too long. */
5355
public static synchronized void warnAboutSlowInterrupt(
@@ -87,6 +89,16 @@ static synchronized void warnAboutSlowInterrupt(
8789
makeString(stackTraceAndState.trace));
8890
});
8991

92+
try {
93+
var out = new ByteArrayOutputStream();
94+
ThreadDumper.dumpThreads(out);
95+
logger.atWarning().log(
96+
"Dumping additional thread state using ThreadDumper:\n%s",
97+
new String(out.toByteArray(), UTF_8));
98+
} catch (IOException e) {
99+
logger.atWarning().withCause(e).log("Failed to dump threads with ThreadDumper.");
100+
}
101+
90102
SlowInterruptInnerException inner =
91103
new SlowInterruptInnerException(
92104
Joiner.on(' ')

0 commit comments

Comments
 (0)