[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: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57207}
This commit is contained in:
Peter Marshall 2018-10-31 15:29:55 +01:00 committed by Commit Bot
parent 9884930b32
commit 2fb919f4b7

View File

@ -2548,6 +2548,57 @@ TEST(MultipleProfilers) {
profiler2->StopProfiling("2"); 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 test_cpu_profiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8