Chromium Code Reviews| Index: test/cctest/test-cpu-profiler.cc |
| diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc |
| index 8b34875f2b8dd0f5f13e8aa021ec76c23f512648..ca9b6c2b84d5daca9b7fa237eadafd45b2f41538 100644 |
| --- a/test/cctest/test-cpu-profiler.cc |
| +++ b/test/cctest/test-cpu-profiler.cc |
| @@ -278,7 +278,7 @@ TEST(TickEvents) { |
| TEST(CrashIfStoppingLastNonExistentProfile) { |
| CcTest::InitializeVM(); |
| TestSetup test_setup; |
| - CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); |
| + std::unique_ptr<CpuProfiler> profiler(new CpuProfiler(CcTest::i_isolate())); |
| profiler->StartProfiling("1"); |
| profiler->StopProfiling("2"); |
| profiler->StartProfiling("1"); |
| @@ -337,7 +337,7 @@ TEST(Issue1398) { |
| TEST(DeleteAllCpuProfiles) { |
| CcTest::InitializeVM(); |
| TestSetup test_setup; |
| - CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); |
| + std::unique_ptr<CpuProfiler> profiler(new CpuProfiler(CcTest::i_isolate())); |
| CHECK_EQ(0, profiler->GetProfilesCount()); |
| profiler->DeleteAllProfiles(); |
| CHECK_EQ(0, profiler->GetProfilesCount()); |
| @@ -381,7 +381,7 @@ static bool FindCpuProfile(v8::CpuProfiler* v8profiler, |
| TEST(DeleteCpuProfile) { |
| LocalContext env; |
| v8::HandleScope scope(env->GetIsolate()); |
| - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| + v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(env->GetIsolate()); |
| i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler); |
| CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| @@ -414,42 +414,68 @@ TEST(DeleteCpuProfile) { |
| CHECK(FindCpuProfile(cpu_profiler, p3)); |
| p3->Delete(); |
| CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| + cpu_profiler->Dispose(); |
| } |
| TEST(ProfileStartEndTime) { |
| LocalContext env; |
| v8::HandleScope scope(env->GetIsolate()); |
| - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| + v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(env->GetIsolate()); |
| v8::Local<v8::String> profile_name = v8_str("test"); |
| cpu_profiler->StartProfiling(profile_name); |
| const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| CHECK(profile->GetStartTime() <= profile->GetEndTime()); |
| + cpu_profiler->Dispose(); |
| } |
| -static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env, |
| - v8::Local<v8::Function> function, |
| - v8::Local<v8::Value> argv[], int argc, |
| - unsigned min_js_samples = 0, |
| - unsigned min_external_samples = 0, |
| - bool collect_samples = false) { |
| - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| +class ProfilerHelper { |
| + public: |
| + explicit ProfilerHelper(v8::Local<v8::Context> context) |
| + : context_(context), |
| + profiler_(v8::CpuProfiler::New(context->GetIsolate())), |
| + owned_(true) {} |
| + ProfilerHelper(v8::Local<v8::Context> context, v8::CpuProfiler* profiler) |
| + : context_(context), profiler_(profiler), owned_(false) {} |
| + ~ProfilerHelper() { |
| + if (owned_) profiler_->Dispose(); |
| + } |
| + |
| + v8::CpuProfile* Run(v8::Local<v8::Function> function, |
| + v8::Local<v8::Value> argv[], int argc, |
| + unsigned min_js_samples = 0, |
| + unsigned min_external_samples = 0, |
| + bool collect_samples = false); |
| + |
| + v8::CpuProfiler* profiler() { return profiler_; } |
| + |
| + private: |
| + v8::Local<v8::Context> context_; |
| + v8::CpuProfiler* profiler_; |
| + bool owned_; |
| +}; |
| + |
| +v8::CpuProfile* ProfilerHelper::Run(v8::Local<v8::Function> function, |
| + v8::Local<v8::Value> argv[], int argc, |
| + unsigned min_js_samples, |
| + unsigned min_external_samples, |
| + bool collect_samples) { |
| v8::Local<v8::String> profile_name = v8_str("my_profile"); |
| - cpu_profiler->SetSamplingInterval(100); |
| - cpu_profiler->StartProfiling(profile_name, collect_samples); |
| + profiler_->SetSamplingInterval(100); |
| + profiler_->StartProfiling(profile_name, collect_samples); |
| - v8::internal::CpuProfiler* i_cpu_profiler = |
| - reinterpret_cast<v8::internal::CpuProfiler*>(cpu_profiler); |
| - v8::sampler::Sampler* sampler = i_cpu_profiler->processor()->sampler(); |
| + v8::internal::CpuProfiler* iprofiler = |
| + reinterpret_cast<v8::internal::CpuProfiler*>(profiler_); |
| + v8::sampler::Sampler* sampler = iprofiler->processor()->sampler(); |
| sampler->StartCountingSamples(); |
| do { |
| - function->Call(env, env->Global(), argc, argv).ToLocalChecked(); |
| + function->Call(context_, context_->Global(), argc, argv).ToLocalChecked(); |
| } while (sampler->js_sample_count() < min_js_samples || |
| sampler->external_sample_count() < min_external_samples); |
| - v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| + v8::CpuProfile* profile = profiler_->StopProfiling(profile_name); |
| CHECK(profile); |
| // Dump collected profile to have a better diagnostic in case of failure. |
| @@ -458,7 +484,6 @@ static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env, |
| return profile; |
| } |
| - |
| static const v8::CpuProfileNode* FindChild(v8::Local<v8::Context> context, |
| const v8::CpuProfileNode* node, |
| const char* name) { |
| @@ -507,10 +532,6 @@ static const ProfileNode* GetSimpleBranch(v8::Local<v8::Context> context, |
| return reinterpret_cast<const ProfileNode*>(node); |
| } |
| -static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| - info.GetIsolate()->GetCpuProfiler()->CollectSample(); |
| -} |
| - |
| static const char* cpu_profiler_test_source = |
| "%NeverOptimizeFunction(loop);\n" |
| "%NeverOptimizeFunction(delay);\n" |
| @@ -573,8 +594,8 @@ TEST(CollectCpuProfile) { |
| int32_t profiling_interval_ms = 200; |
| v8::Local<v8::Value> args[] = { |
| v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 1000); |
| + ProfilerHelper helper(env.local()); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -630,8 +651,8 @@ TEST(HotDeoptNoFrameEntry) { |
| int32_t profiling_interval_ms = 200; |
| v8::Local<v8::Value> args[] = { |
| v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 1000); |
| + ProfilerHelper helper(env.local()); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000); |
| function->Call(env.local(), env->Global(), arraysize(args), args) |
| .ToLocalChecked(); |
| @@ -653,8 +674,9 @@ TEST(CollectCpuProfileSamples) { |
| int32_t profiling_interval_ms = 200; |
| v8::Local<v8::Value> args[] = { |
| v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; |
| + ProfilerHelper helper(env.local()); |
| v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 1000, 0, true); |
| + helper.Run(function, args, arraysize(args), 1000, 0, true); |
| CHECK_LE(200, profile->GetSamplesCount()); |
| uint64_t end_time = profile->GetEndTime(); |
| @@ -706,8 +728,8 @@ TEST(SampleWhenFrameIsNotSetup) { |
| int32_t duration_ms = 100; |
| v8::Local<v8::Value> args[] = { |
| v8::Integer::New(env->GetIsolate(), duration_ms)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 1000); |
| + ProfilerHelper helper(env.local()); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -788,8 +810,7 @@ TEST(NativeAccessorUninitializedIC) { |
| func_template->InstanceTemplate(); |
| TestApiCallbacks accessors(100); |
| - v8::Local<v8::External> data = |
| - v8::External::New(isolate, &accessors); |
| + v8::Local<v8::External> data = v8::External::New(isolate, &accessors); |
| instance_template->SetAccessor(v8_str("foo"), &TestApiCallbacks::Getter, |
| &TestApiCallbacks::Setter, data); |
| v8::Local<v8::Function> func = |
| @@ -801,10 +822,10 @@ TEST(NativeAccessorUninitializedIC) { |
| CompileRun(native_accessor_test_source); |
| v8::Local<v8::Function> function = GetFunction(env.local(), "start"); |
| + ProfilerHelper helper(env.local()); |
| int32_t repeat_count = 1; |
| v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 0, 100); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 100); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -856,8 +877,8 @@ TEST(NativeAccessorMonomorphicIC) { |
| int32_t repeat_count = 100; |
| v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 0, 100); |
| + ProfilerHelper helper(env.local()); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 100); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -881,12 +902,11 @@ TEST(NativeMethodUninitializedIC) { |
| v8::HandleScope scope(isolate); |
| TestApiCallbacks callbacks(100); |
| - v8::Local<v8::External> data = |
| - v8::External::New(isolate, &callbacks); |
| + v8::Local<v8::External> data = v8::External::New(isolate, &callbacks); |
| v8::Local<v8::FunctionTemplate> func_template = |
| v8::FunctionTemplate::New(isolate); |
| - func_template->SetClassName(v8_str("Test_InstanceCostructor")); |
| + func_template->SetClassName(v8_str("Test_InstanceConstructor")); |
| v8::Local<v8::ObjectTemplate> proto_template = |
| func_template->PrototypeTemplate(); |
| v8::Local<v8::Signature> signature = |
| @@ -905,10 +925,10 @@ TEST(NativeMethodUninitializedIC) { |
| CompileRun(native_method_test_source); |
| v8::Local<v8::Function> function = GetFunction(env.local(), "start"); |
| + ProfilerHelper helper(env.local()); |
| int32_t repeat_count = 1; |
| v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 0, 100); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 100); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -959,10 +979,10 @@ TEST(NativeMethodMonomorphicIC) { |
| callbacks.set_warming_up(false); |
| } |
| + ProfilerHelper helper(env.local()); |
| int32_t repeat_count = 100; |
| v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 0, 200); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 200); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| GetChild(env.local(), root, "start"); |
| @@ -987,11 +1007,13 @@ TEST(BoundFunctionCall) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
|
lpy
2016/07/06 21:34:35
I don't understand why we use a scope here to crea
alph
2016/07/06 21:45:16
Besides ProfilerHelper ProfilerExtension does also
alph
2016/07/06 23:12:41
I simplified it a bit.
|
| CompileRun(bound_function_test_source); |
| v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0); |
| + ProfilerHelper helper(env, profiler_scope.profiler()); |
| + v8::CpuProfile* profile = helper.Run(function, nullptr, 0); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| @@ -1146,11 +1168,11 @@ TEST(FunctionCallSample) { |
| CompileRun(call_function_test_source); |
| v8::Local<v8::Function> function = GetFunction(env.local(), "start"); |
| + ProfilerHelper helper(env.local()); |
| int32_t duration_ms = 100; |
| v8::Local<v8::Value> args[] = { |
| v8::Integer::New(env->GetIsolate(), duration_ms)}; |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 1000); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -1199,12 +1221,11 @@ TEST(FunctionApplySample) { |
| CompileRun(function_apply_test_source); |
| v8::Local<v8::Function> function = GetFunction(env.local(), "start"); |
| + ProfilerHelper helper(env.local()); |
| int32_t duration_ms = 100; |
| v8::Local<v8::Value> args[] = { |
| v8::Integer::New(env->GetIsolate(), duration_ms)}; |
| - |
| - v8::CpuProfile* profile = |
| - RunProfiler(env.local(), function, args, arraysize(args), 1000); |
| + v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); |
| @@ -1245,14 +1266,15 @@ TEST(CpuProfileDeepStack) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| CompileRun(cpu_profiler_deep_stack_test_source); |
| v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| v8::Local<v8::String> profile_name = v8_str("my_profile"); |
| function->Call(env, env->Global(), 0, NULL).ToLocalChecked(); |
| - v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| + v8::CpuProfile* profile = |
| + profiler_scope.profiler()->StopProfiling(profile_name); |
| CHECK(profile); |
| // Dump collected profile to have a better diagnostic in case of failure. |
| reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
| @@ -1303,6 +1325,7 @@ TEST(JsNativeJsSample) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| env->GetIsolate(), CallJsFunction); |
| @@ -1314,7 +1337,8 @@ TEST(JsNativeJsSample) { |
| CompileRun(js_native_js_test_source); |
| v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); |
| + ProfilerHelper helper(env, profiler_scope.profiler()); |
| + v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| @@ -1364,8 +1388,9 @@ TEST(JsNativeJsRuntimeJsSample) { |
| env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); |
| CompileRun(js_native_js_runtime_js_test_source); |
| + ProfilerHelper helper(env); |
| v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); |
| + v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| @@ -1410,6 +1435,7 @@ TEST(JsNative1JsNative2JsSample) { |
| i::FLAG_allow_natives_syntax = true; |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| v8::Context::Scope context_scope(env); |
| v8::Local<v8::Function> func1 = |
| @@ -1427,9 +1453,10 @@ TEST(JsNative1JsNative2JsSample) { |
| env->Global()->Set(env, v8_str("CallJsFunction2"), func2).FromJust(); |
| CompileRun(js_native1_js_native2_js_test_source); |
| - v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); |
| + ProfilerHelper helper(env, profiler_scope.profiler()); |
| + v8::Local<v8::Function> function = GetFunction(env, "start"); |
| + v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 1000); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| @@ -1448,10 +1475,15 @@ static const char* js_force_collect_sample_source = |
| " CallCollectSample();\n" |
| "}"; |
| +static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| + i::ProfilerExtension::Scope::profiler()->CollectSample(); |
| +} |
| + |
| TEST(CollectSampleAPI) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| v8::Local<v8::FunctionTemplate> func_template = |
| v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample); |
| @@ -1461,8 +1493,9 @@ TEST(CollectSampleAPI) { |
| env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust(); |
| CompileRun(js_force_collect_sample_source); |
| + ProfilerHelper helper(env, profiler_scope.profiler()); |
| v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); |
| + v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 0); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| @@ -1505,6 +1538,7 @@ TEST(JsNativeJsRuntimeJsSampleMultiple) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| v8::Local<v8::FunctionTemplate> func_template = |
| v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction); |
| @@ -1514,9 +1548,10 @@ TEST(JsNativeJsRuntimeJsSampleMultiple) { |
| env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); |
| CompileRun(js_native_js_runtime_multiple_test_source); |
| - v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 500, 500); |
| + ProfilerHelper helper(env, profiler_scope.profiler()); |
| + v8::Local<v8::Function> function = GetFunction(env, "start"); |
| + v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 500, 500); |
| const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| @@ -1568,14 +1603,15 @@ TEST(Inlining) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| CompileRun(inlining_test_source); |
| v8::Local<v8::Function> function = GetFunction(env, "start"); |
| - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| v8::Local<v8::String> profile_name = v8_str("my_profile"); |
| function->Call(env, env->Global(), 0, NULL).ToLocalChecked(); |
| - v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| + v8::CpuProfile* profile = |
| + profiler_scope.profiler()->StopProfiling(profile_name); |
| CHECK(profile); |
| // Dump collected profile to have a better diagnostic in case of failure. |
| reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
| @@ -1597,13 +1633,14 @@ TEST(Inlining) { |
| TEST(IdleTime) { |
| LocalContext env; |
| v8::HandleScope scope(env->GetIsolate()); |
| - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| + v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(env->GetIsolate()); |
| v8::Local<v8::String> profile_name = v8_str("my_profile"); |
| cpu_profiler->StartProfiling(profile_name); |
| i::Isolate* isolate = CcTest::i_isolate(); |
| - i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); |
| + i::ProfilerEventsProcessor* processor = |
| + reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->processor(); |
| processor->AddCurrentStack(isolate, true); |
| cpu_profiler->SetIdle(true); |
| @@ -1630,6 +1667,7 @@ TEST(IdleTime) { |
| CHECK_GE(idle_node->GetHitCount(), 3u); |
| profile->Delete(); |
| + cpu_profiler->Dispose(); |
| } |
| static void CheckFunctionDetails(v8::Isolate* isolate, |
| @@ -1652,6 +1690,7 @@ TEST(FunctionDetails) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| v8::Local<v8::Script> script_a = CompileWithOrigin( |
| "%NeverOptimizeFunction(foo);\n" |
| @@ -1698,7 +1737,7 @@ TEST(DontStopOnFinishedProfileDelete) { |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| - v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
| + v8::CpuProfiler* profiler = v8::CpuProfiler::New(env->GetIsolate()); |
| i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
| CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| @@ -1723,6 +1762,7 @@ TEST(DontStopOnFinishedProfileDelete) { |
| outer_profile->Delete(); |
| outer_profile = NULL; |
| CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| + profiler->Dispose(); |
| } |
| @@ -1744,9 +1784,9 @@ TEST(CollectDeoptEvents) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| - v8::Isolate* isolate = env->GetIsolate(); |
| - v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); |
| - i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| + i::CpuProfiler* iprofiler = |
| + reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler()); |
| const char opt_source[] = |
| "function opt_function%d(value, depth) {\n" |
| @@ -1874,9 +1914,9 @@ TEST(DeoptAtFirstLevelInlinedSource) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| - v8::Isolate* isolate = env->GetIsolate(); |
| - v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); |
| - i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| + i::CpuProfiler* iprofiler = |
| + reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler()); |
| // 0.........1.........2.........3.........4.........5.........6.........7 |
| const char* source = |
| @@ -1943,9 +1983,9 @@ TEST(DeoptAtSecondLevelInlinedSource) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| - v8::Isolate* isolate = env->GetIsolate(); |
| - v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); |
| - i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| + i::CpuProfiler* iprofiler = |
| + reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler()); |
| // 0.........1.........2.........3.........4.........5.........6.........7 |
| const char* source = |
| @@ -2017,9 +2057,9 @@ TEST(DeoptUntrackedFunction) { |
| v8::HandleScope scope(CcTest::isolate()); |
| v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| v8::Context::Scope context_scope(env); |
| - v8::Isolate* isolate = env->GetIsolate(); |
| - v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); |
| - i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
| + v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate()); |
| + i::CpuProfiler* iprofiler = |
| + reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler()); |
| // 0.........1.........2.........3.........4.........5.........6.........7 |
| const char* source = |