2010-03-19 13:51:01 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2013-03-07 11:12:26 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2010-03-19 13:51:01 +00:00
|
|
|
//
|
|
|
|
// Tests of profiles generator and utilities.
|
|
|
|
|
2013-05-28 08:00:16 +00:00
|
|
|
#define V8_DISABLE_DEPRECATIONS 1
|
2010-03-19 13:51:01 +00:00
|
|
|
#include "v8.h"
|
|
|
|
#include "cpu-profiler-inl.h"
|
|
|
|
#include "cctest.h"
|
2013-04-10 09:47:44 +00:00
|
|
|
#include "utils.h"
|
2011-03-22 16:10:01 +00:00
|
|
|
#include "../include/v8-profiler.h"
|
2013-05-28 08:00:16 +00:00
|
|
|
#undef V8_DISABLE_DEPRECATIONS
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
using i::CodeEntry;
|
2010-03-30 11:38:39 +00:00
|
|
|
using i::CpuProfile;
|
2010-08-10 12:06:42 +00:00
|
|
|
using i::CpuProfiler;
|
2010-03-19 13:51:01 +00:00
|
|
|
using i::CpuProfilesCollection;
|
|
|
|
using i::ProfileGenerator;
|
|
|
|
using i::ProfileNode;
|
|
|
|
using i::ProfilerEventsProcessor;
|
2013-04-10 14:31:13 +00:00
|
|
|
using i::ScopedVector;
|
2010-06-08 11:27:00 +00:00
|
|
|
using i::TokenEnumerator;
|
2013-04-10 09:47:44 +00:00
|
|
|
using i::Vector;
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(StartStop) {
|
|
|
|
CpuProfilesCollection profiles;
|
|
|
|
ProfileGenerator generator(&profiles);
|
2013-04-26 07:50:35 +00:00
|
|
|
ProfilerEventsProcessor processor(&generator, &profiles);
|
2010-03-19 13:51:01 +00:00
|
|
|
processor.Start();
|
|
|
|
processor.Stop();
|
|
|
|
processor.Join();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline i::Address ToAddress(int n) {
|
|
|
|
return reinterpret_cast<i::Address>(n);
|
|
|
|
}
|
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
|
|
|
|
i::Address frame1,
|
|
|
|
i::Address frame2 = NULL,
|
|
|
|
i::Address frame3 = NULL) {
|
|
|
|
i::TickSample* sample = proc->TickSampleEvent();
|
2010-03-19 13:51:01 +00:00
|
|
|
sample->pc = frame1;
|
2013-04-19 11:55:01 +00:00
|
|
|
sample->tos = frame1;
|
2010-03-19 13:51:01 +00:00
|
|
|
sample->frames_count = 0;
|
|
|
|
if (frame2 != NULL) {
|
|
|
|
sample->stack[0] = frame2;
|
|
|
|
sample->frames_count = 1;
|
|
|
|
}
|
|
|
|
if (frame3 != NULL) {
|
|
|
|
sample->stack[1] = frame3;
|
|
|
|
sample->frames_count = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-12 07:23:43 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TestSetup {
|
|
|
|
public:
|
|
|
|
TestSetup()
|
|
|
|
: old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) {
|
|
|
|
i::FLAG_prof_browser_mode = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestSetup() {
|
|
|
|
i::FLAG_prof_browser_mode = old_flag_prof_browser_mode_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool old_flag_prof_browser_mode_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2010-03-19 13:51:01 +00:00
|
|
|
TEST(CodeEvents) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-02-15 09:27:10 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
i::Heap* heap = isolate->heap();
|
|
|
|
i::Factory* factory = isolate->factory();
|
2010-04-12 07:23:43 +00:00
|
|
|
TestSetup test_setup;
|
2010-03-19 13:51:01 +00:00
|
|
|
CpuProfilesCollection profiles;
|
2013-04-02 07:48:25 +00:00
|
|
|
profiles.StartProfiling("", 1, false);
|
2010-03-19 13:51:01 +00:00
|
|
|
ProfileGenerator generator(&profiles);
|
2013-04-26 07:50:35 +00:00
|
|
|
ProfilerEventsProcessor processor(&generator, &profiles);
|
2010-03-19 13:51:01 +00:00
|
|
|
processor.Start();
|
|
|
|
|
|
|
|
// Enqueue code creation events.
|
2013-02-15 09:27:10 +00:00
|
|
|
i::HandleScope scope(isolate);
|
2010-03-19 13:51:01 +00:00
|
|
|
const char* aaa_str = "aaa";
|
2013-02-15 09:27:10 +00:00
|
|
|
i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
|
2010-04-13 11:59:37 +00:00
|
|
|
i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
|
2010-03-19 13:51:01 +00:00
|
|
|
processor.CodeCreateEvent(i::Logger::FUNCTION_TAG,
|
|
|
|
*aaa_name,
|
2013-02-15 09:27:10 +00:00
|
|
|
heap->empty_string(),
|
2010-03-19 13:51:01 +00:00
|
|
|
0,
|
|
|
|
ToAddress(0x1000),
|
2011-02-22 16:31:24 +00:00
|
|
|
0x100,
|
2013-05-14 22:51:33 +00:00
|
|
|
ToAddress(0x10000),
|
|
|
|
NULL);
|
2010-03-19 13:51:01 +00:00
|
|
|
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
|
|
|
|
"bbb",
|
|
|
|
ToAddress(0x1200),
|
|
|
|
0x80);
|
|
|
|
processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
|
|
|
|
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
|
|
|
|
"ddd",
|
|
|
|
ToAddress(0x1400),
|
|
|
|
0x80);
|
|
|
|
processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500));
|
|
|
|
processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10);
|
2011-09-14 11:47:03 +00:00
|
|
|
processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10);
|
2012-11-30 10:26:21 +00:00
|
|
|
// Enqueue a tick event to enable code events processing.
|
|
|
|
EnqueueTickSampleEvent(&processor, ToAddress(0x1000));
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
processor.Stop();
|
|
|
|
processor.Join();
|
|
|
|
|
|
|
|
// Check the state of profile generator.
|
|
|
|
CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000));
|
|
|
|
CHECK_NE(NULL, entry1);
|
|
|
|
CHECK_EQ(aaa_str, entry1->name());
|
|
|
|
CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200));
|
|
|
|
CHECK_NE(NULL, entry2);
|
|
|
|
CHECK_EQ("bbb", entry2->name());
|
|
|
|
CodeEntry* entry3 = generator.code_map()->FindEntry(ToAddress(0x1300));
|
|
|
|
CHECK_NE(NULL, entry3);
|
2010-04-06 10:36:38 +00:00
|
|
|
CHECK_EQ("5", entry3->name());
|
2010-03-19 13:51:01 +00:00
|
|
|
CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1400)));
|
|
|
|
CodeEntry* entry4 = generator.code_map()->FindEntry(ToAddress(0x1500));
|
|
|
|
CHECK_NE(NULL, entry4);
|
|
|
|
CHECK_EQ("ddd", entry4->name());
|
|
|
|
CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1600)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static int CompareProfileNodes(const T* p1, const T* p2) {
|
|
|
|
return strcmp((*p1)->entry()->name(), (*p2)->entry()->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TickEvents) {
|
2010-04-12 07:23:43 +00:00
|
|
|
TestSetup test_setup;
|
2010-03-19 13:51:01 +00:00
|
|
|
CpuProfilesCollection profiles;
|
2013-04-02 07:48:25 +00:00
|
|
|
profiles.StartProfiling("", 1, false);
|
2010-03-19 13:51:01 +00:00
|
|
|
ProfileGenerator generator(&profiles);
|
2013-04-26 07:50:35 +00:00
|
|
|
ProfilerEventsProcessor processor(&generator, &profiles);
|
2010-03-19 13:51:01 +00:00
|
|
|
processor.Start();
|
|
|
|
|
|
|
|
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
|
|
|
|
"bbb",
|
|
|
|
ToAddress(0x1200),
|
|
|
|
0x80);
|
|
|
|
processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
|
|
|
|
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
|
|
|
|
"ddd",
|
|
|
|
ToAddress(0x1400),
|
|
|
|
0x80);
|
2012-11-30 10:26:21 +00:00
|
|
|
EnqueueTickSampleEvent(&processor, ToAddress(0x1210));
|
|
|
|
EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220));
|
|
|
|
EnqueueTickSampleEvent(&processor,
|
|
|
|
ToAddress(0x1404),
|
|
|
|
ToAddress(0x1305),
|
|
|
|
ToAddress(0x1230));
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
processor.Stop();
|
|
|
|
processor.Join();
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* profile =
|
2010-06-08 11:27:00 +00:00
|
|
|
profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
|
2010-03-30 11:38:39 +00:00
|
|
|
CHECK_NE(NULL, profile);
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
// Check call trees.
|
2010-03-30 11:38:39 +00:00
|
|
|
const i::List<ProfileNode*>* top_down_root_children =
|
|
|
|
profile->top_down()->root()->children();
|
|
|
|
CHECK_EQ(1, top_down_root_children->length());
|
|
|
|
CHECK_EQ("bbb", top_down_root_children->last()->entry()->name());
|
|
|
|
const i::List<ProfileNode*>* top_down_bbb_children =
|
|
|
|
top_down_root_children->last()->children();
|
|
|
|
CHECK_EQ(1, top_down_bbb_children->length());
|
2010-04-06 10:36:38 +00:00
|
|
|
CHECK_EQ("5", top_down_bbb_children->last()->entry()->name());
|
2010-03-30 11:38:39 +00:00
|
|
|
const i::List<ProfileNode*>* top_down_stub_children =
|
|
|
|
top_down_bbb_children->last()->children();
|
|
|
|
CHECK_EQ(1, top_down_stub_children->length());
|
|
|
|
CHECK_EQ("ddd", top_down_stub_children->last()->entry()->name());
|
|
|
|
const i::List<ProfileNode*>* top_down_ddd_children =
|
|
|
|
top_down_stub_children->last()->children();
|
|
|
|
CHECK_EQ(0, top_down_ddd_children->length());
|
2010-03-19 13:51:01 +00:00
|
|
|
}
|
2010-03-30 11:38:39 +00:00
|
|
|
|
2010-08-10 12:06:42 +00:00
|
|
|
|
|
|
|
// http://crbug/51594
|
|
|
|
// This test must not crash.
|
|
|
|
TEST(CrashIfStoppingLastNonExistentProfile) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2010-08-10 12:06:42 +00:00
|
|
|
TestSetup test_setup;
|
2013-04-02 07:53:50 +00:00
|
|
|
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
|
|
|
|
profiler->StartProfiling("1");
|
|
|
|
profiler->StopProfiling("2");
|
|
|
|
profiler->StartProfiling("1");
|
|
|
|
profiler->StopProfiling("");
|
2010-08-10 12:06:42 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
|
2011-05-19 08:25:38 +00:00
|
|
|
// 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;
|
2013-04-02 07:48:25 +00:00
|
|
|
profiles.StartProfiling("", 1, false);
|
2011-05-19 08:25:38 +00:00
|
|
|
ProfileGenerator generator(&profiles);
|
2013-04-26 07:50:35 +00:00
|
|
|
ProfilerEventsProcessor processor(&generator, &profiles);
|
2011-05-19 08:25:38 +00:00
|
|
|
processor.Start();
|
|
|
|
|
|
|
|
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
|
|
|
|
"bbb",
|
|
|
|
ToAddress(0x1200),
|
|
|
|
0x80);
|
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
i::TickSample* sample = processor.TickSampleEvent();
|
2011-05-19 08:25:38 +00:00
|
|
|
sample->pc = ToAddress(0x1200);
|
2013-04-19 11:55:01 +00:00
|
|
|
sample->tos = 0;
|
2011-05-19 08:25:38 +00:00
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
TEST(DeleteAllCpuProfiles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2011-03-22 16:10:01 +00:00
|
|
|
TestSetup test_setup;
|
2013-04-02 07:53:50 +00:00
|
|
|
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
|
|
|
|
CHECK_EQ(0, profiler->GetProfilesCount());
|
|
|
|
profiler->DeleteAllProfiles();
|
|
|
|
CHECK_EQ(0, profiler->GetProfilesCount());
|
|
|
|
|
|
|
|
profiler->StartProfiling("1");
|
|
|
|
profiler->StopProfiling("1");
|
|
|
|
CHECK_EQ(1, profiler->GetProfilesCount());
|
|
|
|
profiler->DeleteAllProfiles();
|
|
|
|
CHECK_EQ(0, profiler->GetProfilesCount());
|
|
|
|
profiler->StartProfiling("1");
|
|
|
|
profiler->StartProfiling("2");
|
|
|
|
profiler->StopProfiling("2");
|
|
|
|
profiler->StopProfiling("1");
|
|
|
|
CHECK_EQ(2, profiler->GetProfilesCount());
|
|
|
|
profiler->DeleteAllProfiles();
|
|
|
|
CHECK_EQ(0, profiler->GetProfilesCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
|
|
|
|
// Test profiling cancellation by the 'delete' command.
|
2013-04-02 07:53:50 +00:00
|
|
|
profiler->StartProfiling("1");
|
|
|
|
profiler->StartProfiling("2");
|
|
|
|
CHECK_EQ(0, profiler->GetProfilesCount());
|
|
|
|
profiler->DeleteAllProfiles();
|
|
|
|
CHECK_EQ(0, profiler->GetProfilesCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-28 08:00:16 +00:00
|
|
|
static const v8::CpuProfile* FindCpuProfile(v8::CpuProfiler* profiler,
|
|
|
|
unsigned uid) {
|
|
|
|
int length = profiler->GetProfileCount();
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
const v8::CpuProfile* profile = profiler->GetCpuProfile(i);
|
|
|
|
if (profile->GetUid() == uid) {
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
TEST(DeleteCpuProfile) {
|
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2013-04-02 08:16:53 +00:00
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
2011-03-22 16:10:01 +00:00
|
|
|
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
v8::Local<v8::String> name1 = v8::String::New("1");
|
2013-04-02 08:16:53 +00:00
|
|
|
cpu_profiler->StartCpuProfiling(name1);
|
|
|
|
const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p1);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
unsigned uid1 = p1->GetUid();
|
2013-05-28 08:00:16 +00:00
|
|
|
CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p1)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
2013-05-28 08:00:16 +00:00
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
|
2011-03-22 16:10:01 +00:00
|
|
|
|
|
|
|
v8::Local<v8::String> name2 = v8::String::New("2");
|
2013-04-02 08:16:53 +00:00
|
|
|
cpu_profiler->StartCpuProfiling(name2);
|
|
|
|
const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p2);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
unsigned uid2 = p2->GetUid();
|
|
|
|
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
|
2013-05-28 08:00:16 +00:00
|
|
|
CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2));
|
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
|
2011-03-22 16:10:01 +00:00
|
|
|
v8::Local<v8::String> name3 = v8::String::New("3");
|
2013-04-02 08:16:53 +00:00
|
|
|
cpu_profiler->StartCpuProfiling(name3);
|
|
|
|
const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p3);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(2, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
unsigned uid3 = p3->GetUid();
|
|
|
|
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
|
2013-05-28 08:00:16 +00:00
|
|
|
CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3));
|
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p2)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
2013-05-28 08:00:16 +00:00
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2));
|
|
|
|
CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p3)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
2013-05-28 08:00:16 +00:00
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3));
|
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2));
|
|
|
|
CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeleteCpuProfileDifferentTokens) {
|
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2013-04-02 08:16:53 +00:00
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
2011-03-22 16:10:01 +00:00
|
|
|
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
v8::Local<v8::String> name1 = v8::String::New("1");
|
2013-04-02 08:16:53 +00:00
|
|
|
cpu_profiler->StartCpuProfiling(name1);
|
|
|
|
const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p1);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
unsigned uid1 = p1->GetUid();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(p1, cpu_profiler->FindCpuProfile(uid1));
|
2011-03-22 16:10:01 +00:00
|
|
|
v8::Local<v8::String> token1 = v8::String::New("token1");
|
2013-04-02 08:16:53 +00:00
|
|
|
const v8::CpuProfile* p1_t1 = cpu_profiler->FindCpuProfile(uid1, token1);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p1_t1);
|
|
|
|
CHECK_NE(p1, p1_t1);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p1)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
|
|
|
CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1));
|
|
|
|
CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1, token1));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p1_t1)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
|
|
|
|
v8::Local<v8::String> name2 = v8::String::New("2");
|
2013-04-02 08:16:53 +00:00
|
|
|
cpu_profiler->StartCpuProfiling(name2);
|
2011-03-22 16:10:01 +00:00
|
|
|
v8::Local<v8::String> token2 = v8::String::New("token2");
|
2013-04-02 08:16:53 +00:00
|
|
|
const v8::CpuProfile* p2_t2 = cpu_profiler->StopCpuProfiling(name2, token2);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p2_t2);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
unsigned uid2 = p2_t2->GetUid();
|
|
|
|
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
|
2013-04-02 08:16:53 +00:00
|
|
|
const v8::CpuProfile* p2 = cpu_profiler->FindCpuProfile(uid2);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(p2_t2, p2);
|
|
|
|
v8::Local<v8::String> name3 = v8::String::New("3");
|
2013-04-02 08:16:53 +00:00
|
|
|
cpu_profiler->StartCpuProfiling(name3);
|
|
|
|
const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p3);
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(2, cpu_profiler->GetProfileCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
unsigned uid3 = p3->GetUid();
|
|
|
|
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p2_t2)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
|
|
|
CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2));
|
|
|
|
CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p2)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(1, cpu_profiler->GetProfileCount());
|
|
|
|
CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2));
|
|
|
|
CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
|
2011-03-22 16:10:01 +00:00
|
|
|
const_cast<v8::CpuProfile*>(p3)->Delete();
|
2013-04-02 08:16:53 +00:00
|
|
|
CHECK_EQ(0, cpu_profiler->GetProfileCount());
|
|
|
|
CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid3));
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
2013-04-10 09:47:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
static bool ContainsString(v8::Handle<v8::String> string,
|
|
|
|
const Vector<v8::Handle<v8::String> >& vector) {
|
|
|
|
for (int i = 0; i < vector.length(); i++) {
|
|
|
|
if (string->Equals(vector[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CheckChildrenNames(const v8::CpuProfileNode* node,
|
|
|
|
const Vector<v8::Handle<v8::String> >& names) {
|
|
|
|
int count = node->GetChildrenCount();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
v8::Handle<v8::String> name = node->GetChild(i)->GetFunctionName();
|
|
|
|
CHECK(ContainsString(name, names));
|
|
|
|
// Check that there are no duplicates.
|
|
|
|
for (int j = 0; j < count; j++) {
|
|
|
|
if (j == i) continue;
|
|
|
|
CHECK_NE(name, node->GetChild(j)->GetFunctionName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node,
|
|
|
|
const char* name) {
|
|
|
|
int count = node->GetChildrenCount();
|
|
|
|
v8::Handle<v8::String> nameHandle = v8::String::New(name);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
const v8::CpuProfileNode* child = node->GetChild(i);
|
|
|
|
if (nameHandle->Equals(child->GetFunctionName())) return child;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-24 16:19:06 +00:00
|
|
|
static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node,
|
|
|
|
const char* name) {
|
|
|
|
const v8::CpuProfileNode* result = FindChild(node, name);
|
|
|
|
CHECK(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 09:47:44 +00:00
|
|
|
static void CheckSimpleBranch(const v8::CpuProfileNode* node,
|
|
|
|
const char* names[], int length) {
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
const char* name = names[i];
|
2013-05-24 16:19:06 +00:00
|
|
|
node = GetChild(node, name);
|
2013-04-10 09:47:44 +00:00
|
|
|
int expectedChildrenCount = (i == length - 1) ? 0 : 1;
|
|
|
|
CHECK_EQ(expectedChildrenCount, node->GetChildrenCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char* cpu_profiler_test_source = "function loop(timeout) {\n"
|
|
|
|
" this.mmm = 0;\n"
|
|
|
|
" var start = Date.now();\n"
|
|
|
|
" while (Date.now() - start < timeout) {\n"
|
|
|
|
" var n = 100*1000;\n"
|
|
|
|
" while(n > 1) {\n"
|
|
|
|
" n--;\n"
|
|
|
|
" this.mmm += n * n * n;\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
"function delay() { try { loop(10); } catch(e) { } }\n"
|
|
|
|
"function bar() { delay(); }\n"
|
|
|
|
"function baz() { delay(); }\n"
|
|
|
|
"function foo() {\n"
|
|
|
|
" try {\n"
|
|
|
|
" delay();\n"
|
|
|
|
" bar();\n"
|
|
|
|
" delay();\n"
|
|
|
|
" baz();\n"
|
|
|
|
" } catch (e) { }\n"
|
|
|
|
"}\n"
|
2013-04-15 14:45:38 +00:00
|
|
|
"function start(timeout) {\n"
|
2013-04-10 09:47:44 +00:00
|
|
|
" var start = Date.now();\n"
|
|
|
|
" do {\n"
|
|
|
|
" foo();\n"
|
|
|
|
" var duration = Date.now() - start;\n"
|
2013-04-15 14:45:38 +00:00
|
|
|
" } while (duration < timeout);\n"
|
2013-04-10 09:47:44 +00:00
|
|
|
" return duration;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Check that the profile tree for the script above will look like the
|
|
|
|
// following:
|
|
|
|
//
|
|
|
|
// [Top down]:
|
|
|
|
// 1062 0 (root) [-1]
|
|
|
|
// 1054 0 start [-1]
|
|
|
|
// 1054 1 foo [-1]
|
|
|
|
// 265 0 baz [-1]
|
|
|
|
// 265 1 delay [-1]
|
|
|
|
// 264 264 loop [-1]
|
|
|
|
// 525 3 delay [-1]
|
|
|
|
// 522 522 loop [-1]
|
|
|
|
// 263 0 bar [-1]
|
|
|
|
// 263 1 delay [-1]
|
|
|
|
// 262 262 loop [-1]
|
|
|
|
// 2 2 (program) [-1]
|
|
|
|
// 6 6 (garbage collector) [-1]
|
|
|
|
TEST(CollectCpuProfile) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::New("start")));
|
|
|
|
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
v8::Local<v8::String> profile_name = v8::String::New("my_profile");
|
|
|
|
|
|
|
|
cpu_profiler->StartCpuProfiling(profile_name);
|
2013-04-15 14:45:38 +00:00
|
|
|
int32_t profiling_interval_ms = 200;
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
// 200ms is not enough on Windows. See
|
|
|
|
// https://code.google.com/p/v8/issues/detail?id=2628
|
|
|
|
profiling_interval_ms = 500;
|
|
|
|
#endif
|
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) };
|
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
2013-04-10 09:47:44 +00:00
|
|
|
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
|
|
|
|
|
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
|
|
|
reinterpret_cast<i::CpuProfile*>(
|
|
|
|
const_cast<v8::CpuProfile*>(profile))->Print();
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
|
|
|
names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::New("start");
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
2013-05-24 16:19:06 +00:00
|
|
|
const v8::CpuProfileNode* startNode = GetChild(root, "start");
|
2013-04-10 09:47:44 +00:00
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
|
|
|
|
2013-05-24 16:19:06 +00:00
|
|
|
const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo");
|
2013-04-10 09:47:44 +00:00
|
|
|
CHECK_EQ(3, fooNode->GetChildrenCount());
|
|
|
|
|
|
|
|
const char* barBranch[] = { "bar", "delay", "loop" };
|
|
|
|
CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch));
|
|
|
|
const char* bazBranch[] = { "baz", "delay", "loop" };
|
|
|
|
CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch));
|
|
|
|
const char* delayBranch[] = { "delay", "loop" };
|
|
|
|
CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch));
|
2013-04-10 14:31:13 +00:00
|
|
|
|
|
|
|
cpu_profiler->DeleteAllCpuProfiles();
|
2013-04-10 09:47:44 +00:00
|
|
|
}
|
2013-05-14 22:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char* cpu_profiler_test_source2 = "function loop() {}\n"
|
|
|
|
"function delay() { loop(); }\n"
|
|
|
|
"function start(count) {\n"
|
|
|
|
" var k = 0;\n"
|
|
|
|
" do {\n"
|
|
|
|
" delay();\n"
|
|
|
|
" } while (++k < count*100*1000);\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
// Check that the profile tree doesn't contain unexpecte traces:
|
|
|
|
// - 'loop' can be called only by 'delay'
|
|
|
|
// - 'delay' may be called only by 'start'
|
|
|
|
// The profile will look like the following:
|
|
|
|
//
|
|
|
|
// [Top down]:
|
|
|
|
// 135 0 (root) [-1] #1
|
|
|
|
// 121 72 start [-1] #3
|
|
|
|
// 49 33 delay [-1] #4
|
|
|
|
// 16 16 loop [-1] #5
|
|
|
|
// 14 14 (program) [-1] #2
|
|
|
|
TEST(SampleWhenFrameIsNotSetup) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::New("start")));
|
|
|
|
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
v8::Local<v8::String> profile_name = v8::String::New("my_profile");
|
|
|
|
|
|
|
|
cpu_profiler->StartCpuProfiling(profile_name);
|
|
|
|
int32_t repeat_count = 100;
|
|
|
|
#if defined(USE_SIMULATOR)
|
|
|
|
// Simulators are much slower.
|
|
|
|
repeat_count = 1;
|
|
|
|
#endif
|
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
|
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
|
|
|
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
|
|
|
|
|
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
|
|
|
reinterpret_cast<i::CpuProfile*>(
|
|
|
|
const_cast<v8::CpuProfile*>(profile))->Print();
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
|
|
|
names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::New("start");
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* startNode = FindChild(root, "start");
|
2013-05-17 15:10:25 +00:00
|
|
|
// On slow machines there may be no meaningfull samples at all, skip the
|
|
|
|
// check there.
|
|
|
|
if (startNode && startNode->GetChildrenCount() > 0) {
|
2013-05-14 22:51:33 +00:00
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
2013-05-24 16:19:06 +00:00
|
|
|
const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay");
|
2013-05-14 22:51:33 +00:00
|
|
|
if (delayNode->GetChildrenCount() > 0) {
|
|
|
|
CHECK_EQ(1, delayNode->GetChildrenCount());
|
2013-05-24 16:19:06 +00:00
|
|
|
GetChild(delayNode, "loop");
|
2013-05-14 22:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_profiler->DeleteAllCpuProfiles();
|
|
|
|
}
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const char* native_accessor_test_source = "function start(count) {\n"
|
|
|
|
" for (var i = 0; i < count; i++) {\n"
|
|
|
|
" var o = instance.foo;\n"
|
|
|
|
" instance.foo = o + 1;\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
|
|
|
|
class FooAccessorsData {
|
|
|
|
public:
|
|
|
|
explicit FooAccessorsData(int min_duration_ms)
|
2013-06-05 06:15:41 +00:00
|
|
|
: min_duration_ms_(min_duration_ms),
|
|
|
|
getter_duration_(0),
|
2013-06-06 07:00:57 +00:00
|
|
|
setter_duration_(0),
|
|
|
|
getter_iterations_(0),
|
|
|
|
setter_iterations_(0) {}
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name,
|
|
|
|
const v8::AccessorInfo& info) {
|
|
|
|
FooAccessorsData* data = fromInfo(info);
|
2013-06-06 07:00:57 +00:00
|
|
|
data->getter_duration_ = data->Wait(&data->getter_iterations_);
|
2013-06-04 10:57:32 +00:00
|
|
|
return v8::Int32::New(2013);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Setter(v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::AccessorInfo& info) {
|
|
|
|
FooAccessorsData* data = fromInfo(info);
|
2013-06-06 07:00:57 +00:00
|
|
|
data->setter_duration_ = data->Wait(&data->setter_iterations_);
|
2013-06-05 06:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintAccessorTime() {
|
2013-06-06 07:00:57 +00:00
|
|
|
i::OS::Print("getter: %f ms (%d); setter: %f ms (%d)\n", getter_duration_,
|
|
|
|
getter_iterations_, setter_duration_, setter_iterations_);
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-06-06 07:00:57 +00:00
|
|
|
double Wait(int* iterations) {
|
2013-06-04 10:57:32 +00:00
|
|
|
double start = i::OS::TimeCurrentMillis();
|
2013-06-05 06:15:41 +00:00
|
|
|
double duration = 0;
|
|
|
|
while (duration < min_duration_ms_) {
|
2013-06-07 17:25:47 +00:00
|
|
|
i::OS::Sleep(1);
|
2013-06-04 10:57:32 +00:00
|
|
|
duration = i::OS::TimeCurrentMillis() - start;
|
2013-06-06 07:00:57 +00:00
|
|
|
++*iterations;
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
2013-06-05 06:15:41 +00:00
|
|
|
return duration;
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) {
|
|
|
|
void* data = v8::External::Cast(*info.Data())->Value();
|
|
|
|
return reinterpret_cast<FooAccessorsData*>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
int min_duration_ms_;
|
2013-06-05 06:15:41 +00:00
|
|
|
double getter_duration_;
|
|
|
|
double setter_duration_;
|
2013-06-06 07:00:57 +00:00
|
|
|
int getter_iterations_;
|
|
|
|
int setter_iterations_;
|
2013-06-04 10:57:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that native accessors are properly reported in the CPU profile.
|
|
|
|
// This test checks the case when the long-running accessors are called
|
|
|
|
// only once and the optimizer doesn't have chance to change the invocation
|
|
|
|
// code.
|
|
|
|
TEST(NativeAccessorNameInProfile1) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
|
|
|
|
v8::Local<v8::ObjectTemplate> instance_template =
|
|
|
|
func_template->InstanceTemplate();
|
|
|
|
|
|
|
|
FooAccessorsData accessors(100);
|
|
|
|
v8::Local<v8::External> data = v8::External::New(&accessors);
|
|
|
|
instance_template->SetAccessor(
|
|
|
|
v8::String::New("foo"), &FooAccessorsData::Getter,
|
|
|
|
&FooAccessorsData::Setter, data);
|
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
|
|
|
v8::Local<v8::Object> instance = func->NewInstance();
|
|
|
|
env->Global()->Set(v8::String::New("instance"), instance);
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::New("start")));
|
|
|
|
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
v8::Local<v8::String> profile_name = v8::String::New("my_profile");
|
|
|
|
|
|
|
|
cpu_profiler->StartCpuProfiling(profile_name);
|
|
|
|
int32_t repeat_count = 1;
|
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
|
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
|
|
|
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
|
|
|
|
|
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
|
|
|
reinterpret_cast<i::CpuProfile*>(
|
|
|
|
const_cast<v8::CpuProfile*>(profile))->Print();
|
2013-06-05 06:15:41 +00:00
|
|
|
accessors.PrintAccessorTime();
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
const v8::CpuProfileNode* startNode = GetChild(root, "start");
|
|
|
|
GetChild(startNode, "get foo");
|
|
|
|
GetChild(startNode, "set foo");
|
|
|
|
|
|
|
|
cpu_profiler->DeleteAllCpuProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that native accessors are properly reported in the CPU profile.
|
|
|
|
// This test makes sure that the accessors are called enough times to become
|
|
|
|
// hot and to trigger optimizations.
|
|
|
|
TEST(NativeAccessorNameInProfile2) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
|
|
|
|
v8::Local<v8::ObjectTemplate> instance_template =
|
|
|
|
func_template->InstanceTemplate();
|
|
|
|
|
|
|
|
FooAccessorsData accessors(1);
|
|
|
|
v8::Local<v8::External> data = v8::External::New(&accessors);
|
|
|
|
instance_template->SetAccessor(
|
|
|
|
v8::String::New("foo"), &FooAccessorsData::Getter,
|
|
|
|
&FooAccessorsData::Setter, data);
|
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
|
|
|
v8::Local<v8::Object> instance = func->NewInstance();
|
|
|
|
env->Global()->Set(v8::String::New("instance"), instance);
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::New("start")));
|
|
|
|
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
v8::Local<v8::String> profile_name = v8::String::New("my_profile");
|
|
|
|
|
|
|
|
cpu_profiler->StartCpuProfiling(profile_name);
|
|
|
|
int32_t repeat_count = 100;
|
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
|
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
|
|
|
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
|
|
|
|
|
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
|
|
|
reinterpret_cast<i::CpuProfile*>(
|
|
|
|
const_cast<v8::CpuProfile*>(profile))->Print();
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
const v8::CpuProfileNode* startNode = GetChild(root, "start");
|
|
|
|
// TODO(yurys): in LoadIC should be changed to report external callback
|
|
|
|
// invocation. See r13768 where it was LoadCallbackProperty was removed.
|
|
|
|
// GetChild(startNode, "get foo");
|
|
|
|
GetChild(startNode, "set foo");
|
|
|
|
|
|
|
|
cpu_profiler->DeleteAllCpuProfiles();
|
|
|
|
}
|