Commit 2fb919f4 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cpu-profiler] Add a basic test for multiple isolates profiling

We don't have any tests which run multiple isolates concurrently and
starts a profiler in each of them. This test is a basic starting point
so that we can check for flakiness caused by races or interrupts.

The profiling mechanisms should be totally separate for two isolates,
so this should (theoretically) not cause any problems.

A use case for multiple isolates is for workers or in Node via cloud
functions, so we should get some more coverage here.

Change-Id: I0ca6d1296bc7bae7238c51b4487259d09e38d690
Reviewed-on: https://chromium-review.googlesource.com/c/1309823
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57207}
parent 9884930b
......@@ -2548,6 +2548,57 @@ TEST(MultipleProfilers) {
profiler2->StopProfiling("2");
}
void ProfileSomeCode(v8::Isolate* isolate) {
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
LocalContext context(isolate);
v8::CpuProfiler* profiler = v8::CpuProfiler::New(isolate);
v8::Local<v8::String> profile_name = v8_str("1");
profiler->StartProfiling(profile_name);
const char* source = R"(
function foo() {
var s = {};
for (var i = 0; i < 1e4; ++i) {
for (var j = 0; j < 100; j++) {
s['item' + j] = 'bar';
}
}
}
foo();
)";
CompileRun(source);
profiler->StopProfiling(profile_name);
profiler->Dispose();
}
class IsolateThread : public v8::base::Thread {
public:
IsolateThread() : Thread(Options("IsolateThread")) {}
void Run() override {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
ProfileSomeCode(isolate);
isolate->Dispose();
}
};
// Checking for crashes and TSAN issues with multiple isolates profiling.
TEST(MultipleIsolates) {
IsolateThread thread1;
IsolateThread thread2;
thread1.Start();
thread2.Start();
thread1.Join();
thread2.Join();
}
} // namespace test_cpu_profiler
} // namespace internal
} // namespace v8
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