Commit 96458105 authored by Bartek Nowierski's avatar Bartek Nowierski Committed by Commit Bot

Introduce and emit "function calls in detached window" use counters.

NOTE! This re-introduces the following change with a modification that
detached_window_time_in_seconds is initialized with 0, instead of
current time.
https://chromium-review.googlesource.com/c/v8/v8/+/1924000

Bug: chromium:1018156
Change-Id: I6d0880e0355d2cb08dbf4f2ef92c8fcead03f9ad
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1958344Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65393}
parent d406bfd6
......@@ -8237,6 +8237,18 @@ class V8_EXPORT Isolate {
kRegExpReplaceCalledOnSlowRegExp = 80,
kDisplayNames = 81,
kSharedArrayBufferConstructed = 82,
// Temporary kCallInDetachedWindowBy* counters are for reporting function
// calls within contexts marked using |SetDetachedWindowReason|.
// TODO(bartekn,chromium:1018156): Remove once not needed.
kCallInDetachedWindowByNavigation = 83,
kCallInDetachedWindowByNavigationAfter10s = 84,
kCallInDetachedWindowByNavigationAfter1min = 85,
kCallInDetachedWindowByClosing = 86,
kCallInDetachedWindowByClosingAfter10s = 87,
kCallInDetachedWindowByClosingAfter1min = 88,
kCallInDetachedWindowByOtherReason = 89,
kCallInDetachedWindowByOtherReasonAfter10s = 90,
kCallInDetachedWindowByOtherReasonAfter1min = 91,
// If you add new values here, you'll also need to update Chromium's:
// web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
......
......@@ -503,6 +503,16 @@ STATIC_ASSERT(NativeContext::kSize ==
void NativeContext::SetDetachedWindowReason(
v8::Context::DetachedWindowReason reason) {
set_detached_window_reason(Smi::FromEnum(reason));
Isolate* isolate = GetIsolate();
// kWindowNotDetached is used when initializing. Don't initialize to time
// based value due to build artifact inconsistency (see crbug/1029863).
// It's safe to use 0, because the value isn't used in the kWindowNotDetached
// case.
set_detached_window_time_in_seconds(Smi::FromInt(
reason == v8::Context::kWindowNotDetached
? 0
: static_cast<int>(isolate->time_millis_since_init() / 1000)));
}
v8::Context::DetachedWindowReason NativeContext::GetDetachedWindowReason()
......@@ -511,5 +521,12 @@ v8::Context::DetachedWindowReason NativeContext::GetDetachedWindowReason()
detached_window_reason().value());
}
int NativeContext::SecondsSinceDetachedWindow() const {
DCHECK(detached_window_reason().value() != v8::Context::kWindowNotDetached);
Isolate* isolate = GetIsolate();
return static_cast<int>(isolate->time_millis_since_init() / 1000 -
detached_window_time_in_seconds().value());
}
} // namespace internal
} // namespace v8
......@@ -369,6 +369,7 @@ enum ContextLookupFlags {
V(WEAKSET_ADD_INDEX, JSFunction, weakset_add) \
V(OSR_CODE_CACHE_INDEX, WeakFixedArray, osr_code_cache) \
V(DETACHED_WINDOW_REASON_INDEX, Smi, detached_window_reason) \
V(DETACHED_WINDOW_TIME_INDEX, Smi, detached_window_time_in_seconds) \
NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V)
// A table of all script contexts. Every loaded top-level script with top-level
......@@ -734,6 +735,8 @@ class NativeContext : public Context {
void SetDetachedWindowReason(v8::Context::DetachedWindowReason reason);
v8::Context::DetachedWindowReason GetDetachedWindowReason() const;
// This can be off up to 1s in each direction.
int SecondsSinceDetachedWindow() const;
private:
STATIC_ASSERT(OffsetOfElementAt(EMBEDDER_DATA_INDEX) ==
......
......@@ -87,9 +87,38 @@ RUNTIME_FUNCTION(Runtime_ReportDetachedWindowAccess) {
DCHECK_EQ(0, args.length());
Handle<NativeContext> native_context(isolate->context().native_context(),
isolate);
// TODO(bartekn,chromium:1018156): Report this to Blink, for it to emit it
// via UKM. Use native_context->detached_window_reason().value()
// This will be addressed as the first step after this CL lands.
v8::Isolate::UseCounterFeature counter_main;
v8::Isolate::UseCounterFeature counter_10s;
v8::Isolate::UseCounterFeature counter_1min;
switch (native_context->GetDetachedWindowReason()) {
case v8::Context::kWindowNotDetached:
// We should never get here. Just exit early in case we do.
return ReadOnlyRoots(isolate).undefined_value();
case v8::Context::kDetachedWindowByNavigation:
counter_main = v8::Isolate::kCallInDetachedWindowByNavigation;
counter_10s = v8::Isolate::kCallInDetachedWindowByNavigationAfter10s;
counter_1min = v8::Isolate::kCallInDetachedWindowByNavigationAfter1min;
break;
case v8::Context::kDetachedWindowByClosing:
counter_main = v8::Isolate::kCallInDetachedWindowByClosing;
counter_10s = v8::Isolate::kCallInDetachedWindowByClosingAfter10s;
counter_1min = v8::Isolate::kCallInDetachedWindowByClosingAfter1min;
break;
case v8::Context::kDetachedWindowByOtherReason:
counter_main = v8::Isolate::kCallInDetachedWindowByOtherReason;
counter_10s = v8::Isolate::kCallInDetachedWindowByOtherReasonAfter10s;
counter_1min = v8::Isolate::kCallInDetachedWindowByOtherReasonAfter1min;
break;
}
isolate->CountUsage(counter_main);
// This can be off by up to 1s in each direction, but that's ok.
int secs_passed = native_context->SecondsSinceDetachedWindow();
if (secs_passed >= 10) {
isolate->CountUsage(counter_10s);
}
if (secs_passed >= 60) {
isolate->CountUsage(counter_1min);
}
// The return value isn't needed, but RUNTIME_FUNCTION sets it up.
return ReadOnlyRoots(isolate).undefined_value();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment