Skip to content

Commit a0cb57f

Browse files
authored
[6.2.0] profile: add profile_finish_ts (#18129)
"date" field in Bazel json profile is a confusing field. It uses Java Date.toString() output which includes local timezone that could be hard to parse. The name is misleading since users could mistook it for profile start time, while it actually means the finish/end time, when Bazel calls the writer to serialize profiling data to disk. Add "profile_finish_ts" which has a clearer name and more consistent value with the time unit being used in the rest of the JSON profile(microseconds). We shall deprecate the "date" field in a separate patch in a major release.
1 parent 3687b56 commit a0cb57f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

site/en/rules/performance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ Example:
278278
"otherData": {
279279
"build_id": "101bff9a-7243-4c1a-8503-9dc6ae4c3b05",
280280
"date": "Tue Jun 16 08:30:21 CEST 2020",
281+
"profile_finish_ts": "1677666095162000",
281282
"output_base": "/usr/local/google/_bazel_johndoe/573d4be77eaa72b91a3dfaa497bf8cd0"
282283
},
283284
"traceEvents": [

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.lang.management.ManagementFactory;
4040
import java.nio.charset.StandardCharsets;
4141
import java.time.Duration;
42+
import java.time.Instant;
4243
import java.util.ArrayList;
4344
import java.util.Arrays;
4445
import java.util.Date;
@@ -1086,13 +1087,15 @@ public void run() {
10861087
// The buffer size of 262144 is chosen at random.
10871088
new OutputStreamWriter(
10881089
new BufferedOutputStream(outStream, 262144), StandardCharsets.UTF_8))) {
1090+
var finishDate = Instant.now();
10891091
writer.beginObject();
10901092
writer.name("otherData");
10911093
writer.beginObject();
10921094
writer.name("bazel_version").value(BlazeVersionInfo.instance().getReleaseName());
10931095
writer.name("build_id").value(buildID.toString());
10941096
writer.name("output_base").value(outputBase);
1095-
writer.name("date").value(new Date().toString());
1097+
writer.name("date").value(finishDate.toString());
1098+
writer.name("profile_finish_ts").value(finishDate.getEpochSecond() * 1000);
10961099
writer.endObject();
10971100
writer.name("traceEvents");
10981101
writer.beginArray();

0 commit comments

Comments
 (0)