Skip to content

Commit

Permalink
Replace CounterSeriesTask.ofProfilerTask with direct constructor call
Browse files Browse the repository at this point in the history
... and remove `ProfilerTask`s that are no longer used after the refactor.

PiperOrigin-RevId: 675548469
Change-Id: Iad16e816904b90b9b1373e75580a04e05e9c7c5a
  • Loading branch information
coeuvre authored and copybara-github committed Sep 17, 2024
1 parent 79ab580 commit 94b72e4
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private void addRange(

private static class LocalCpuUsageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask LOCAL_CPU_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.LOCAL_CPU_USAGE);
new CounterSeriesTask("CPU usage (Bazel)", "cpu", CounterSeriesTask.Color.GOOD);

private final OperatingSystemMXBean osBean;
private long previousCpuTimeNanos;
Expand All @@ -307,7 +307,7 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class LocalMemoryUsageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask LOCAL_MEMORY_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.LOCAL_MEMORY_USAGE);
new CounterSeriesTask("Memory usage (Bazel)", "memory", CounterSeriesTask.Color.OLIVE);
private final MemoryMXBean memoryBean;
private final BugReporter bugReporter;

Expand Down Expand Up @@ -337,7 +337,7 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class SystemCpuUsageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask SYSTEM_CPU_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.SYSTEM_CPU_USAGE);
new CounterSeriesTask("CPU usage (total)", "system cpu", CounterSeriesTask.Color.RAIL_LOAD);
private final OperatingSystemMXBean osBean;
private final int numProcessors;

Expand All @@ -362,7 +362,7 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class SystemMemoryUsageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask SYSTEM_MEMORY_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.SYSTEM_MEMORY_USAGE);
new CounterSeriesTask("Memory usage (total)", "system memory", CounterSeriesTask.Color.BAD);
private final OperatingSystemMXBean osBean;

private SystemMemoryUsageCollector(OperatingSystemMXBean osBean) {
Expand Down Expand Up @@ -396,7 +396,8 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class WorkerMemoryUsageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask WORKERS_MEMORY_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.WORKERS_MEMORY_USAGE);
new CounterSeriesTask(
"Workers memory usage", "workers memory", CounterSeriesTask.Color.RAIL_ANIMATION);
private final WorkerProcessMetricsCollector workerProcessMetricsCollector;

private WorkerMemoryUsageCollector(
Expand All @@ -420,7 +421,7 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class SystemLoadAverageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask SYSTEM_LOAD_AVERAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.SYSTEM_LOAD_AVERAGE);
new CounterSeriesTask("System load average", "load", CounterSeriesTask.Color.GENERIC_WORK);
private final OperatingSystemMXBean osBean;

private SystemLoadAverageCollector(OperatingSystemMXBean osBean) {
Expand All @@ -438,9 +439,15 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class SystemNetworkUsageCollector implements CounterSeriesCollector {
private static final CounterSeriesTask SYSTEM_NETWORK_UP_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.SYSTEM_NETWORK_UP_USAGE);
new CounterSeriesTask(
"Network Up usage (total)",
"system network up (Mbps)",
CounterSeriesTask.Color.RAIL_RESPONSE);
private static final CounterSeriesTask SYSTEM_NETWORK_DOWN_USAGE =
CounterSeriesTask.ofProfilerTask(ProfilerTask.SYSTEM_NETWORK_DOWN_USAGE);
new CounterSeriesTask(
"Network Down usage (total)",
"system network down (Mbps)",
CounterSeriesTask.Color.RAIL_RESPONSE);

@Override
public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> consumer) {
Expand All @@ -453,9 +460,13 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class ResourceManagerEstimationCollector implements CounterSeriesCollector {
private static final CounterSeriesTask MEMORY_USAGE_ESTIMATION =
CounterSeriesTask.ofProfilerTask(ProfilerTask.MEMORY_USAGE_ESTIMATION);
new CounterSeriesTask(
"Memory usage estimation", "estimated memory", CounterSeriesTask.Color.RAIL_IDLE);
private static final CounterSeriesTask CPU_USAGE_ESTIMATION =
CounterSeriesTask.ofProfilerTask(ProfilerTask.CPU_USAGE_ESTIMATION);
new CounterSeriesTask(
"CPU usage estimation",
"estimated cpu",
CounterSeriesTask.Color.CQ_BUILD_ATTEMPT_PASSED);

private final ResourceEstimator resourceEstimator;

Expand All @@ -474,15 +485,30 @@ public void collect(double deltaNanos, BiConsumer<CounterSeriesTask, Double> con

private static class PressureStallIndicatorCollector implements CounterSeriesCollector {
private static final CounterSeriesTask PRESSURE_STALL_FULL_IO =
CounterSeriesTask.ofProfilerTask(ProfilerTask.PRESSURE_STALL_FULL_IO);
private static final CounterSeriesTask PRESSURE_STALL_FULL_MEMORY =
CounterSeriesTask.ofProfilerTask(ProfilerTask.PRESSURE_STALL_FULL_MEMORY);
new CounterSeriesTask(
"I/O pressure stall level",
"i/o pressure (full)",
CounterSeriesTask.Color.RAIL_ANIMATION);
private static final CounterSeriesTask PRESSURE_STALL_SOME_IO =
CounterSeriesTask.ofProfilerTask(ProfilerTask.PRESSURE_STALL_SOME_IO);
new CounterSeriesTask(
"I/O pressure stall level",
"i/o pressure (some)",
CounterSeriesTask.Color.CQ_BUILD_ATTEMPT_FAILED);
private static final CounterSeriesTask PRESSURE_STALL_FULL_MEMORY =
new CounterSeriesTask(
"Memory pressure stall level",
"memory pressure (full)",
CounterSeriesTask.Color.THREAD_STATE_UNKNOWN);
private static final CounterSeriesTask PRESSURE_STALL_SOME_MEMORY =
CounterSeriesTask.ofProfilerTask(ProfilerTask.PRESSURE_STALL_SOME_MEMORY);
new CounterSeriesTask(
"Memory pressure stall level",
"memory pressure (some)",
CounterSeriesTask.Color.RAIL_IDLE);
private static final CounterSeriesTask PRESSURE_STALL_SOME_CPU =
CounterSeriesTask.ofProfilerTask(ProfilerTask.PRESSURE_STALL_SOME_CPU);
new CounterSeriesTask(
"CPU pressure stall level",
"cpu pressure (some)",
CounterSeriesTask.Color.THREAD_STATE_RUNNING);

@Override
public List<List<CounterSeriesTask>> getStackedTaskGroups() {
Expand Down Expand Up @@ -518,34 +544,52 @@ private record SkyFunctionProfilerTasks(
ImmutableMap.of(
SkyFunctions.PACKAGE,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.PACKAGE_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(ProfilerTask.PACKAGE_SKYFUNCTION_DONE)),
new CounterSeriesTask(
"SkyFunction (PACKAGE)", "package (total)", /* color= */ null),
new CounterSeriesTask(
"SkyFunction (PACKAGE)", "package (done)", /* color= */ null)),
SkyFunctions.BZL_LOAD,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.BZL_LOAD_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(ProfilerTask.BZL_LOAD_SKYFUNCTION_DONE)),
new CounterSeriesTask(
"SkyFunction (BZL_LOAD)", "bzl_load (total)", /* color= */ null),
new CounterSeriesTask(
"SkyFunction (BZL_LOAD)", "bzl_load (done)", /* color= */ null)),
SkyFunctions.GLOB,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.GLOB_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(ProfilerTask.GLOB_SKYFUNCTION_DONE)),
new CounterSeriesTask("SkyFunction (GLOB)", "glob (total)", /* color= */ null),
new CounterSeriesTask("SkyFunction (GLOB)", "glob (done)", /* color= */ null)),
SkyFunctions.GLOBS,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.GLOBS_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(ProfilerTask.GLOBS_SKYFUNCTION_DONE)),
new CounterSeriesTask(
"SkyFunction (GLOBS)", "globs (total)", /* color= */ null),
new CounterSeriesTask(
"SkyFunction (GLOBS)", "globs (done)", /* color= */ null)),
SkyFunctions.CONFIGURED_TARGET,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.CONFIGURED_TARGET_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(
ProfilerTask.CONFIGURED_TARGET_SKYFUNCTION_DONE)),
new CounterSeriesTask(
"SkyFunction (CONFIGURED_TARGET)",
"configured target (total)",
/* color= */ null),
new CounterSeriesTask(
"SkyFunction (CONFIGURED_TARGET)",
"configured target (done)",
/* color= */ null)),
SkyFunctions.ASPECT,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.ASPECT_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(ProfilerTask.ASPECT_SKYFUNCTION_DONE)),
new CounterSeriesTask(
"SkyFunction (ASPECT)", "aspect (total)", /* color= */ null),
new CounterSeriesTask(
"SkyFunction (ASPECT)", "aspect (done)", /* color= */ null)),
SkyFunctions.ACTION_EXECUTION,
new SkyFunctionProfilerTasks(
CounterSeriesTask.ofProfilerTask(ProfilerTask.ACTION_EXECUTION_SKYFUNCTION),
CounterSeriesTask.ofProfilerTask(
ProfilerTask.ACTION_EXECUTION_SKYFUNCTION_DONE)));
new CounterSeriesTask(
"SkyFunction (ACTION_EXECUTION)",
"action execution (total)",
/* color= */ null),
new CounterSeriesTask(
"SkyFunction (ACTION_EXECUTION)",
"action execution (done)",
/* color= */ null)));

private final InMemoryGraph graph;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,66 @@
// limitations under the License.
package com.google.devtools.build.lib.profiler;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Map.entry;

import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;

/** Describes counter series to be logged into profile. */
public record CounterSeriesTask(String laneName, @Nullable String colorName, String seriesName) {
public static CounterSeriesTask ofProfilerTask(ProfilerTask profilerTask) {
checkState(
COUNTER_TASK_TO_SERIES_NAME.containsKey(profilerTask),
"COUNTER_TASK_TO_SERIES_NAME does not contain %s",
profilerTask);
/**
* Describes counter series to be logged into profile.
*
* @param laneName The lane name for the counter series. Series with the same lane name should be
* stacked when displaying.
* @param seriesName The name for the counter series.
* @param color The color for the counter series. If {@code null}, the profile viewer will pick a
* color automatically.
*/
public record CounterSeriesTask(String laneName, String seriesName, @Nullable Color color) {
/** The revered color for rendering the bar chart. */
public enum Color {
// Pick acceptable counter colors manually, unfortunately we have to pick from these
// weird reserved names from
// https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html
THREAD_STATE_UNINTERRUPTIBLE("thread_state_uninterruptible"),
THREAD_STATE_IOWAIT("thread_state_iowait"),
THREAD_STATE_RUNNING("thread_state_running"),
THREAD_STATE_RUNNABLE("thread_state_runnable"),
THREAD_STATE_SLEEPING("thread_state_sleeping"),
THREAD_STATE_UNKNOWN("thread_state_unknown"),
BACKGROUND_MEMORY_DUMP("background_memory_dump"),
LIGHT_MEMORY_DUMP("light_memory_dump"),
DETAILED_MEMORY_DUMP("detailed_memory_dump"),
VSYNC_HIGHLIGHT_COLOR("vsync_highlight_color"),
GENERIC_WORK("generic_work"),
GOOD("good"),
BAD("bad"),
TERRIBLE("terrible"),
BLACK("black"),
GREY("grey"),
WHITE("white"),
YELLOW("yellow"),
OLIVE("olive"),
RAIL_RESPONSE("rail_response"),
RAIL_ANIMATION("rail_animation"),
RAIL_IDLE("rail_idle"),
RAIL_LOAD("rail_load"),
STARTUP("startup"),
HEAP_DUMP_STACK_FRAME("heap_dump_stack_frame"),
HEAP_DUMP_OBJECT_TYPE("heap_dump_object_type"),
HEAP_DUMP_CHILD_NODE_ARROW("heap_dump_child_node_arrow"),
CQ_BUILD_RUNNING("cq_build_running"),
CQ_BUILD_PASSED("cq_build_passed"),
CQ_BUILD_FAILED("cq_build_failed"),
CQ_BUILD_ABANDONED("cq_build_abandoned"),
CQ_BUILD_ATTEMPT_RUNNIG("cq_build_attempt_runnig"),
CQ_BUILD_ATTEMPT_PASSED("cq_build_attempt_passed"),
CQ_BUILD_ATTEMPT_FAILED("cq_build_attempt_failed");

var laneName = profilerTask.description;
var seriesName = COUNTER_TASK_TO_SERIES_NAME.get(profilerTask);
var colorName = COUNTER_TASK_TO_COLOR.get(profilerTask);
return new CounterSeriesTask(laneName, colorName, seriesName);
}
private final String value;

private static final ImmutableMap<ProfilerTask, String> COUNTER_TASK_TO_SERIES_NAME =
ImmutableMap.ofEntries(
entry(ProfilerTask.ACTION_COUNTS, "action"),
entry(ProfilerTask.ACTION_CACHE_COUNTS, "local action cache"),
entry(ProfilerTask.LOCAL_ACTION_COUNTS, "local action"),
entry(ProfilerTask.LOCAL_CPU_USAGE, "cpu"),
entry(ProfilerTask.SYSTEM_CPU_USAGE, "system cpu"),
entry(ProfilerTask.LOCAL_MEMORY_USAGE, "memory"),
entry(ProfilerTask.SYSTEM_MEMORY_USAGE, "system memory"),
entry(ProfilerTask.SYSTEM_NETWORK_UP_USAGE, "system network up (Mbps)"),
entry(ProfilerTask.SYSTEM_NETWORK_DOWN_USAGE, "system network down (Mbps)"),
entry(ProfilerTask.WORKERS_MEMORY_USAGE, "workers memory"),
entry(ProfilerTask.SYSTEM_LOAD_AVERAGE, "load"),
entry(ProfilerTask.MEMORY_USAGE_ESTIMATION, "estimated memory"),
entry(ProfilerTask.CPU_USAGE_ESTIMATION, "estimated cpu"),
entry(ProfilerTask.PRESSURE_STALL_FULL_IO, "i/o pressure (full)"),
entry(ProfilerTask.PRESSURE_STALL_FULL_MEMORY, "memory pressure (full)"),
entry(ProfilerTask.PRESSURE_STALL_SOME_IO, "i/o pressure (some)"),
entry(ProfilerTask.PRESSURE_STALL_SOME_MEMORY, "memory pressure (some)"),
entry(ProfilerTask.PRESSURE_STALL_SOME_CPU, "cpu pressure (some)"),
entry(ProfilerTask.ACTION_EXECUTION_SKYFUNCTION, "action execution (total)"),
entry(ProfilerTask.ACTION_EXECUTION_SKYFUNCTION_DONE, "action execution (done)"),
entry(ProfilerTask.CONFIGURED_TARGET_SKYFUNCTION, "configured target (total)"),
entry(ProfilerTask.CONFIGURED_TARGET_SKYFUNCTION_DONE, "configured target (done)"),
entry(ProfilerTask.ASPECT_SKYFUNCTION, "aspect (total)"),
entry(ProfilerTask.ASPECT_SKYFUNCTION_DONE, "aspect (done)"),
entry(ProfilerTask.PACKAGE_SKYFUNCTION, "package (total)"),
entry(ProfilerTask.PACKAGE_SKYFUNCTION_DONE, "package (done)"),
entry(ProfilerTask.BZL_LOAD_SKYFUNCTION, "bzl_load (total)"),
entry(ProfilerTask.BZL_LOAD_SKYFUNCTION_DONE, "bzl_load (done)"),
entry(ProfilerTask.GLOB_SKYFUNCTION, "glob (total)"),
entry(ProfilerTask.GLOB_SKYFUNCTION_DONE, "glob (done)"),
entry(ProfilerTask.GLOBS_SKYFUNCTION, "globs (total)"),
entry(ProfilerTask.GLOBS_SKYFUNCTION_DONE, "globs (done)"));
private Color(String value) {
this.value = value;
}

// Pick acceptable counter colors manually, unfortunately we have to pick from these
// weird reserved names from
// https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html
private static final ImmutableMap<ProfilerTask, String> COUNTER_TASK_TO_COLOR =
ImmutableMap.ofEntries(
entry(ProfilerTask.LOCAL_ACTION_COUNTS, "detailed_memory_dump"),
entry(ProfilerTask.LOCAL_CPU_USAGE, "good"),
entry(ProfilerTask.SYSTEM_CPU_USAGE, "rail_load"),
entry(ProfilerTask.LOCAL_MEMORY_USAGE, "olive"),
entry(ProfilerTask.SYSTEM_MEMORY_USAGE, "bad"),
entry(ProfilerTask.SYSTEM_NETWORK_UP_USAGE, "rail_response"),
entry(ProfilerTask.SYSTEM_NETWORK_DOWN_USAGE, "rail_response"),
entry(ProfilerTask.WORKERS_MEMORY_USAGE, "rail_animation"),
entry(ProfilerTask.SYSTEM_LOAD_AVERAGE, "generic_work"),
entry(ProfilerTask.MEMORY_USAGE_ESTIMATION, "rail_idle"),
entry(ProfilerTask.CPU_USAGE_ESTIMATION, "cq_build_attempt_passed"),
entry(ProfilerTask.PRESSURE_STALL_FULL_IO, "rail_animation"),
entry(ProfilerTask.PRESSURE_STALL_SOME_IO, "cq_build_attempt_failed"),
entry(ProfilerTask.PRESSURE_STALL_FULL_MEMORY, "thread_state_unknown"),
entry(ProfilerTask.PRESSURE_STALL_SOME_MEMORY, "rail_idle"),
entry(ProfilerTask.PRESSURE_STALL_SOME_CPU, "thread_state_running"));
public String value() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ final class CounterSeriesTraceData implements TraceData {
len = entry.getValue().length;

this.displayName = task.laneName();
this.colorName = task.colorName();
if (task.color() != null) {
this.colorName = task.color().value();
}
} else {
// Check that second and subsequent series have the same length as the first.
Preconditions.checkState(len == entry.getValue().length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,14 @@ private void collectActionCounts() {
double[] actionCountValues = actionCountTimeSeries.toDoubleArray(len);
actionCountTimeSeriesRef.set(null);
counterSeriesMap.put(
CounterSeriesTask.ofProfilerTask(ProfilerTask.ACTION_COUNTS), actionCountValues);
new CounterSeriesTask("action count", "action", /* color= */ null), actionCountValues);
}
TimeSeries actionCacheCountTimeSeries = actionCacheCountTimeSeriesRef.get();
if (actionCacheCountTimeSeries != null) {
double[] actionCacheCountValues = actionCacheCountTimeSeries.toDoubleArray(len);
actionCacheCountTimeSeriesRef.set(null);
counterSeriesMap.put(
CounterSeriesTask.ofProfilerTask(ProfilerTask.ACTION_CACHE_COUNTS),
new CounterSeriesTask("action cache count", "local action cache", /* color= */ null),
actionCacheCountValues);
}
if (!counterSeriesMap.isEmpty()) {
Expand All @@ -552,7 +552,8 @@ private void collectActionCounts() {
double[] localActionCountValues = localActionCountTimeSeries.toDoubleArray(len);
localActionCountTimeSeriesRef.set(null);
localCounterSeriesMap.put(
CounterSeriesTask.ofProfilerTask(ProfilerTask.LOCAL_ACTION_COUNTS),
new CounterSeriesTask(
"action count (local)", "local action", CounterSeriesTask.Color.DETAILED_MEMORY_DUMP),
localActionCountValues);
}
if (hasNonZeroValues(localCounterSeriesMap)) {
Expand Down
Loading

0 comments on commit 94b72e4

Please sign in to comment.