Collect sample with trace id in inspector_trace_events::SetCallStack
This is a cheaper way to collect a stack trace at the moment a
trace event is dispatched (vs using CaptureSourceLocation, which
requires sync stack symbolization). We can use this stack trace data
to help us improve the trace events + cpu samples consolidation in the
Performance panel in DevTools.
As follow up work we should:
1. Use the helper in other events (e.g. performance.measure / mark)
2. Remove the usage of CaptureSourceLocation in the helper, since it is
considerably more expensive than collecting a marked sample and we
wouldn't need it now (if the risk/cost of breaking backwards compat is
low enough).
(see https://docs.google.com/document/d/1XTCUflYvxjHitBbnHeTzQQjipPIY4hilQ8iG06BilRk/edit?tab=t.0 for more context)
Bug: 396355813
Change-Id: I4330a38fb01b3551b36970942cc37fb605630c43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6288548
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Commit-Queue: Andres Olivares <andoli@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1424470}
diff --git a/third_party/blink/renderer/core/inspector/inspector_trace_events.cc b/third_party/blink/renderer/core/inspector/inspector_trace_events.cc
index be4a963..079c04df 100644
--- a/third_party/blink/renderer/core/inspector/inspector_trace_events.cc
+++ b/third_party/blink/renderer/core/inspector/inspector_trace_events.cc
@@ -8,6 +8,7 @@
#include <memory>
+#include "base/trace_event/trace_id_helper.h"
#include "cc/layers/picture_layer.h"
#include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/capture_source_location.h"
@@ -123,9 +124,15 @@
// So we collect the top frame with CaptureSourceLocation() to
// get the binding call site info.
auto source_location = CaptureSourceLocation();
+ uint64_t sample_trace_id = base::trace_event::GetNextGlobalTraceId();
+ // Bit mask the 64-bit sample trace id to 53 bits to allow it to be
+ // used in JavaScript trace clients (e.g. DevTools).
+ uint64_t mask = ((1ULL << 53) - 1);
+ sample_trace_id = sample_trace_id & mask;
+ dict.Add("sampleTraceId", sample_trace_id);
if (source_location->HasStackTrace())
dict.Add("stackTrace", source_location);
- v8::CpuProfiler::CollectSample(isolate);
+ v8::CpuProfiler::CollectSample(isolate, sample_trace_id);
}
void InspectorTraceEvents::WillSendRequest(