Commit 7990a606 authored by Simon Zünd's avatar Simon Zünd Committed by V8 LUCI CQ

[inspector] Remove initial version of the async stack tagging API

The intial version of the API was replaced with a more ergonomic one
recently.

We can also safely remove the test as the new API guarantees that
tasks are always finished and cancelled.

Bug: chromium:1334585
Change-Id: I9ff8b92fcd73ef821c86de52c40a1d04b15ea918
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3780539Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81950}
parent 2253d9c5
...@@ -488,104 +488,6 @@ void V8Console::memorySetterCallback( ...@@ -488,104 +488,6 @@ void V8Console::memorySetterCallback(
// setter just ignores the passed value. http://crbug.com/468611 // setter just ignores the passed value. http://crbug.com/468611
} }
v8::Maybe<int64_t> V8Console::ValidateAndGetTaskId(
const v8::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() != 1) {
info.GetIsolate()->ThrowError("Unexpected arguments");
return v8::Nothing<int64_t>();
}
int64_t argId;
if (!info[0]->IsNumber() ||
!v8::Just(info[0].As<v8::Integer>()->Value()).To(&argId)) {
info.GetIsolate()->ThrowError("Task ID should be an integer");
return v8::Nothing<int64_t>();
}
auto it = m_asyncTaskIds.find(argId);
if (it == m_asyncTaskIds.end()) {
info.GetIsolate()->ThrowError("Task with ID doesn't exist");
return v8::Nothing<int64_t>();
}
return v8::Just(argId);
}
void V8Console::scheduleAsyncTask(
const v8::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() != 1 && info.Length() != 2) {
info.GetIsolate()->ThrowError("Unexpected arguments");
return;
}
if (info.Length() == 2 && !info[1]->IsBoolean()) {
info.GetIsolate()->ThrowError("Unexpected arguments");
return;
}
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, v8::debug::ConsoleContext(), m_inspector);
String16 argName = helper.firstArgToString(String16());
bool recurring =
info.Length() == 2 ? info[1].As<v8::Boolean>()->Value() : false;
int64_t id = m_taskIdCounter++;
auto it = m_asyncTaskIds.find(id);
if (it != m_asyncTaskIds.end()) {
info.GetIsolate()->ThrowError("Task with ID already exists");
return;
}
AsyncTaskInfo taskInfo;
taskInfo.ptr = new int();
taskInfo.recurring = recurring;
m_asyncTaskIds.emplace(id, taskInfo);
StringView taskName = StringView(argName.characters16(), argName.length());
m_inspector->asyncTaskScheduled(taskName, taskInfo.ptr, recurring);
info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), id));
}
void V8Console::startAsyncTask(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Maybe<int64_t> maybeArgId = ValidateAndGetTaskId(info);
if (maybeArgId.IsNothing()) return;
int64_t taskId = maybeArgId.FromJust();
AsyncTaskInfo taskInfo = m_asyncTaskIds[taskId];
m_inspector->asyncTaskStarted(taskInfo.ptr);
}
void V8Console::finishAsyncTask(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Maybe<int64_t> maybeArgId = ValidateAndGetTaskId(info);
if (maybeArgId.IsNothing()) return;
int64_t taskId = maybeArgId.FromJust();
AsyncTaskInfo taskInfo = m_asyncTaskIds[taskId];
m_inspector->asyncTaskFinished(taskInfo.ptr);
if (taskInfo.recurring) {
return;
}
delete taskInfo.ptr;
m_asyncTaskIds.erase(taskId);
}
void V8Console::cancelAsyncTask(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Maybe<int64_t> maybeArgId = ValidateAndGetTaskId(info);
if (maybeArgId.IsNothing()) return;
int64_t taskId = maybeArgId.FromJust();
AsyncTaskInfo taskInfo = m_asyncTaskIds[taskId];
m_inspector->asyncTaskCanceled(taskInfo.ptr);
delete taskInfo.ptr;
m_asyncTaskIds.erase(taskId);
}
void V8Console::scheduleTask(const v8::FunctionCallbackInfo<v8::Value>& info) { void V8Console::scheduleTask(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate(); v8::Isolate* isolate = info.GetIsolate();
if (info.Length() < 1 || !info[0]->IsString() || if (info.Length() < 1 || !info[0]->IsString() ||
...@@ -921,38 +823,6 @@ void V8Console::installAsyncStackTaggingAPI(v8::Local<v8::Context> context, ...@@ -921,38 +823,6 @@ void V8Console::installAsyncStackTaggingAPI(v8::Local<v8::Context> context,
v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope microtasksScope(isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks); v8::MicrotasksScope::kDoNotRunMicrotasks);
console
->Set(context, toV8StringInternalized(isolate, "scheduleAsyncTask"),
v8::Function::New(context,
&V8Console::call<&V8Console::scheduleAsyncTask>,
data, 0, v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect)
.ToLocalChecked())
.Check();
console
->Set(context, toV8StringInternalized(isolate, "startAsyncTask"),
v8::Function::New(context,
&V8Console::call<&V8Console::startAsyncTask>,
data, 0, v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect)
.ToLocalChecked())
.Check();
console
->Set(context, toV8StringInternalized(isolate, "finishAsyncTask"),
v8::Function::New(context,
&V8Console::call<&V8Console::finishAsyncTask>,
data, 0, v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect)
.ToLocalChecked())
.Check();
console
->Set(context, toV8StringInternalized(isolate, "cancelAsyncTask"),
v8::Function::New(context,
&V8Console::call<&V8Console::cancelAsyncTask>,
data, 0, v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect)
.ToLocalChecked())
.Check();
console console
->Set( ->Set(
context, toV8StringInternalized(isolate, "scheduleTask"), context, toV8StringInternalized(isolate, "scheduleTask"),
......
...@@ -63,11 +63,6 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -63,11 +63,6 @@ class V8Console : public v8::debug::ConsoleDelegate {
v8::Local<v8::ArrayBuffer> m_thisReference; v8::Local<v8::ArrayBuffer> m_thisReference;
}; };
struct AsyncTaskInfo {
int* ptr;
bool recurring;
};
explicit V8Console(V8InspectorImpl* inspector); explicit V8Console(V8InspectorImpl* inspector);
private: private:
...@@ -146,12 +141,6 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -146,12 +141,6 @@ class V8Console : public v8::debug::ConsoleDelegate {
void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
v8::Maybe<int64_t> ValidateAndGetTaskId(
const v8::FunctionCallbackInfo<v8::Value>&);
void scheduleAsyncTask(const v8::FunctionCallbackInfo<v8::Value>&);
void startAsyncTask(const v8::FunctionCallbackInfo<v8::Value>&);
void finishAsyncTask(const v8::FunctionCallbackInfo<v8::Value>&);
void cancelAsyncTask(const v8::FunctionCallbackInfo<v8::Value>&);
void scheduleTask(const v8::FunctionCallbackInfo<v8::Value>&); void scheduleTask(const v8::FunctionCallbackInfo<v8::Value>&);
void runTask(const v8::FunctionCallbackInfo<v8::Value>&); void runTask(const v8::FunctionCallbackInfo<v8::Value>&);
...@@ -209,14 +198,6 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -209,14 +198,6 @@ class V8Console : public v8::debug::ConsoleDelegate {
V8InspectorImpl* m_inspector; V8InspectorImpl* m_inspector;
// A map of unique pointers used for the scheduling and joining async stacks.
// The async stack traces instrumentation is exposed on the console object,
// behind a --experimental-async-stack-tagging-api flag. For now, it serves
// as a prototype that aims to validate whether the debugging experience can
// be improved for userland code that uses custom schedulers.
int64_t m_taskIdCounter = 0;
std::map<int64_t, AsyncTaskInfo> m_asyncTaskIds;
// All currently alive tasks. We mark tasks immediately as weak when created // All currently alive tasks. We mark tasks immediately as weak when created
// but we need the finalizer to cancel the task when GC cleans them up. // but we need the finalizer to cancel the task when GC cleans them up.
std::map<void*, std::unique_ptr<TaskInfo>> m_tasks; std::map<void*, std::unique_ptr<TaskInfo>> m_tasks;
......
Clear the async stack on navigations
---------- console.trace: 0 ----------
bar (test.js:7:10)
(anonymous) (test.js:12:0)
-- foo --
foo (test.js:2:17)
(anonymous) (test.js:12:4)
---------- console.trace: 1 ----------
bar (test.js:7:10)
(anonymous) (test.js:12:0)
-- foo --
foo (test.js:2:17)
(anonymous) (test.js:12:4)
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --experimental-async-stack-tagging-api
const {session, contextGroup, Protocol} = InspectorTest.start('Clear the async stack on navigations');
const script = `
function foo() {
return console.scheduleAsyncTask("foo", true);
}
function bar(id) {
console.startAsyncTask(id);
console.trace(id); // When context is reset, this trace gets broken.
// no finish
console.cancelAsyncTask(id);
}
bar(foo());
`;
session.setupScriptMap();
(async () => {
Protocol.Runtime.onConsoleAPICalled(({params}) => {
InspectorTest.log(`---------- console.${params.type}: ${params.args[0].value} ----------`);
session.logCallFrames(params.stackTrace.callFrames);
session.logAsyncStackTrace(params.stackTrace.parent);
});
await Protocol.Runtime.enable();
await Protocol.Debugger.enable();
await Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 });
contextGroup.addScript(script, 0, 0, 'test.js');
await Protocol.Debugger.onceScriptParsed();
contextGroup.reset();
// Run the same script again and make sure that the task stack has been reset.
contextGroup.addScript(script, 0, 0, 'test.js');
await Protocol.Debugger.onceScriptParsed();
InspectorTest.completeTest();
})();
...@@ -217,7 +217,6 @@ ...@@ -217,7 +217,6 @@
'regress/regress-crbug-1197392': [SKIP], 'regress/regress-crbug-1197392': [SKIP],
'debugger/command-line-api-with-arrow-function': [SKIP], 'debugger/command-line-api-with-arrow-function': [SKIP],
'regress/regress-crbug-1199919': [SKIP], 'regress/regress-crbug-1199919': [SKIP],
'console/clear-async-stack-on-context-reset': [SKIP],
'console/destroy-context-during-log': [SKIP], 'console/destroy-context-during-log': [SKIP],
'console/scoped-variables': [SKIP], 'console/scoped-variables': [SKIP],
'cpu-profiler/console-profile': [SKIP], 'cpu-profiler/console-profile': [SKIP],
......
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