From cbae4a4b9ba4144772818bca81338665c58657ff Mon Sep 17 00:00:00 2001 From: Son Luong Ngoc Date: Sun, 16 Apr 2023 11:05:12 +0200 Subject: [PATCH] profile: add profile_finish_ts "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. --- site/en/advanced/performance/json-trace-profile.md | 1 + .../devtools/build/lib/profiler/JsonTraceFileWriter.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/site/en/advanced/performance/json-trace-profile.md b/site/en/advanced/performance/json-trace-profile.md index 732a87dd420dc4..9589c3159b0171 100644 --- a/site/en/advanced/performance/json-trace-profile.md +++ b/site/en/advanced/performance/json-trace-profile.md @@ -168,6 +168,7 @@ Example: "otherData": { "build_id": "101bff9a-7243-4c1a-8503-9dc6ae4c3b05", "date": "Wed Oct 26 08:22:35 CEST 2022", + "profile_finish_ts": "1677666095162000", "output_base": "/usr/local/google/_bazel_johndoe/573d4be77eaa72b91a3dfaa497bf8cd0" }, "traceEvents": [ diff --git a/src/main/java/com/google/devtools/build/lib/profiler/JsonTraceFileWriter.java b/src/main/java/com/google/devtools/build/lib/profiler/JsonTraceFileWriter.java index d55daf9c4851d9..ed0e18c9299172 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/JsonTraceFileWriter.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/JsonTraceFileWriter.java @@ -24,6 +24,7 @@ import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.time.Instant; import java.util.Date; import java.util.HashMap; import java.util.UUID; @@ -172,13 +173,15 @@ public void run() { // The buffer size of 262144 is chosen at random. new OutputStreamWriter( new BufferedOutputStream(outStream, 262144), StandardCharsets.UTF_8))) { + var finishDate = Instant.now(); writer.beginObject(); writer.name("otherData"); writer.beginObject(); writer.name("bazel_version").value(BlazeVersionInfo.instance().getReleaseName()); writer.name("build_id").value(buildID.toString()); writer.name("output_base").value(outputBase); - writer.name("date").value(new Date().toString()); + writer.name("date").value(finishDate.toString()); + writer.name("profile_finish_ts").value(finishDate.getEpochSecond() * 1000); writer.endObject(); writer.name("traceEvents"); writer.beginArray();