Skip to content

Instantly share code, notes, and snippets.

@alexnj
Last active April 10, 2023 23:16
Show Gist options
  • Save alexnj/6c040056a151280765a2477254825333 to your computer and use it in GitHub Desktop.
Save alexnj/6c040056a151280765a2477254825333 to your computer and use it in GitHub Desktop.
Patch adding detail to perf measures
diff --git a/third_party/blink/renderer/core/timing/performance_user_timing.cc b/third_party/blink/renderer/core/timing/performance_user_timing.cc
index 1056e5c6f04d7..3f7a36ba36450 100644
--- a/third_party/blink/renderer/core/timing/performance_user_timing.cc
+++ b/third_party/blink/renderer/core/timing/performance_user_timing.cc
@@ -210,12 +210,28 @@ PerformanceMeasure* UserTiming::Measure(ScriptState* script_state,
WTF::AddFloatToHash(hash, start_time);
WTF::AddFloatToHash(hash, end_time);
+ v8::Local<v8::Context> context =
+ performance_->GetExecutionContext()->GetIsolate()->GetCurrentContext();
+ String serialized_detail = "";
+ if (!detail.V8Value()->IsNullOrUndefined()) {
+ v8::Local<v8::String> v8_string;
+ if (v8::JSON::Stringify(context, detail.V8Value()).ToLocal(&v8_string)) {
+ serialized_detail = ToCoreString(v8_string);
+ }
+ }
+
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP1(
"blink.user_timing", measure_name.Utf8().c_str(), hash,
unsafe_start_time, "startTime", start_time);
- TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
- "blink.user_timing", measure_name.Utf8().c_str(), hash,
- unsafe_end_time);
+ if (serialized_detail.length()) {
+ TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP1(
+ "blink.user_timing", measure_name.Utf8().c_str(), hash,
+ unsafe_end_time, "serialized_detail", serialized_detail);
+ } else {
+ TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
+ "blink.user_timing", measure_name.Utf8().c_str(), hash,
+ unsafe_end_time);
+ }
}
PerformanceMeasure* measure =
diff --git a/third_party/blink/web_tests/inspector-protocol/timeline/user-timing-expected.txt b/third_party/blink/web_tests/inspector-protocol/timeline/user-timing-expected.txt
index 022ce7fb3734a..cbeea2b596e39 100644
--- a/third_party/blink/web_tests/inspector-protocol/timeline/user-timing-expected.txt
+++ b/third_party/blink/web_tests/inspector-protocol/timeline/user-timing-expected.txt
@@ -1,14 +1,17 @@
Tests render blocking status in script traces.
Recording started
Tracing complete
+first to third
+"detail of first to third"
+first to third-2
+{"name":"test","v":1}
+first to third-2
+first to third
now to first
now
now to first
first to second
-first to third
first
first to second
second
-first to third
third
-
diff --git a/third_party/blink/web_tests/inspector-protocol/timeline/user-timing.js b/third_party/blink/web_tests/inspector-protocol/timeline/user-timing.js
index cbb8fc54cbc55..674cb05887f90 100644
--- a/third_party/blink/web_tests/inspector-protocol/timeline/user-timing.js
+++ b/third_party/blink/web_tests/inspector-protocol/timeline/user-timing.js
@@ -23,17 +23,24 @@
performance.mark("third");
performance.measure("now to first", "now", "first");
performance.measure("first to second", "first", "second");
- performance.measure("first to third", "first", "third");
+ performance.measure("first to third", {
+ detail: "detail of first to third",
+ start: 10, end: 25});
+ performance.measure("first to third-2", {
+ detail: {name: "test", v: 1},
+ start: 20, end: 25});
})();
`);
const events = await tracingHelper.stopTracing(/blink.user_timing/);
const sorted_events = events.sort((a, b) => {
- return (a["ts"] - b["ts"]);
+ return a["ts"] - b["ts"];
});
for (let e of sorted_events) {
testRunner.log(e["name"]);
+ if (e.args?.["serialized_detail"])
+ testRunner.log(e.args?.["serialized_detail"]);
}
testRunner.completeTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment