diff --git a/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfile.java b/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfile.java index b398129..389d491 100644 --- a/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfile.java +++ b/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfile.java @@ -172,22 +172,15 @@ static boolean isMainThread(ProfileThread thread) { } /** - * Returns whether the passed-in thread looks like the garbage collection, both for newer and - * older versions of Bazel. See - * https://github.com/bazelbuild/bazel/commit/a03674e6297ed5f6f740889cba8780d7c4ffe05c for when - * the naming of the garbage collection thread was changed. + * Returns whether the passed-in thread has at least one garbage collection event. * * @param thread the thread to check - * @return whether the thread looks like it is the garbage collection thread + * @return whether the thread includes a garbage collection event */ @VisibleForTesting static boolean isGarbageCollectorThread(ProfileThread thread) { - String name = thread.getName(); - if (Strings.isNullOrEmpty(name)) { - return false; - } - return name.equals(BazelProfileConstants.THREAD_GARBAGE_COLLECTOR) - || name.equals(BazelProfileConstants.THREAD_GARBAGE_COLLECTOR_OLD); + return thread.getCompleteEvents().stream() + .anyMatch(event -> event.category.equals(BazelProfileConstants.CAT_GARBAGE_COLLECTION)); } /** diff --git a/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfileConstants.java b/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfileConstants.java index 67fbf77..425bc52 100644 --- a/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfileConstants.java +++ b/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/BazelProfileConstants.java @@ -21,9 +21,34 @@ public class BazelProfileConstants { // Thread names: event.name == METADATA_THREAD_NAME && event.args.name == constant below // These constants should not be used outside this package. @VisibleForTesting public static final String THREAD_CRITICAL_PATH = "Critical Path"; - @VisibleForTesting public static final String THREAD_GARBAGE_COLLECTOR = "Garbage Collector"; - // See https://github.com/bazelbuild/bazel/commit/a03674e6297ed5f6f740889cba8780d7c4ffe05c - static final String THREAD_GARBAGE_COLLECTOR_OLD = "Service Thread"; + + /** + * Deprecated. + * + *
The thread that contains GC events has been renamed multiple times, so it's discouraged to + * use it to filter for GC events. Instead, match the event category against {@link + * #CAT_GARBAGE_COLLECTION}. + * + *
Used thread names over time include "Service Thread", "Garbage Collector" and "Notification + * Thread". E.g. see + * https://github.com/bazelbuild/bazel/commit/a03674e6297ed5f6f740889cba8780d7c4ffe05c + */ + @Deprecated @VisibleForTesting + public static final String THREAD_GARBAGE_COLLECTOR = "Garbage Collector"; + + /** + * Deprecated. + * + *
The thread that contains GC events has been renamed multiple times, so it's discouraged to + * use it to filter for GC events. Instead, match the event category against {@link + * #CAT_GARBAGE_COLLECTION}. + * + *
Used thread names over time include "Service Thread", "Garbage Collector" and "Notification
+ * Thread". E.g. see
+ * https://github.com/bazelbuild/bazel/commit/a03674e6297ed5f6f740889cba8780d7c4ffe05c
+ */
+ @Deprecated static final String THREAD_GARBAGE_COLLECTOR_OLD = "Service Thread";
+
@VisibleForTesting public static final String THREAD_MAIN = "Main Thread";
// See https://github.com/bazelbuild/bazel/commit/a03674e6297ed5f6f740889cba8780d7c4ffe05c
static final String THREAD_MAIN_OLD_PREFIX = "grpc-command";
diff --git a/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/ProfileThread.java b/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/ProfileThread.java
index 74be0a4..16efee5 100644
--- a/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/ProfileThread.java
+++ b/analyzer/java/com/engflow/bazel/invocation/analyzer/bazelprofile/ProfileThread.java
@@ -19,6 +19,7 @@
import com.engflow.bazel.invocation.analyzer.traceeventformat.InstantEvent;
import com.engflow.bazel.invocation.analyzer.traceeventformat.TraceEventFormatConstants;
import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterators;
@@ -78,19 +79,19 @@ public ProfileThread(
ThreadId threadId,
@Nullable String name,
@Nullable Integer sortIndex,
- List