diff options
Diffstat (limited to 'deps/v8/test/cctest/test-cpu-profiler.cc')
-rw-r--r-- | deps/v8/test/cctest/test-cpu-profiler.cc | 188 |
1 files changed, 177 insertions, 11 deletions
diff --git a/deps/v8/test/cctest/test-cpu-profiler.cc b/deps/v8/test/cctest/test-cpu-profiler.cc index 7f06bc34d8..7d898cedb3 100644 --- a/deps/v8/test/cctest/test-cpu-profiler.cc +++ b/deps/v8/test/cctest/test-cpu-profiler.cc @@ -7,6 +7,7 @@ #include "v8.h" #include "cpu-profiler-inl.h" #include "cctest.h" +#include "../include/v8-profiler.h" namespace i = v8::internal; @@ -25,9 +26,6 @@ TEST(StartStop) { ProfileGenerator generator(&profiles); ProfilerEventsProcessor processor(&generator); processor.Start(); - while (!processor.running()) { - i::Thread::YieldCPU(); - } processor.Stop(); processor.Join(); } @@ -89,18 +87,15 @@ TEST(CodeEvents) { ProfileGenerator generator(&profiles); ProfilerEventsProcessor processor(&generator); processor.Start(); - while (!processor.running()) { - i::Thread::YieldCPU(); - } // Enqueue code creation events. i::HandleScope scope; const char* aaa_str = "aaa"; - i::Handle<i::String> aaa_name = i::Factory::NewStringFromAscii( + i::Handle<i::String> aaa_name = FACTORY->NewStringFromAscii( i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, *aaa_name, - i::Heap::empty_string(), + HEAP->empty_string(), 0, ToAddress(0x1000), 0x100, @@ -153,9 +148,6 @@ TEST(TickEvents) { ProfileGenerator generator(&profiles); ProfilerEventsProcessor processor(&generator); processor.Start(); - while (!processor.running()) { - i::Thread::YieldCPU(); - } processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, "bbb", @@ -236,4 +228,178 @@ TEST(CrashIfStoppingLastNonExistentProfile) { CpuProfiler::TearDown(); } + +// http://code.google.com/p/v8/issues/detail?id=1398 +// Long stacks (exceeding max frames limit) must not be erased. +TEST(Issue1398) { + TestSetup test_setup; + CpuProfilesCollection profiles; + profiles.StartProfiling("", 1); + ProfileGenerator generator(&profiles); + ProfilerEventsProcessor processor(&generator); + processor.Start(); + + processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, + "bbb", + ToAddress(0x1200), + 0x80); + + i::TickSample* sample = processor.TickSampleEvent(); + sample->pc = ToAddress(0x1200); + sample->tos = 0; + sample->frames_count = i::TickSample::kMaxFramesCount; + for (int i = 0; i < sample->frames_count; ++i) { + sample->stack[i] = ToAddress(0x1200); + } + + processor.Stop(); + processor.Join(); + CpuProfile* profile = + profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); + CHECK_NE(NULL, profile); + + int actual_depth = 0; + const ProfileNode* node = profile->top_down()->root(); + while (node->children()->length() > 0) { + node = node->children()->last(); + ++actual_depth; + } + + CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. +} + + +TEST(DeleteAllCpuProfiles) { + InitializeVM(); + TestSetup test_setup; + CpuProfiler::Setup(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CpuProfiler::DeleteAllProfiles(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + + CpuProfiler::StartProfiling("1"); + CpuProfiler::StopProfiling("1"); + CHECK_EQ(1, CpuProfiler::GetProfilesCount()); + CpuProfiler::DeleteAllProfiles(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CpuProfiler::StartProfiling("1"); + CpuProfiler::StartProfiling("2"); + CpuProfiler::StopProfiling("2"); + CpuProfiler::StopProfiling("1"); + CHECK_EQ(2, CpuProfiler::GetProfilesCount()); + CpuProfiler::DeleteAllProfiles(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + + // Test profiling cancellation by the 'delete' command. + CpuProfiler::StartProfiling("1"); + CpuProfiler::StartProfiling("2"); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CpuProfiler::DeleteAllProfiles(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + + CpuProfiler::TearDown(); +} + + +TEST(DeleteCpuProfile) { + v8::HandleScope scope; + LocalContext env; + + CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount()); + v8::Local<v8::String> name1 = v8::String::New("1"); + v8::CpuProfiler::StartProfiling(name1); + const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1); + CHECK_NE(NULL, p1); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + unsigned uid1 = p1->GetUid(); + CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1)); + const_cast<v8::CpuProfile*>(p1)->Delete(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); + + v8::Local<v8::String> name2 = v8::String::New("2"); + v8::CpuProfiler::StartProfiling(name2); + const v8::CpuProfile* p2 = v8::CpuProfiler::StopProfiling(name2); + CHECK_NE(NULL, p2); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + unsigned uid2 = p2->GetUid(); + CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); + CHECK_EQ(p2, v8::CpuProfiler::FindProfile(uid2)); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); + v8::Local<v8::String> name3 = v8::String::New("3"); + v8::CpuProfiler::StartProfiling(name3); + const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3); + CHECK_NE(NULL, p3); + CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount()); + unsigned uid3 = p3->GetUid(); + CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); + CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); + const_cast<v8::CpuProfile*>(p2)->Delete(); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); + CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); + const_cast<v8::CpuProfile*>(p3)->Delete(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); +} + + +TEST(DeleteCpuProfileDifferentTokens) { + v8::HandleScope scope; + LocalContext env; + + CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount()); + v8::Local<v8::String> name1 = v8::String::New("1"); + v8::CpuProfiler::StartProfiling(name1); + const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1); + CHECK_NE(NULL, p1); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + unsigned uid1 = p1->GetUid(); + CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1)); + v8::Local<v8::String> token1 = v8::String::New("token1"); + const v8::CpuProfile* p1_t1 = v8::CpuProfiler::FindProfile(uid1, token1); + CHECK_NE(NULL, p1_t1); + CHECK_NE(p1, p1_t1); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + const_cast<v8::CpuProfile*>(p1)->Delete(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1, token1)); + const_cast<v8::CpuProfile*>(p1_t1)->Delete(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + + v8::Local<v8::String> name2 = v8::String::New("2"); + v8::CpuProfiler::StartProfiling(name2); + v8::Local<v8::String> token2 = v8::String::New("token2"); + const v8::CpuProfile* p2_t2 = v8::CpuProfiler::StopProfiling(name2, token2); + CHECK_NE(NULL, p2_t2); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + unsigned uid2 = p2_t2->GetUid(); + CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); + const v8::CpuProfile* p2 = v8::CpuProfiler::FindProfile(uid2); + CHECK_NE(p2_t2, p2); + v8::Local<v8::String> name3 = v8::String::New("3"); + v8::CpuProfiler::StartProfiling(name3); + const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3); + CHECK_NE(NULL, p3); + CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount()); + unsigned uid3 = p3->GetUid(); + CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); + CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); + const_cast<v8::CpuProfile*>(p2_t2)->Delete(); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); + CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); + const_cast<v8::CpuProfile*>(p2)->Delete(); + CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); + CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); + const_cast<v8::CpuProfile*>(p3)->Delete(); + CHECK_EQ(0, CpuProfiler::GetProfilesCount()); + CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); +} + #endif // ENABLE_LOGGING_AND_PROFILING |