From 2fb919f4b773d07186978a32d17aa23201beed49 Mon Sep 17 00:00:00 2001 From: Peter Marshall Date: Wed, 31 Oct 2018 15:29:55 +0100 Subject: [PATCH] [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 Reviewed-by: Alexei Filippov Cr-Commit-Position: refs/heads/master@{#57207} --- test/cctest/test-cpu-profiler.cc | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index b59c47fed7..0bf5710f13 100644 --- a/test/cctest/test-cpu-profiler.cc +++ b/test/cctest/test-cpu-profiler.cc @@ -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 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