Skip to content

Commit

Permalink
RELNOTES[INC]: JSON profile: Use doubles instead of strings for count…
Browse files Browse the repository at this point in the history
…er series.

Chrome Tracing can render stacked counter series, but only handles them correctly if values are doubles (and not strings).

We want to stack action count and local action cache checks, as well as CPU usage and memory usages.

PiperOrigin-RevId: 496331067
Change-Id: I1370856c1d1f68781bde1cc68286f71a64e1a180
  • Loading branch information
meisterT authored and Copybara-Service committed Dec 19, 2022
1 parent ba6fcbc commit 6d1dd4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
Expand Up @@ -255,10 +255,16 @@ Iterable<SlowTask> getSlowestTasks() {
}
}

// TODO(twerth): Make use of counterValue directly in a follow-up change.
private static final class CounterData extends TaskData {
private final double counterValue;

public CounterData(long timeNanos, ProfilerTask type, double counterValue) {
super(/* id= */ -1, timeNanos, type, String.valueOf(counterValue));
this.counterValue = counterValue;
}

public double getCounterValue() {
return counterValue;
}
}

Expand Down Expand Up @@ -1211,8 +1217,10 @@ public void run() {
}

if (COUNTER_TASK_TO_SERIES_NAME.containsKey(data.type)) {
Preconditions.checkArgument(data instanceof CounterData);
CounterData counterData = (CounterData) data;
// Skip counts equal to zero. They will show up as a thin line in the profile.
if ("0.0".equals(data.description)) {
if (Math.abs(counterData.getCounterValue()) <= 0.00001) {
continue;
}
writer.setIndent(" ");
Expand All @@ -1236,7 +1244,9 @@ public void run() {
writer.name("args");

writer.beginObject();
writer.name(COUNTER_TASK_TO_SERIES_NAME.get(data.type)).value(data.description);
writer
.name(COUNTER_TASK_TO_SERIES_NAME.get(data.type))
.value(counterData.getCounterValue());
writer.endObject();

writer.endObject();
Expand Down
10 changes: 5 additions & 5 deletions src/test/shell/integration/profiler_test.sh
Expand Up @@ -74,15 +74,15 @@ EOF

function test_metrics() {
helper "" ""
expect_log 'CPU usage (Bazel).*"cpu":"[0-9.]\+"'
expect_log 'CPU usage (total).*"system cpu":"[0-9.]\+"'
expect_log 'Memory usage (Bazel).*"memory":"[0-9.]\+"'
expect_log 'Memory usage (total).*"system memory":"[0-9.]\+"'
expect_log 'CPU usage (Bazel).*"cpu":[0-9.]\+'
expect_log 'CPU usage (total).*"system cpu":[0-9.]\+'
expect_log 'Memory usage (Bazel).*"memory":[0-9.]\+'
expect_log 'Memory usage (total).*"system memory":[0-9.]\+'
}

function test_metrics_with_load_average() {
helper "" "--experimental_collect_load_average_in_profiler"
expect_log 'System load average.*"load":"[0-9.]\+"'
expect_log 'System load average.*"load":[0-9.]\+'
}

run_suite "Integration tests for profiler data."

0 comments on commit 6d1dd4e

Please sign in to comment.