Skip to content

Commit 6d1dd4e

Browse files
meisterTcopybara-github
authored andcommitted
RELNOTES[INC]: JSON profile: Use doubles instead of strings for counter 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
1 parent ba6fcbc commit 6d1dd4e

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/main/java/com/google/devtools/build/lib/profiler/Profiler.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,16 @@ Iterable<SlowTask> getSlowestTasks() {
255255
}
256256
}
257257

258-
// TODO(twerth): Make use of counterValue directly in a follow-up change.
259258
private static final class CounterData extends TaskData {
259+
private final double counterValue;
260+
260261
public CounterData(long timeNanos, ProfilerTask type, double counterValue) {
261262
super(/* id= */ -1, timeNanos, type, String.valueOf(counterValue));
263+
this.counterValue = counterValue;
264+
}
265+
266+
public double getCounterValue() {
267+
return counterValue;
262268
}
263269
}
264270

@@ -1211,8 +1217,10 @@ public void run() {
12111217
}
12121218

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

12381246
writer.beginObject();
1239-
writer.name(COUNTER_TASK_TO_SERIES_NAME.get(data.type)).value(data.description);
1247+
writer
1248+
.name(COUNTER_TASK_TO_SERIES_NAME.get(data.type))
1249+
.value(counterData.getCounterValue());
12401250
writer.endObject();
12411251

12421252
writer.endObject();

src/test/shell/integration/profiler_test.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ EOF
7474

7575
function test_metrics() {
7676
helper "" ""
77-
expect_log 'CPU usage (Bazel).*"cpu":"[0-9.]\+"'
78-
expect_log 'CPU usage (total).*"system cpu":"[0-9.]\+"'
79-
expect_log 'Memory usage (Bazel).*"memory":"[0-9.]\+"'
80-
expect_log 'Memory usage (total).*"system memory":"[0-9.]\+"'
77+
expect_log 'CPU usage (Bazel).*"cpu":[0-9.]\+'
78+
expect_log 'CPU usage (total).*"system cpu":[0-9.]\+'
79+
expect_log 'Memory usage (Bazel).*"memory":[0-9.]\+'
80+
expect_log 'Memory usage (total).*"system memory":[0-9.]\+'
8181
}
8282

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

8888
run_suite "Integration tests for profiler data."

0 commit comments

Comments
 (0)