RELNOTES[INC]: Remove `--experimental_profile_cpu_usage`.

We always want to do that if we are generating the JSON trace profile.

PiperOrigin-RevId: 402312896
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java
index 8496c0e..86bfe91 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java
@@ -478,6 +478,15 @@
         documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
         help = "No-op")
     public TriState enableTracerCompression;
+
+    @Option(
+        name = "experimental_profile_cpu_usage",
+        defaultValue = "true",
+        effectTags = {OptionEffectTag.NO_OP},
+        metadataTags = {OptionMetadataTag.DEPRECATED, OptionMetadataTag.EXPERIMENTAL},
+        documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+        help = "No-op")
+    public boolean enableCpuUsageProfiling;
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
index e0fdbcb..f5b5725 100644
--- a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
+++ b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
@@ -366,7 +366,6 @@
       boolean recordAllDurations,
       Clock clock,
       long execStartTimeNanos,
-      boolean enabledCpuUsageProfiling,
       boolean slimProfile,
       boolean includePrimaryOutput,
       boolean includeTargetLabel,
@@ -389,7 +388,7 @@
         TASK_COUNT < 256,
         "The profiler implementation supports only up to 255 different ProfilerTask values.");
 
-    // reset state for the new profiling session
+    // Reset state for the new profiling session.
     taskId.set(0);
     this.recordAllDurations = recordAllDurations;
     FileWriter writer = null;
@@ -421,15 +420,14 @@
     }
     this.writerRef.set(writer);
 
-    // activate profiler
+    // Activate profiler.
     profileStartTime = execStartTimeNanos;
     profileCpuStartTime = getProcessCpuTime();
 
-    if (enabledCpuUsageProfiling) {
-      cpuUsageThread = new CollectLocalResourceUsage(bugReporter);
-      cpuUsageThread.setDaemon(true);
-      cpuUsageThread.start();
-    }
+    // Start collecting Bazel and system-wide CPU metric collection.
+    cpuUsageThread = new CollectLocalResourceUsage(bugReporter);
+    cpuUsageThread.setDaemon(true);
+    cpuUsageThread.start();
   }
 
   /**
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 43e806e..77f1f5f 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
@@ -394,7 +394,6 @@
             recordFullProfilerData,
             clock,
             execStartTimeNanos,
-            options.enableCpuUsageProfiling,
             options.slimProfile,
             options.includePrimaryOutput,
             options.profileIncludeTargetLabel,
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
index e8a1420..3e15816 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
@@ -225,14 +225,6 @@
   public TriState enableTracer;
 
   @Option(
-      name = "experimental_profile_cpu_usage",
-      defaultValue = "true",
-      documentationCategory = OptionDocumentationCategory.LOGGING,
-      effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.BAZEL_MONITORING},
-      help = "If set, Bazel will measure cpu usage and add it to the JSON profile.")
-  public boolean enableCpuUsageProfiling;
-
-  @Option(
       name = "experimental_profile_additional_tasks",
       converter = ProfilerTaskConverter.class,
       defaultValue = "null",
diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/util/BlazeRuntimeWrapper.java b/src/test/java/com/google/devtools/build/lib/buildtool/util/BlazeRuntimeWrapper.java
index 5812fba..2326242 100644
--- a/src/test/java/com/google/devtools/build/lib/buildtool/util/BlazeRuntimeWrapper.java
+++ b/src/test/java/com/google/devtools/build/lib/buildtool/util/BlazeRuntimeWrapper.java
@@ -319,7 +319,6 @@
               /*recordAllDurations=*/ false,
               new JavaClock(),
               /*execStartTimeNanos=*/ 42,
-              /*enabledCpuUsageProfiling=*/ false,
               /*slimProfile=*/ false,
               /*includePrimaryOutput=*/ false,
               /*includeTargetLabel=*/ false,
diff --git a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java
index 1b9bb9c..fa73cb0 100644
--- a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java
@@ -100,7 +100,6 @@
         false,
         BlazeClock.instance(),
         BlazeClock.nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -119,7 +118,6 @@
         false,
         BlazeClock.instance(),
         BlazeClock.nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -159,7 +157,7 @@
     profiler.logEvent(ProfilerTask.PHASE, "should be ignored");
 
     JsonProfile jsonProfile = new JsonProfile(new ByteArrayInputStream(buffer.toByteArray()));
-    assertThat(jsonProfile.getTraceEvents())
+    assertThat(removeUsageEvents(jsonProfile.getTraceEvents()))
         .hasSize(
             2 /* thread names */
                 + 2 /* thread indices */
@@ -225,7 +223,6 @@
         true,
         clock,
         clock.nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -274,7 +271,6 @@
         true,
         BlazeClock.instance(),
         BlazeClock.instance().nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -395,7 +391,6 @@
         true,
         BlazeClock.instance(),
         BlazeClock.instance().nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -451,7 +446,7 @@
     profiler.stop();
 
     JsonProfile jsonProfile = new JsonProfile(new ByteArrayInputStream(buffer.toByteArray()));
-    assertThat(jsonProfile.getTraceEvents())
+    assertThat(removeUsageEvents(jsonProfile.getTraceEvents()))
         .hasSize(
             4 /* thread names */
                 + 4 /* thread indices */
@@ -517,7 +512,8 @@
     profiler.stop();
 
     JsonProfile jsonProfile = new JsonProfile(new ByteArrayInputStream(buffer.toByteArray()));
-    assertThat(jsonProfile.getTraceEvents())
+    List<TraceEvent> filteredEvents = removeUsageEvents(jsonProfile.getTraceEvents());
+    assertThat(filteredEvents)
         .hasSize(
             4 /* thread names */
                 + 4 /* threads sort index */
@@ -526,16 +522,21 @@
                 + 1 /* complex task */
                 + 1 /* last task */
                 + 1 /* finishing */);
-    assertThat(getTraceEventsForPhase(ProfilePhase.INIT, jsonProfile.getTraceEvents())).isEmpty();
-    assertThat(
-            getTraceEventsForPhase(ProfilePhase.TARGET_PATTERN_EVAL, jsonProfile.getTraceEvents()))
+    assertThat(getTraceEventsForPhase(ProfilePhase.INIT, filteredEvents)).isEmpty();
+    assertThat(getTraceEventsForPhase(ProfilePhase.TARGET_PATTERN_EVAL, filteredEvents))
         .hasSize(100); // thread1
-    assertThat(getTraceEventsForPhase(ProfilePhase.ANALYZE, jsonProfile.getTraceEvents()))
+    assertThat(getTraceEventsForPhase(ProfilePhase.ANALYZE, filteredEvents))
         .hasSize(101); // complex task and thread2a
-    assertThat(getTraceEventsForPhase(ProfilePhase.EXECUTE, jsonProfile.getTraceEvents()))
+    assertThat(getTraceEventsForPhase(ProfilePhase.EXECUTE, filteredEvents))
         .hasSize(102); // thread2b + last task + finishing
   }
 
+  // Filter out CPU and memory usage events. These are non-deterministic depending on the duration
+  // of the profile.
+  private static List<TraceEvent> removeUsageEvents(List<TraceEvent> events) {
+    return events.stream().filter(e -> !e.name().contains("usage")).collect(Collectors.toList());
+  }
+
   /**
    * Extracts all events for a given phase.
    *
@@ -587,7 +588,6 @@
         false,
         badClock,
         initialNanoTime,
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -646,7 +646,6 @@
         false,
         BlazeClock.instance(),
         BlazeClock.instance().nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -675,7 +674,6 @@
         false,
         BlazeClock.instance(),
         BlazeClock.instance().nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,
@@ -700,7 +698,6 @@
         true,
         clock,
         clock.nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ true,
         /*includeTargetLabel=*/ false,
@@ -733,7 +730,6 @@
         true,
         clock,
         clock.nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         /*slimProfile=*/ false,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ true,
@@ -765,7 +761,6 @@
         false,
         BlazeClock.instance(),
         BlazeClock.instance().nanoTime(),
-        /*enabledCpuUsageProfiling=*/ false,
         slimProfile,
         /*includePrimaryOutput=*/ false,
         /*includeTargetLabel=*/ false,