Skip to content

Commit e2c5939

Browse files
lberkicopybara-github
authored andcommitted
Keep original description if it is the same for all merged events.
RELNOTES: None. PiperOrigin-RevId: 785383007 Change-Id: Iec05a90b3ec596348b265d4d3aba6d689c142661
1 parent d76cd27 commit e2c5939

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ private static final class MergedEvent {
123123
long startTimeNanos;
124124
long endTimeNanos;
125125
TaskData data;
126+
@Nullable String description; // Null if merged events have different descriptions
126127

127128
/*
128129
* Tries to merge an additional event, i.e. if the event is close enough to the already merged
@@ -142,19 +143,24 @@ TaskData maybeMerge(TaskData data) {
142143
}
143144
if (count == 0) {
144145
this.data = data;
146+
this.description = data.description;
145147
this.startTimeNanos = startTimeNanos;
146148
this.endTimeNanos = endTimeNanos;
147149
count++;
148150
return null;
149151
} else if (startTimeNanos <= this.endTimeNanos + SLIM_PROFILE_MAXIMAL_PAUSE_NS) {
152+
if (!data.description.equals(description)) {
153+
description = null;
154+
}
150155
this.endTimeNanos = endTimeNanos;
151156
count++;
152157
return null;
153158
} else {
154159
TaskData ret = getAndReset();
160+
this.data = data;
161+
this.description = data.description;
155162
this.startTimeNanos = startTimeNanos;
156163
this.endTimeNanos = endTimeNanos;
157-
this.data = data;
158164
count = 1;
159165
return ret;
160166
}
@@ -166,12 +172,18 @@ TaskData getAndReset() {
166172
if (data == null || count <= 1) {
167173
ret = data;
168174
} else {
175+
String mergedDescription;
176+
if (description != null) {
177+
mergedDescription = String.format("%dx %s", count, description);
178+
} else {
179+
mergedDescription = String.format("%dx various events", count);
180+
}
169181
ret =
170182
new TaskData(
171183
data.threadId,
172184
this.startTimeNanos,
173185
this.endTimeNanos - this.startTimeNanos,
174-
"merged " + count + " events");
186+
mergedDescription);
175187
}
176188
count = 0;
177189
data = null;

src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,11 @@ private ByteArrayOutputStream getJsonProfileOutputStream(boolean slimProfile) th
10481048
public void testSlimProfileSize() throws Exception {
10491049
ByteArrayOutputStream fatOutputStream = getJsonProfileOutputStream(/* slimProfile= */ false);
10501050
String fatOutput = fatOutputStream.toString();
1051-
assertThat(fatOutput).doesNotContain("merged");
1051+
assertThat(fatOutput).doesNotContain("x foo");
10521052

10531053
ByteArrayOutputStream slimOutputStream = getJsonProfileOutputStream(/* slimProfile= */ true);
10541054
String slimOutput = slimOutputStream.toString();
1055-
assertThat(slimOutput).contains("merged");
1055+
assertThat(slimOutput).contains("x foo");
10561056

10571057
long fatProfileLen = fatOutputStream.size();
10581058
long slimProfileLen = slimOutputStream.size();

0 commit comments

Comments
 (0)