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.
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#include "include/v8-profiler.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/cpu-profiler-inl.h"
|
|
|
|
#include "src/smart-pointers.h"
|
|
|
|
#include "src/utils.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/profiler-extension.h"
|
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;
|
2013-07-08 11:26:15 +00:00
|
|
|
using i::Heap;
|
2010-03-19 13:51:01 +00:00
|
|
|
using i::ProfileGenerator;
|
|
|
|
using i::ProfileNode;
|
|
|
|
using i::ProfilerEventsProcessor;
|
2013-04-10 14:31:13 +00:00
|
|
|
using i::ScopedVector;
|
2013-08-23 10:59:29 +00:00
|
|
|
using i::SmartPointer;
|
2013-04-10 09:47:44 +00:00
|
|
|
using i::Vector;
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(StartStop) {
|
2013-09-11 07:14:41 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
CpuProfilesCollection profiles(isolate->heap());
|
2010-03-19 13:51:01 +00:00
|
|
|
ProfileGenerator generator(&profiles);
|
2013-08-29 09:15:13 +00:00
|
|
|
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
|
2014-06-30 13:25:46 +00:00
|
|
|
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->Start();
|
|
|
|
processor->StopSynchronously();
|
2010-03-19 13:51:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
|
|
|
|
i::Address frame1,
|
|
|
|
i::Address frame2 = NULL,
|
|
|
|
i::Address frame3 = NULL) {
|
2013-08-23 08:22:07 +00:00
|
|
|
i::TickSample* sample = proc->StartTickSample();
|
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;
|
|
|
|
}
|
2013-08-23 08:22:07 +00:00
|
|
|
proc->FinishTickSample();
|
2010-03-19 13:51:01 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2013-07-01 10:12:03 +00:00
|
|
|
|
|
|
|
i::Code* CreateCode(LocalContext* env) {
|
|
|
|
static int counter = 0;
|
|
|
|
i::EmbeddedVector<char, 256> script;
|
|
|
|
i::EmbeddedVector<char, 32> name;
|
|
|
|
|
2014-06-13 16:43:27 +00:00
|
|
|
i::SNPrintF(name, "function_%d", ++counter);
|
2013-07-01 10:12:03 +00:00
|
|
|
const char* name_start = name.start();
|
2014-06-13 16:43:27 +00:00
|
|
|
i::SNPrintF(script,
|
2013-07-01 10:12:03 +00:00
|
|
|
"function %s() {\n"
|
|
|
|
"var counter = 0;\n"
|
|
|
|
"for (var i = 0; i < %d; ++i) counter += i;\n"
|
|
|
|
"return '%s_' + counter;\n"
|
|
|
|
"}\n"
|
|
|
|
"%s();\n", name_start, counter, name_start, name_start);
|
|
|
|
CompileRun(script.start());
|
|
|
|
i::Handle<i::JSFunction> fun = v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(
|
|
|
|
(*env)->Global()->Get(v8_str(name_start))));
|
|
|
|
return fun->code();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-19 13:51:01 +00:00
|
|
|
TEST(CodeEvents) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-07-01 10:12:03 +00:00
|
|
|
LocalContext env;
|
2013-09-19 09:17:13 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
i::Factory* factory = isolate->factory();
|
2010-04-12 07:23:43 +00:00
|
|
|
TestSetup test_setup;
|
2013-07-01 10:12:03 +00:00
|
|
|
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
i::Code* aaa_code = CreateCode(&env);
|
|
|
|
i::Code* comment_code = CreateCode(&env);
|
|
|
|
i::Code* args5_code = CreateCode(&env);
|
|
|
|
i::Code* comment2_code = CreateCode(&env);
|
|
|
|
i::Code* moved_code = CreateCode(&env);
|
|
|
|
i::Code* args3_code = CreateCode(&env);
|
|
|
|
i::Code* args4_code = CreateCode(&env);
|
|
|
|
|
2013-09-11 07:14:41 +00:00
|
|
|
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
|
2013-12-18 08:59:09 +00:00
|
|
|
profiles->StartProfiling("", false);
|
2013-07-01 10:12:03 +00:00
|
|
|
ProfileGenerator generator(profiles);
|
2013-08-29 09:15:13 +00:00
|
|
|
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
|
2014-06-30 13:25:46 +00:00
|
|
|
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->Start();
|
2013-12-09 07:41:20 +00:00
|
|
|
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
// Enqueue code creation events.
|
|
|
|
const char* aaa_str = "aaa";
|
2014-04-17 13:27:02 +00:00
|
|
|
i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str);
|
2013-07-01 10:12:03 +00:00
|
|
|
profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name);
|
|
|
|
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment");
|
|
|
|
profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
|
|
|
|
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2");
|
|
|
|
profiler.CodeMoveEvent(comment2_code->address(), moved_code->address());
|
|
|
|
profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3);
|
|
|
|
profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4);
|
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
// Enqueue a tick event to enable code events processing.
|
2013-12-09 07:41:20 +00:00
|
|
|
EnqueueTickSampleEvent(processor.get(), aaa_code->address());
|
2010-03-19 13:51:01 +00:00
|
|
|
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->StopSynchronously();
|
2010-03-19 13:51:01 +00:00
|
|
|
|
|
|
|
// Check the state of profile generator.
|
2013-07-01 10:12:03 +00:00
|
|
|
CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address());
|
|
|
|
CHECK_NE(NULL, aaa);
|
|
|
|
CHECK_EQ(aaa_str, aaa->name());
|
|
|
|
|
|
|
|
CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address());
|
|
|
|
CHECK_NE(NULL, comment);
|
|
|
|
CHECK_EQ("comment", comment->name());
|
|
|
|
|
|
|
|
CodeEntry* args5 = generator.code_map()->FindEntry(args5_code->address());
|
|
|
|
CHECK_NE(NULL, args5);
|
|
|
|
CHECK_EQ("5", args5->name());
|
|
|
|
|
|
|
|
CHECK_EQ(NULL, generator.code_map()->FindEntry(comment2_code->address()));
|
|
|
|
|
|
|
|
CodeEntry* comment2 = generator.code_map()->FindEntry(moved_code->address());
|
|
|
|
CHECK_NE(NULL, comment2);
|
|
|
|
CHECK_EQ("comment2", comment2->name());
|
2010-03-19 13:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static int CompareProfileNodes(const T* p1, const T* p2) {
|
|
|
|
return strcmp((*p1)->entry()->name(), (*p2)->entry()->name());
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2010-03-19 13:51:01 +00:00
|
|
|
TEST(TickEvents) {
|
2010-04-12 07:23:43 +00:00
|
|
|
TestSetup test_setup;
|
2013-07-01 10:12:03 +00:00
|
|
|
LocalContext env;
|
2013-09-19 09:17:13 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
2013-07-01 10:12:03 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
i::Code* frame1_code = CreateCode(&env);
|
|
|
|
i::Code* frame2_code = CreateCode(&env);
|
|
|
|
i::Code* frame3_code = CreateCode(&env);
|
|
|
|
|
2013-09-11 07:14:41 +00:00
|
|
|
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
|
2013-12-18 08:59:09 +00:00
|
|
|
profiles->StartProfiling("", false);
|
2013-07-01 10:12:03 +00:00
|
|
|
ProfileGenerator generator(profiles);
|
2013-08-29 09:15:13 +00:00
|
|
|
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
|
2014-06-30 13:25:46 +00:00
|
|
|
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->Start();
|
2013-12-09 07:41:20 +00:00
|
|
|
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
|
2010-03-19 13:51:01 +00:00
|
|
|
|
2013-07-01 10:12:03 +00:00
|
|
|
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb");
|
|
|
|
profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
|
|
|
|
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
|
|
|
|
|
2013-12-09 07:41:20 +00:00
|
|
|
EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start());
|
2013-07-01 10:12:03 +00:00
|
|
|
EnqueueTickSampleEvent(
|
2013-12-09 07:41:20 +00:00
|
|
|
processor.get(),
|
2013-07-01 10:12:03 +00:00
|
|
|
frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2,
|
|
|
|
frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2);
|
|
|
|
EnqueueTickSampleEvent(
|
2013-12-09 07:41:20 +00:00
|
|
|
processor.get(),
|
2013-07-01 10:12:03 +00:00
|
|
|
frame3_code->instruction_end() - 1,
|
|
|
|
frame2_code->instruction_end() - 1,
|
|
|
|
frame1_code->instruction_end() - 1);
|
2010-03-19 13:51:01 +00:00
|
|
|
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->StopSynchronously();
|
2013-07-30 07:01:16 +00:00
|
|
|
CpuProfile* profile = profiles->StopProfiling("");
|
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-09-19 09:17:13 +00:00
|
|
|
CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
|
2013-04-02 07:53:50 +00:00
|
|
|
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;
|
2013-07-01 10:12:03 +00:00
|
|
|
LocalContext env;
|
2013-09-19 09:17:13 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
2013-07-01 10:12:03 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
i::Code* code = CreateCode(&env);
|
|
|
|
|
2013-09-11 07:14:41 +00:00
|
|
|
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
|
2013-12-18 08:59:09 +00:00
|
|
|
profiles->StartProfiling("", false);
|
2013-07-01 10:12:03 +00:00
|
|
|
ProfileGenerator generator(profiles);
|
2013-08-29 09:15:13 +00:00
|
|
|
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
|
2014-06-30 13:25:46 +00:00
|
|
|
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->Start();
|
2013-12-09 07:41:20 +00:00
|
|
|
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
|
2011-05-19 08:25:38 +00:00
|
|
|
|
2013-07-01 10:12:03 +00:00
|
|
|
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
|
2011-05-19 08:25:38 +00:00
|
|
|
|
2013-08-23 10:59:29 +00:00
|
|
|
i::TickSample* sample = processor->StartTickSample();
|
2013-07-01 10:12:03 +00:00
|
|
|
sample->pc = code->address();
|
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;
|
2014-06-24 16:00:51 +00:00
|
|
|
for (unsigned i = 0; i < sample->frames_count; ++i) {
|
2013-07-01 10:12:03 +00:00
|
|
|
sample->stack[i] = code->address();
|
2011-05-19 08:25:38 +00:00
|
|
|
}
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->FinishTickSample();
|
2011-05-19 08:25:38 +00:00
|
|
|
|
2013-08-23 10:59:29 +00:00
|
|
|
processor->StopSynchronously();
|
2013-07-30 07:01:16 +00:00
|
|
|
CpuProfile* profile = profiles->StopProfiling("");
|
2011-05-19 08:25:38 +00:00
|
|
|
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-09-19 09:17:13 +00:00
|
|
|
CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
|
2013-04-02 07:53:50 +00:00
|
|
|
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-12-18 08:59:09 +00:00
|
|
|
static bool FindCpuProfile(v8::CpuProfiler* v8profiler,
|
|
|
|
const v8::CpuProfile* v8profile) {
|
|
|
|
i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(v8profiler);
|
|
|
|
const i::CpuProfile* profile =
|
|
|
|
reinterpret_cast<const i::CpuProfile*>(v8profile);
|
|
|
|
int length = profiler->GetProfilesCount();
|
2013-05-28 08:00:16 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2013-12-18 08:59:09 +00:00
|
|
|
if (profile == profiler->GetProfile(i))
|
|
|
|
return true;
|
2013-05-28 08:00:16 +00:00
|
|
|
}
|
2013-12-18 08:59:09 +00:00
|
|
|
return false;
|
2013-05-28 08:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2013-12-18 08:59:09 +00:00
|
|
|
i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler);
|
2011-03-22 16:10:01 +00:00
|
|
|
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1");
|
2014-03-28 09:24:49 +00:00
|
|
|
cpu_profiler->StartProfiling(name1);
|
|
|
|
v8::CpuProfile* p1 = cpu_profiler->StopProfiling(name1);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p1);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
|
|
|
CHECK(FindCpuProfile(cpu_profiler, p1));
|
2014-03-28 09:24:49 +00:00
|
|
|
p1->Delete();
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2");
|
2014-03-28 09:24:49 +00:00
|
|
|
cpu_profiler->StartProfiling(name2);
|
|
|
|
v8::CpuProfile* p2 = cpu_profiler->StopProfiling(name2);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p2);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
|
|
|
CHECK(FindCpuProfile(cpu_profiler, p2));
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3");
|
2014-03-28 09:24:49 +00:00
|
|
|
cpu_profiler->StartProfiling(name3);
|
|
|
|
v8::CpuProfile* p3 = cpu_profiler->StopProfiling(name3);
|
2011-03-22 16:10:01 +00:00
|
|
|
CHECK_NE(NULL, p3);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(2, iprofiler->GetProfilesCount());
|
|
|
|
CHECK_NE(p2, p3);
|
|
|
|
CHECK(FindCpuProfile(cpu_profiler, p3));
|
|
|
|
CHECK(FindCpuProfile(cpu_profiler, p2));
|
2014-03-28 09:24:49 +00:00
|
|
|
p2->Delete();
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
|
|
|
CHECK(!FindCpuProfile(cpu_profiler, p2));
|
|
|
|
CHECK(FindCpuProfile(cpu_profiler, p3));
|
2014-03-28 09:24:49 +00:00
|
|
|
p3->Delete();
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-05 07:17:08 +00:00
|
|
|
TEST(ProfileStartEndTime) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::String> profile_name =
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "test");
|
2014-03-28 09:24:49 +00:00
|
|
|
cpu_profiler->StartProfiling(profile_name);
|
|
|
|
const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
|
2013-08-05 07:17:08 +00:00
|
|
|
CHECK(profile->GetStartTime() <= profile->GetEndTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
static v8::CpuProfile* RunProfiler(
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::Handle<v8::Context> env, v8::Handle<v8::Function> function,
|
2013-07-10 12:56:58 +00:00
|
|
|
v8::Handle<v8::Value> argv[], int argc,
|
2014-04-25 18:53:06 +00:00
|
|
|
unsigned min_js_samples, bool collect_samples = false) {
|
2013-07-10 12:56:58 +00:00
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::String> profile_name =
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
|
2013-07-10 12:56:58 +00:00
|
|
|
|
2014-04-25 18:53:06 +00:00
|
|
|
cpu_profiler->StartProfiling(profile_name, collect_samples);
|
2013-07-10 12:56:58 +00:00
|
|
|
|
|
|
|
i::Sampler* sampler =
|
|
|
|
reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler();
|
|
|
|
sampler->StartCountingSamples();
|
|
|
|
do {
|
|
|
|
function->Call(env->Global(), argc, argv);
|
|
|
|
} while (sampler->js_and_external_sample_count() < min_js_samples);
|
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
|
2013-07-10 12:56:58 +00:00
|
|
|
|
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
2014-03-28 09:24:49 +00:00
|
|
|
reinterpret_cast<i::CpuProfile*>(profile)->Print();
|
2013-07-10 12:56:58 +00:00
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
static const v8::CpuProfileNode* FindChild(v8::Isolate* isolate,
|
|
|
|
const v8::CpuProfileNode* node,
|
2013-04-10 09:47:44 +00:00
|
|
|
const char* name) {
|
|
|
|
int count = node->GetChildrenCount();
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> nameHandle = v8::String::NewFromUtf8(isolate, name);
|
2013-04-10 09:47:44 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
const v8::CpuProfileNode* child = node->GetChild(i);
|
|
|
|
if (nameHandle->Equals(child->GetFunctionName())) return child;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
static const v8::CpuProfileNode* GetChild(v8::Isolate* isolate,
|
|
|
|
const v8::CpuProfileNode* node,
|
2013-05-24 16:19:06 +00:00
|
|
|
const char* name) {
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* result = FindChild(isolate, node, name);
|
2013-10-10 13:03:41 +00:00
|
|
|
if (!result) {
|
|
|
|
char buffer[100];
|
2014-06-13 16:43:27 +00:00
|
|
|
i::SNPrintF(Vector<char>(buffer, ARRAY_SIZE(buffer)),
|
|
|
|
"Failed to GetChild: %s", name);
|
2013-10-10 13:03:41 +00:00
|
|
|
FATAL(buffer);
|
|
|
|
}
|
2013-05-24 16:19:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
static void CheckSimpleBranch(v8::Isolate* isolate,
|
|
|
|
const v8::CpuProfileNode* node,
|
2013-04-10 09:47:44 +00:00
|
|
|
const char* names[], int length) {
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
const char* name = names[i];
|
2013-11-22 12:43:17 +00:00
|
|
|
node = GetChild(isolate, 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());
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
cpu_profiler_test_source))->Run();
|
2013-04-10 09:47:44 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-04-10 09:47:44 +00:00
|
|
|
|
2013-04-15 14:45:38 +00:00
|
|
|
int32_t profiling_interval_ms = 200;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)
|
|
|
|
};
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200);
|
2013-04-15 14:45:38 +00:00
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
2013-04-10 09:47:44 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-04-10 09:47:44 +00:00
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
2013-04-10 09:47:44 +00:00
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* fooNode =
|
|
|
|
GetChild(env->GetIsolate(), startNode, "foo");
|
2013-04-10 09:47:44 +00:00
|
|
|
CHECK_EQ(3, fooNode->GetChildrenCount());
|
|
|
|
|
|
|
|
const char* barBranch[] = { "bar", "delay", "loop" };
|
2013-11-22 12:43:17 +00:00
|
|
|
CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch,
|
|
|
|
ARRAY_SIZE(barBranch));
|
2013-04-10 09:47:44 +00:00
|
|
|
const char* bazBranch[] = { "baz", "delay", "loop" };
|
2013-11-22 12:43:17 +00:00
|
|
|
CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch,
|
|
|
|
ARRAY_SIZE(bazBranch));
|
2013-04-10 09:47:44 +00:00
|
|
|
const char* delayBranch[] = { "delay", "loop" };
|
2013-11-22 12:43:17 +00:00
|
|
|
CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch,
|
|
|
|
ARRAY_SIZE(delayBranch));
|
2013-04-10 14:31:13 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-04-10 09:47:44 +00:00
|
|
|
}
|
2013-05-14 22:51:33 +00:00
|
|
|
|
|
|
|
|
2014-05-22 05:36:27 +00:00
|
|
|
static const char* hot_deopt_no_frame_entry_test_source =
|
|
|
|
"function foo(a, b) {\n"
|
|
|
|
" try {\n"
|
|
|
|
" return a + b;\n"
|
|
|
|
" } catch (e) { }\n"
|
|
|
|
"}\n"
|
|
|
|
"function start(timeout) {\n"
|
|
|
|
" var start = Date.now();\n"
|
|
|
|
" do {\n"
|
|
|
|
" for (var i = 1; i < 1000; ++i) foo(1, i);\n"
|
|
|
|
" var duration = Date.now() - start;\n"
|
|
|
|
" } while (duration < timeout);\n"
|
|
|
|
" 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]
|
|
|
|
// 2 2 (program) [-1]
|
|
|
|
// 6 6 (garbage collector) [-1]
|
|
|
|
//
|
|
|
|
// The test checks no FP ranges are present in a deoptimized funcion.
|
|
|
|
// If 'foo' has no ranges the samples falling into the prologue will miss the
|
|
|
|
// 'start' function on the stack, so 'foo' will be attached to the (root).
|
|
|
|
TEST(HotDeoptNoFrameEntry) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(),
|
|
|
|
hot_deopt_no_frame_entry_test_source))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
|
|
|
|
|
|
|
int32_t profiling_interval_ms = 200;
|
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)
|
|
|
|
};
|
|
|
|
v8::CpuProfile* profile =
|
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200);
|
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
|
|
|
|
|
|
|
GetChild(env->GetIsolate(), startNode, "foo");
|
|
|
|
|
|
|
|
profile->Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 18:53:06 +00:00
|
|
|
TEST(CollectCpuProfileSamples) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
cpu_profiler_test_source))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
|
|
|
|
|
|
|
int32_t profiling_interval_ms = 200;
|
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)
|
|
|
|
};
|
|
|
|
v8::CpuProfile* profile =
|
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200, true);
|
|
|
|
|
|
|
|
CHECK_LE(200, profile->GetSamplesCount());
|
|
|
|
uint64_t end_time = profile->GetEndTime();
|
|
|
|
uint64_t current_time = profile->GetStartTime();
|
|
|
|
CHECK_LE(current_time, end_time);
|
|
|
|
for (int i = 0; i < profile->GetSamplesCount(); i++) {
|
|
|
|
CHECK_NE(NULL, profile->GetSample(i));
|
|
|
|
uint64_t timestamp = profile->GetSampleTimestamp(i);
|
|
|
|
CHECK_LE(current_time, timestamp);
|
|
|
|
CHECK_LE(timestamp, end_time);
|
|
|
|
current_time = timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile->Delete();
|
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
|
2013-10-10 13:03:41 +00:00
|
|
|
// Check that the profile tree doesn't contain unexpected traces:
|
2013-05-14 22:51:33 +00:00
|
|
|
// - '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());
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), cpu_profiler_test_source2))->Run();
|
2013-05-14 22:51:33 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-05-14 22:51:33 +00:00
|
|
|
|
|
|
|
int32_t repeat_count = 100;
|
|
|
|
#if defined(USE_SIMULATOR)
|
|
|
|
// Simulators are much slower.
|
|
|
|
repeat_count = 1;
|
|
|
|
#endif
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(env->GetIsolate(), repeat_count)
|
|
|
|
};
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
|
2013-05-14 22:51:33 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-05-14 22:51:33 +00:00
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
FindChild(env->GetIsolate(), 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-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* delayNode =
|
|
|
|
GetChild(env->GetIsolate(), startNode, "delay");
|
2013-05-14 22:51:33 +00:00
|
|
|
if (delayNode->GetChildrenCount() > 0) {
|
|
|
|
CHECK_EQ(1, delayNode->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), delayNode, "loop");
|
2013-05-14 22:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-05-14 22:51:33 +00:00
|
|
|
}
|
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";
|
|
|
|
|
|
|
|
|
2013-06-11 15:00:41 +00:00
|
|
|
class TestApiCallbacks {
|
2013-06-04 10:57:32 +00:00
|
|
|
public:
|
2013-06-11 15:00:41 +00:00
|
|
|
explicit TestApiCallbacks(int min_duration_ms)
|
2013-06-05 06:15:41 +00:00
|
|
|
: min_duration_ms_(min_duration_ms),
|
2013-06-11 08:32:48 +00:00
|
|
|
is_warming_up_(false) {}
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2013-07-17 12:16:16 +00:00
|
|
|
static void Getter(v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2013-06-11 15:00:41 +00:00
|
|
|
TestApiCallbacks* data = fromInfo(info);
|
2013-06-11 08:32:48 +00:00
|
|
|
data->Wait();
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Setter(v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
2013-07-17 12:16:16 +00:00
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
2013-06-11 15:00:41 +00:00
|
|
|
TestApiCallbacks* data = fromInfo(info);
|
|
|
|
data->Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Callback(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
TestApiCallbacks* data = fromInfo(info);
|
2013-06-11 08:32:48 +00:00
|
|
|
data->Wait();
|
2013-06-05 06:15:41 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 08:32:48 +00:00
|
|
|
void set_warming_up(bool value) { is_warming_up_ = value; }
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
private:
|
2013-06-11 08:32:48 +00:00
|
|
|
void Wait() {
|
|
|
|
if (is_warming_up_) return;
|
2014-06-30 13:25:46 +00:00
|
|
|
double start = v8::base::OS::TimeCurrentMillis();
|
2013-06-05 06:15:41 +00:00
|
|
|
double duration = 0;
|
|
|
|
while (duration < min_duration_ms_) {
|
2014-06-30 13:25:46 +00:00
|
|
|
v8::base::OS::Sleep(1);
|
|
|
|
duration = v8::base::OS::TimeCurrentMillis() - start;
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 12:16:16 +00:00
|
|
|
template<typename T>
|
|
|
|
static TestApiCallbacks* fromInfo(const T& info) {
|
2013-06-04 10:57:32 +00:00
|
|
|
void* data = v8::External::Cast(*info.Data())->Value();
|
2013-06-11 15:00:41 +00:00
|
|
|
return reinterpret_cast<TestApiCallbacks*>(data);
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int min_duration_ms_;
|
2013-06-11 08:32:48 +00:00
|
|
|
bool is_warming_up_;
|
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.
|
2013-06-11 08:32:48 +00:00
|
|
|
TEST(NativeAccessorUninitializedIC) {
|
2013-06-04 10:57:32 +00:00
|
|
|
LocalContext env;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> func_template =
|
|
|
|
v8::FunctionTemplate::New(isolate);
|
2013-06-04 10:57:32 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> instance_template =
|
|
|
|
func_template->InstanceTemplate();
|
|
|
|
|
2013-06-11 15:00:41 +00:00
|
|
|
TestApiCallbacks accessors(100);
|
2013-11-12 11:44:58 +00:00
|
|
|
v8::Local<v8::External> data =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &accessors);
|
2013-06-04 10:57:32 +00:00
|
|
|
instance_template->SetAccessor(
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::String::NewFromUtf8(isolate, "foo"),
|
2013-11-22 12:43:17 +00:00
|
|
|
&TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data);
|
2013-06-04 10:57:32 +00:00
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
|
|
|
v8::Local<v8::Object> instance = func->NewInstance();
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
|
2013-11-22 12:43:17 +00:00
|
|
|
instance);
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::String::NewFromUtf8(isolate, native_accessor_test_source))
|
2013-11-22 12:43:17 +00:00
|
|
|
->Run();
|
2013-06-04 10:57:32 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
int32_t repeat_count = 1;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 180);
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
2013-12-18 10:31:42 +00:00
|
|
|
GetChild(isolate, root, "start");
|
|
|
|
GetChild(isolate, startNode, "get foo");
|
|
|
|
GetChild(isolate, startNode, "set foo");
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
2013-06-11 08:32:48 +00:00
|
|
|
TEST(NativeAccessorMonomorphicIC) {
|
2013-06-04 10:57:32 +00:00
|
|
|
LocalContext env;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> func_template =
|
|
|
|
v8::FunctionTemplate::New(isolate);
|
2013-06-04 10:57:32 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> instance_template =
|
|
|
|
func_template->InstanceTemplate();
|
|
|
|
|
2013-06-11 15:00:41 +00:00
|
|
|
TestApiCallbacks accessors(1);
|
2013-11-12 11:44:58 +00:00
|
|
|
v8::Local<v8::External> data =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &accessors);
|
2013-06-04 10:57:32 +00:00
|
|
|
instance_template->SetAccessor(
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::String::NewFromUtf8(isolate, "foo"),
|
2013-11-22 12:43:17 +00:00
|
|
|
&TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data);
|
2013-06-04 10:57:32 +00:00
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
|
|
|
v8::Local<v8::Object> instance = func->NewInstance();
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
|
2013-11-22 12:43:17 +00:00
|
|
|
instance);
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::String::NewFromUtf8(isolate, native_accessor_test_source))
|
2013-11-22 12:43:17 +00:00
|
|
|
->Run();
|
2013-06-04 10:57:32 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2013-06-11 08:32:48 +00:00
|
|
|
{
|
|
|
|
// Make sure accessors ICs are in monomorphic state before starting
|
|
|
|
// profiling.
|
|
|
|
accessors.set_warming_up(true);
|
|
|
|
int32_t warm_up_iterations = 3;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(isolate, warm_up_iterations)
|
|
|
|
};
|
2013-06-11 08:32:48 +00:00
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
|
|
|
accessors.set_warming_up(false);
|
|
|
|
}
|
|
|
|
|
2013-06-04 10:57:32 +00:00
|
|
|
int32_t repeat_count = 100;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200);
|
2013-06-04 10:57:32 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
2013-12-18 10:31:42 +00:00
|
|
|
GetChild(isolate, root, "start");
|
|
|
|
GetChild(isolate, startNode, "get foo");
|
|
|
|
GetChild(isolate, startNode, "set foo");
|
2013-06-04 10:57:32 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-06-04 10:57:32 +00:00
|
|
|
}
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const char* native_method_test_source = "function start(count) {\n"
|
|
|
|
" for (var i = 0; i < count; i++) {\n"
|
|
|
|
" instance.fooMethod();\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NativeMethodUninitializedIC) {
|
|
|
|
LocalContext env;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
TestApiCallbacks callbacks(100);
|
2013-11-12 11:44:58 +00:00
|
|
|
v8::Local<v8::External> data =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &callbacks);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> func_template =
|
|
|
|
v8::FunctionTemplate::New(isolate);
|
2013-11-22 12:43:17 +00:00
|
|
|
func_template->SetClassName(
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor"));
|
2013-06-11 15:00:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> proto_template =
|
|
|
|
func_template->PrototypeTemplate();
|
2013-11-28 08:21:26 +00:00
|
|
|
v8::Local<v8::Signature> signature =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Signature::New(isolate, func_template);
|
|
|
|
proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"),
|
|
|
|
v8::FunctionTemplate::New(isolate,
|
|
|
|
&TestApiCallbacks::Callback,
|
2013-11-22 12:43:17 +00:00
|
|
|
data, signature, 0));
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
|
|
|
v8::Local<v8::Object> instance = func->NewInstance();
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
|
2013-11-22 12:43:17 +00:00
|
|
|
instance);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(
|
2013-12-18 10:31:42 +00:00
|
|
|
isolate, native_method_test_source))->Run();
|
2013-06-11 15:00:41 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
int32_t repeat_count = 1;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
2013-12-18 10:31:42 +00:00
|
|
|
GetChild(isolate, root, "start");
|
|
|
|
GetChild(isolate, startNode, "fooMethod");
|
2013-06-11 15:00:41 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-06-11 15:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NativeMethodMonomorphicIC) {
|
|
|
|
LocalContext env;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
TestApiCallbacks callbacks(1);
|
2013-11-12 11:44:58 +00:00
|
|
|
v8::Local<v8::External> data =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &callbacks);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> func_template =
|
|
|
|
v8::FunctionTemplate::New(isolate);
|
2013-11-22 12:43:17 +00:00
|
|
|
func_template->SetClassName(
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor"));
|
2013-06-11 15:00:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> proto_template =
|
|
|
|
func_template->PrototypeTemplate();
|
2013-11-28 08:21:26 +00:00
|
|
|
v8::Local<v8::Signature> signature =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Signature::New(isolate, func_template);
|
|
|
|
proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"),
|
|
|
|
v8::FunctionTemplate::New(isolate,
|
|
|
|
&TestApiCallbacks::Callback,
|
2013-11-22 12:43:17 +00:00
|
|
|
data, signature, 0));
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
|
|
|
v8::Local<v8::Object> instance = func->NewInstance();
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
|
2013-11-22 12:43:17 +00:00
|
|
|
instance);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(
|
2013-12-18 10:31:42 +00:00
|
|
|
isolate, native_method_test_source))->Run();
|
2013-06-11 15:00:41 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
|
2013-06-11 15:00:41 +00:00
|
|
|
{
|
|
|
|
// Make sure method ICs are in monomorphic state before starting
|
|
|
|
// profiling.
|
|
|
|
callbacks.set_warming_up(true);
|
|
|
|
int32_t warm_up_iterations = 3;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(isolate, warm_up_iterations)
|
|
|
|
};
|
2013-06-11 15:00:41 +00:00
|
|
|
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
|
|
|
callbacks.set_warming_up(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t repeat_count = 100;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
|
2013-06-11 15:00:41 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
2013-12-18 10:31:42 +00:00
|
|
|
GetChild(isolate, root, "start");
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
2013-12-18 10:31:42 +00:00
|
|
|
GetChild(isolate, root, "start");
|
|
|
|
GetChild(isolate, startNode, "fooMethod");
|
2013-06-11 15:00:41 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-06-11 15:00:41 +00:00
|
|
|
}
|
2013-06-27 09:28:11 +00:00
|
|
|
|
|
|
|
|
2014-07-11 09:06:12 +00:00
|
|
|
static const char* bound_function_test_source =
|
|
|
|
"function foo() {\n"
|
|
|
|
" startProfiling('my_profile');\n"
|
|
|
|
"}\n"
|
|
|
|
"function start() {\n"
|
|
|
|
" var callback = foo.bind(this);\n"
|
|
|
|
" callback();\n"
|
|
|
|
"}";
|
2013-06-27 09:28:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(BoundFunctionCall) {
|
2014-07-11 09:06:12 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
2013-06-27 09:28:11 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source))
|
|
|
|
->Run();
|
2013-06-27 09:28:11 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-06-27 09:28:11 +00:00
|
|
|
|
2014-07-11 09:06:12 +00:00
|
|
|
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
|
2013-06-27 09:28:11 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-06-27 09:28:11 +00:00
|
|
|
// Don't allow |foo| node to be at the top level.
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
|
|
|
GetChild(env->GetIsolate(), startNode, "foo");
|
2013-06-27 09:28:11 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-06-27 09:28:11 +00:00
|
|
|
}
|
2013-07-02 07:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const char* call_function_test_source = "function bar(iterations) {\n"
|
|
|
|
"}\n"
|
|
|
|
"function start(duration) {\n"
|
|
|
|
" var start = Date.now();\n"
|
|
|
|
" while (Date.now() - start < duration) {\n"
|
|
|
|
" try {\n"
|
|
|
|
" bar.call(this, 10 * 1000);\n"
|
|
|
|
" } catch(e) {}\n"
|
|
|
|
" }\n"
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
|
|
// Test that if we sampled thread when it was inside FunctionCall buitin then
|
|
|
|
// its caller frame will be '(unresolved function)' as we have no reliable way
|
|
|
|
// to resolve it.
|
|
|
|
//
|
|
|
|
// [Top down]:
|
|
|
|
// 96 0 (root) [-1] #1
|
|
|
|
// 1 1 (garbage collector) [-1] #4
|
|
|
|
// 5 0 (unresolved function) [-1] #5
|
|
|
|
// 5 5 call [-1] #6
|
|
|
|
// 71 70 start [-1] #3
|
|
|
|
// 1 1 bar [-1] #7
|
|
|
|
// 19 19 (program) [-1] #2
|
|
|
|
TEST(FunctionCallSample) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2013-07-08 11:26:15 +00:00
|
|
|
// Collect garbage that might have be generated while installing extensions.
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
|
2013-07-08 11:26:15 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), call_function_test_source))->Run();
|
2013-07-02 07:51:09 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-07-02 07:51:09 +00:00
|
|
|
|
|
|
|
int32_t duration_ms = 100;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(env->GetIsolate(), duration_ms)
|
|
|
|
};
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
|
2013-07-02 07:51:09 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
{
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(4);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
|
|
|
names[3] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), i::ProfileGenerator::kUnresolvedFunctionName);
|
2013-07-02 07:51:09 +00:00
|
|
|
// Don't allow |bar| and |call| nodes to be at the top level.
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
}
|
|
|
|
|
Fix test-cpu-profiler/FunctionCallSample flakiness under GC stress testing
The test flakes on "V8 GC Stress" bots and the sample looks like this:
[Top down]:
90 0 (root) [-1] #0 1
1 1 (program) [-1] #0 2
89 89 (garbage collector) [-1] #0 3
which means that almost all samples are inside GC and we have no |start| node in the collected profile.
Running the test with different combinations of --gc-interval=500 and --stress-compaction flags gives the results quoted below. They don't give a ground to require |start| node presense in the profile when doing GC stress testing. So this change makes the |start| node optional in the collected profile if GC stress testing is on.
$ ./out/ia32.debug/cctest --gc-interval=500 --stress-compaction --trace-gc test-cpu-profiler/FunctionCallSample
[10291] 76 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 49.5 ms (+ 0.2 ms in 1 steps since start of marking, biggest step 0.2 ms) [StackGuard GC request] [GC in old space requested].
[10291] 110 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 25.3 ms [Logger::LogCompiledFunctions] [GC in old space requested].
[10291] 135 ms: Mark-sweep 0.4 (17.8) -> 0.4 (17.8) MB, 22.8 ms [Logger::LogAccessorCallbacks] [GC in old space requested].
[10291] 179 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 39.9 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [Runtime::PerformGC] [GC in old space forced by flags].
[10291] 209 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 29.1 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [Runtime::PerformGC] [GC in old space forced by flags].
[10291] 240 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 29.1 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [Runtime::PerformGC] [GC in old space forced by flags].
[Top down]:
99 0 (root) [-1] #0 1
4 4 start [-1] #16 3
93 93 (garbage collector) [-1] #0 4
2 2 (program) [-1] #0 2
$ ./out/ia32.debug/cctest --gc-interval=500 --trace-gc test-cpu-profiler/FunctionCallSample
[10328] 46 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 14.9 ms [Logger::LogCompiledFunctions] [GC in old space requested].
[10328] 61 ms: Mark-sweep 0.4 (17.8) -> 0.4 (17.8) MB, 12.9 ms [Logger::LogAccessorCallbacks] [GC in old space requested].
[10328] 65 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 67 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 69 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 70 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 72 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 73 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 75 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 77 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 78 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 80 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 81 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 83 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 85 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 86 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 88 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 89 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 91 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 93 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 94 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 96 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 97 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 99 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 101 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 102 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 104 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 105 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 107 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 109 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 110 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 112 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 113 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 115 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 117 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 118 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 120 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 121 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 123 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 125 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 126 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 128 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 129 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 131 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 133 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 134 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 136 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 137 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 139 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 141 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 142 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 144 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 145 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 147 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 149 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 150 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 152 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 153 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 155 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 157 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 158 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 160 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 162 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 163 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[Top down]:
95 0 (root) [-1] #0 1
12 11 start [-1] #16 3
1 1 bar [-1] #16 4
81 81 (garbage collector) [-1] #0 5
2 2 (program) [-1] #0 2
$ ./out/ia32.debug/cctest --stress-compaction --trace-gc test-cpu-profiler/FunctionCallSample
[10355] 76 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 49.9 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [StackGuard GC request] [GC in old space requested].
[10355] 110 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 25.5 ms [Logger::LogCompiledFunctions] [GC in old space requested].
[10355] 135 ms: Mark-sweep 0.4 (17.8) -> 0.4 (17.8) MB, 22.9 ms [Logger::LogAccessorCallbacks] [GC in old space requested].
[10355] 189 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 49.8 ms (+ 0.2 ms in 1 steps since start of marking, biggest step 0.2 ms) [StackGuard GC request] [GC in old space requested].
[10355] 234 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 42.5 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [StackGuard GC request] [GC in old space requested].
[10355] 278 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 42.5 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [StackGuard GC request] [GC in old space requested].
[Top down]:
135 0 (root) [-1] #0 1
6 6 start [-1] #16 3
127 127 (garbage collector) [-1] #0 4
2 2 (program) [-1] #0 2
BUG=None
R=jkummerow@chromium.org, loislo@chromium.org
Review URL: https://codereview.chromium.org/18068012
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15471 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-07-03 14:26:38 +00:00
|
|
|
// In case of GC stress tests all samples may be in GC phase and there
|
|
|
|
// won't be |start| node in the profiles.
|
|
|
|
bool is_gc_stress_testing =
|
|
|
|
(i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction;
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
FindChild(env->GetIsolate(), root, "start");
|
Fix test-cpu-profiler/FunctionCallSample flakiness under GC stress testing
The test flakes on "V8 GC Stress" bots and the sample looks like this:
[Top down]:
90 0 (root) [-1] #0 1
1 1 (program) [-1] #0 2
89 89 (garbage collector) [-1] #0 3
which means that almost all samples are inside GC and we have no |start| node in the collected profile.
Running the test with different combinations of --gc-interval=500 and --stress-compaction flags gives the results quoted below. They don't give a ground to require |start| node presense in the profile when doing GC stress testing. So this change makes the |start| node optional in the collected profile if GC stress testing is on.
$ ./out/ia32.debug/cctest --gc-interval=500 --stress-compaction --trace-gc test-cpu-profiler/FunctionCallSample
[10291] 76 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 49.5 ms (+ 0.2 ms in 1 steps since start of marking, biggest step 0.2 ms) [StackGuard GC request] [GC in old space requested].
[10291] 110 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 25.3 ms [Logger::LogCompiledFunctions] [GC in old space requested].
[10291] 135 ms: Mark-sweep 0.4 (17.8) -> 0.4 (17.8) MB, 22.8 ms [Logger::LogAccessorCallbacks] [GC in old space requested].
[10291] 179 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 39.9 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [Runtime::PerformGC] [GC in old space forced by flags].
[10291] 209 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 29.1 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [Runtime::PerformGC] [GC in old space forced by flags].
[10291] 240 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 29.1 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [Runtime::PerformGC] [GC in old space forced by flags].
[Top down]:
99 0 (root) [-1] #0 1
4 4 start [-1] #16 3
93 93 (garbage collector) [-1] #0 4
2 2 (program) [-1] #0 2
$ ./out/ia32.debug/cctest --gc-interval=500 --trace-gc test-cpu-profiler/FunctionCallSample
[10328] 46 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 14.9 ms [Logger::LogCompiledFunctions] [GC in old space requested].
[10328] 61 ms: Mark-sweep 0.4 (17.8) -> 0.4 (17.8) MB, 12.9 ms [Logger::LogAccessorCallbacks] [GC in old space requested].
[10328] 65 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 67 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 69 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 70 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 72 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 73 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 75 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 77 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 78 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 80 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 81 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 83 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 85 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 86 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 88 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 89 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 91 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 93 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 94 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 96 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 97 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 99 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 101 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 102 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 104 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 105 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 107 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 109 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 110 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 112 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 113 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 115 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 117 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 118 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 120 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 121 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 123 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 125 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 126 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 128 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 129 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 131 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 133 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 134 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 136 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 137 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 139 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 141 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 142 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 144 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 145 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 147 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 149 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 150 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 152 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 153 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.3 ms [Runtime::PerformGC].
[10328] 155 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 157 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 158 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 160 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 162 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[10328] 163 ms: Scavenge 0.5 (17.8) -> 0.4 (17.8) MB, 1.2 ms [Runtime::PerformGC].
[Top down]:
95 0 (root) [-1] #0 1
12 11 start [-1] #16 3
1 1 bar [-1] #16 4
81 81 (garbage collector) [-1] #0 5
2 2 (program) [-1] #0 2
$ ./out/ia32.debug/cctest --stress-compaction --trace-gc test-cpu-profiler/FunctionCallSample
[10355] 76 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 49.9 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [StackGuard GC request] [GC in old space requested].
[10355] 110 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 25.5 ms [Logger::LogCompiledFunctions] [GC in old space requested].
[10355] 135 ms: Mark-sweep 0.4 (17.8) -> 0.4 (17.8) MB, 22.9 ms [Logger::LogAccessorCallbacks] [GC in old space requested].
[10355] 189 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 49.8 ms (+ 0.2 ms in 1 steps since start of marking, biggest step 0.2 ms) [StackGuard GC request] [GC in old space requested].
[10355] 234 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 42.5 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [StackGuard GC request] [GC in old space requested].
[10355] 278 ms: Mark-sweep 0.5 (17.8) -> 0.4 (17.8) MB, 42.5 ms (+ 0.1 ms in 1 steps since start of marking, biggest step 0.1 ms) [StackGuard GC request] [GC in old space requested].
[Top down]:
135 0 (root) [-1] #0 1
6 6 start [-1] #16 3
127 127 (garbage collector) [-1] #0 4
2 2 (program) [-1] #0 2
BUG=None
R=jkummerow@chromium.org, loislo@chromium.org
Review URL: https://codereview.chromium.org/18068012
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15471 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-07-03 14:26:38 +00:00
|
|
|
CHECK(is_gc_stress_testing || startNode);
|
|
|
|
if (startNode) {
|
2013-07-03 14:04:37 +00:00
|
|
|
ScopedVector<v8::Handle<v8::String> > names(2);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "bar");
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(), "call");
|
2013-07-02 07:51:09 +00:00
|
|
|
CheckChildrenNames(startNode, names);
|
|
|
|
}
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* unresolvedNode = FindChild(
|
|
|
|
env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName);
|
2013-07-02 07:51:09 +00:00
|
|
|
if (unresolvedNode) {
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(1);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call");
|
2013-07-02 07:51:09 +00:00
|
|
|
CheckChildrenNames(unresolvedNode, names);
|
|
|
|
}
|
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-07-02 07:51:09 +00:00
|
|
|
}
|
|
|
|
|
2013-07-03 14:04:37 +00:00
|
|
|
|
|
|
|
static const char* function_apply_test_source = "function bar(iterations) {\n"
|
|
|
|
"}\n"
|
|
|
|
"function test() {\n"
|
|
|
|
" bar.apply(this, [10 * 1000]);\n"
|
|
|
|
"}\n"
|
|
|
|
"function start(duration) {\n"
|
|
|
|
" var start = Date.now();\n"
|
|
|
|
" while (Date.now() - start < duration) {\n"
|
|
|
|
" try {\n"
|
|
|
|
" test();\n"
|
|
|
|
" } catch(e) {}\n"
|
|
|
|
" }\n"
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
|
|
// [Top down]:
|
|
|
|
// 94 0 (root) [-1] #0 1
|
|
|
|
// 2 2 (garbage collector) [-1] #0 7
|
|
|
|
// 82 49 start [-1] #16 3
|
|
|
|
// 1 0 (unresolved function) [-1] #0 8
|
|
|
|
// 1 1 apply [-1] #0 9
|
|
|
|
// 32 21 test [-1] #16 4
|
|
|
|
// 2 2 bar [-1] #16 6
|
|
|
|
// 9 9 apply [-1] #0 5
|
|
|
|
// 10 10 (program) [-1] #0 2
|
|
|
|
TEST(FunctionApplySample) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), function_apply_test_source))
|
|
|
|
->Run();
|
2013-07-03 14:04:37 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-07-03 14:04:37 +00:00
|
|
|
|
|
|
|
int32_t duration_ms = 100;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Handle<v8::Value> args[] = {
|
|
|
|
v8::Integer::New(env->GetIsolate(), duration_ms)
|
|
|
|
};
|
2013-07-03 14:04:37 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile =
|
2014-01-17 10:52:00 +00:00
|
|
|
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
|
2013-07-03 14:04:37 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
{
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-07-03 14:04:37 +00:00
|
|
|
// Don't allow |test|, |bar| and |apply| nodes to be at the top level.
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
}
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
FindChild(env->GetIsolate(), root, "start");
|
2013-07-03 14:04:37 +00:00
|
|
|
if (startNode) {
|
|
|
|
{
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(2);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "test");
|
|
|
|
names[1] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kUnresolvedFunctionName);
|
2013-07-03 14:04:37 +00:00
|
|
|
CheckChildrenNames(startNode, names);
|
|
|
|
}
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* testNode =
|
|
|
|
FindChild(env->GetIsolate(), startNode, "test");
|
2013-07-03 14:04:37 +00:00
|
|
|
if (testNode) {
|
2014-05-08 09:47:17 +00:00
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "bar");
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(), "apply");
|
2014-05-08 09:47:17 +00:00
|
|
|
// apply calls "get length" before invoking the function itself
|
|
|
|
// and we may get hit into it.
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "get length");
|
2013-07-03 14:04:37 +00:00
|
|
|
CheckChildrenNames(testNode, names);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const v8::CpuProfileNode* unresolvedNode =
|
2013-11-22 12:43:17 +00:00
|
|
|
FindChild(env->GetIsolate(), startNode,
|
|
|
|
ProfileGenerator::kUnresolvedFunctionName)) {
|
2013-07-03 14:04:37 +00:00
|
|
|
ScopedVector<v8::Handle<v8::String> > names(1);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply");
|
2013-07-03 14:04:37 +00:00
|
|
|
CheckChildrenNames(unresolvedNode, names);
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), unresolvedNode, "apply");
|
2013-07-03 14:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-07-03 14:04:37 +00:00
|
|
|
}
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
|
2014-06-24 16:00:51 +00:00
|
|
|
static const char* cpu_profiler_deep_stack_test_source =
|
|
|
|
"function foo(n) {\n"
|
|
|
|
" if (n)\n"
|
|
|
|
" foo(n - 1);\n"
|
|
|
|
" else\n"
|
|
|
|
" startProfiling('my_profile');\n"
|
|
|
|
"}\n"
|
|
|
|
"function start() {\n"
|
|
|
|
" foo(250);\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Check a deep stack
|
|
|
|
//
|
|
|
|
// [Top down]:
|
|
|
|
// 0 (root) 0 #1
|
|
|
|
// 2 (program) 0 #2
|
|
|
|
// 0 start 21 #3 no reason
|
|
|
|
// 0 foo 21 #4 no reason
|
|
|
|
// 0 foo 21 #5 no reason
|
|
|
|
// ....
|
|
|
|
// 0 foo 21 #253 no reason
|
|
|
|
// 1 startProfiling 0 #254
|
|
|
|
TEST(CpuProfileDeepStack) {
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
|
|
|
|
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), cpu_profiler_deep_stack_test_source))->Run();
|
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
|
|
|
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
v8::Local<v8::String> profile_name =
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
|
|
|
|
function->Call(env->Global(), 0, NULL);
|
|
|
|
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
|
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
|
|
|
reinterpret_cast<i::CpuProfile*>(profile)->Print();
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
{
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
}
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* node =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
|
|
|
for (int i = 0; i < 250; ++i) {
|
|
|
|
node = GetChild(env->GetIsolate(), node, "foo");
|
|
|
|
}
|
|
|
|
// TODO(alph):
|
|
|
|
// In theory there must be one more 'foo' and a 'startProfiling' nodes,
|
|
|
|
// but due to unstable top frame extraction these might be missing.
|
|
|
|
|
|
|
|
profile->Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-10 13:03:41 +00:00
|
|
|
static const char* js_native_js_test_source =
|
2014-07-11 09:06:12 +00:00
|
|
|
"function foo() {\n"
|
|
|
|
" startProfiling('my_profile');\n"
|
|
|
|
"}\n"
|
|
|
|
"function bar() {\n"
|
|
|
|
" try { foo(); } catch(e) {}\n"
|
|
|
|
"}\n"
|
|
|
|
"function start() {\n"
|
|
|
|
" try {\n"
|
|
|
|
" CallJsFunction(bar);\n"
|
|
|
|
" } catch(e) {}\n"
|
|
|
|
"}";
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
v8::Handle<v8::Function> function = info[0].As<v8::Function>();
|
|
|
|
v8::Handle<v8::Value> argv[] = { info[1] };
|
|
|
|
function->Call(info.This(), ARRAY_SIZE(argv), argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// [Top down]:
|
|
|
|
// 58 0 (root) #0 1
|
|
|
|
// 2 2 (program) #0 2
|
|
|
|
// 56 1 start #16 3
|
|
|
|
// 55 0 CallJsFunction #0 4
|
|
|
|
// 55 1 bar #16 5
|
|
|
|
// 54 54 foo #16 6
|
|
|
|
TEST(JsNativeJsSample) {
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->GetIsolate(), CallJsFunction);
|
2013-07-23 15:01:38 +00:00
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
2013-11-22 12:43:17 +00:00
|
|
|
func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
|
|
|
|
env->Global()->Set(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
js_native_js_test_source))->Run();
|
2013-07-23 15:01:38 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-07-11 09:06:12 +00:00
|
|
|
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
{
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-07-23 15:01:38 +00:00
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
}
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
2013-07-23 15:01:38 +00:00
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
|
|
|
const v8::CpuProfileNode* nativeFunctionNode =
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), startNode, "CallJsFunction");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* barNode =
|
|
|
|
GetChild(env->GetIsolate(), nativeFunctionNode, "bar");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
CHECK_EQ(1, barNode->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), barNode, "foo");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-07-23 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char* js_native_js_runtime_js_test_source =
|
2014-07-11 09:06:12 +00:00
|
|
|
"function foo() {\n"
|
|
|
|
" startProfiling('my_profile');\n"
|
|
|
|
"}\n"
|
|
|
|
"var bound = foo.bind(this);\n"
|
|
|
|
"function bar() {\n"
|
|
|
|
" try { bound(); } catch(e) {}\n"
|
|
|
|
"}\n"
|
|
|
|
"function start() {\n"
|
|
|
|
" try {\n"
|
|
|
|
" CallJsFunction(bar);\n"
|
|
|
|
" } catch(e) {}\n"
|
|
|
|
"}";
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
// [Top down]:
|
|
|
|
// 57 0 (root) #0 1
|
|
|
|
// 55 1 start #16 3
|
|
|
|
// 54 0 CallJsFunction #0 4
|
|
|
|
// 54 3 bar #16 5
|
|
|
|
// 51 51 foo #16 6
|
|
|
|
// 2 2 (program) #0 2
|
|
|
|
TEST(JsNativeJsRuntimeJsSample) {
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->GetIsolate(), CallJsFunction);
|
2013-07-23 15:01:38 +00:00
|
|
|
v8::Local<v8::Function> func = func_template->GetFunction();
|
2013-11-22 12:43:17 +00:00
|
|
|
func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
|
|
|
|
env->Global()->Set(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
js_native_js_runtime_js_test_source))->Run();
|
2013-07-23 15:01:38 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-07-11 09:06:12 +00:00
|
|
|
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-07-23 15:01:38 +00:00
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
2013-07-23 15:01:38 +00:00
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
|
|
|
const v8::CpuProfileNode* nativeFunctionNode =
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), startNode, "CallJsFunction");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* barNode =
|
|
|
|
GetChild(env->GetIsolate(), nativeFunctionNode, "bar");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-05-08 09:47:17 +00:00
|
|
|
// The child is in fact a bound foo.
|
|
|
|
// A bound function has a wrapper that may make calls to
|
|
|
|
// other functions e.g. "get length".
|
|
|
|
CHECK_LE(1, barNode->GetChildrenCount());
|
|
|
|
CHECK_GE(2, barNode->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), barNode, "foo");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-07-23 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
2014-07-01 10:10:12 +00:00
|
|
|
v8::base::OS::Print("In CallJsFunction2\n");
|
2013-07-23 15:01:38 +00:00
|
|
|
CallJsFunction(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char* js_native1_js_native2_js_test_source =
|
2014-07-11 09:06:12 +00:00
|
|
|
"function foo() {\n"
|
|
|
|
" try {\n"
|
|
|
|
" startProfiling('my_profile');\n"
|
|
|
|
" } catch(e) {}\n"
|
|
|
|
"}\n"
|
|
|
|
"function bar() {\n"
|
|
|
|
" CallJsFunction2(foo);\n"
|
|
|
|
"}\n"
|
|
|
|
"function start() {\n"
|
|
|
|
" try {\n"
|
|
|
|
" CallJsFunction1(bar);\n"
|
|
|
|
" } catch(e) {}\n"
|
|
|
|
"}";
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
// [Top down]:
|
|
|
|
// 57 0 (root) #0 1
|
|
|
|
// 55 1 start #16 3
|
|
|
|
// 54 0 CallJsFunction1 #0 4
|
|
|
|
// 54 0 bar #16 5
|
|
|
|
// 54 0 CallJsFunction2 #0 6
|
|
|
|
// 54 54 foo #16 7
|
|
|
|
// 2 2 (program) #0 2
|
|
|
|
TEST(JsNative1JsNative2JsSample) {
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->GetIsolate(), CallJsFunction);
|
2013-07-23 15:01:38 +00:00
|
|
|
v8::Local<v8::Function> func1 = func_template->GetFunction();
|
2013-11-22 12:43:17 +00:00
|
|
|
func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"));
|
|
|
|
env->Global()->Set(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> func2 = v8::FunctionTemplate::New(
|
2013-12-18 10:31:42 +00:00
|
|
|
env->GetIsolate(), CallJsFunction2)->GetFunction();
|
2013-11-22 12:43:17 +00:00
|
|
|
func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"));
|
|
|
|
env->Global()->Set(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
js_native1_js_native2_js_test_source))->Run();
|
2013-07-23 15:01:38 +00:00
|
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
2013-11-22 12:43:17 +00:00
|
|
|
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-07-11 09:06:12 +00:00
|
|
|
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
|
2013-07-23 15:01:38 +00:00
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* startNode =
|
|
|
|
GetChild(env->GetIsolate(), root, "start");
|
2013-07-23 15:01:38 +00:00
|
|
|
CHECK_EQ(1, startNode->GetChildrenCount());
|
|
|
|
const v8::CpuProfileNode* nativeNode1 =
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), startNode, "CallJsFunction1");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
CHECK_EQ(1, nativeNode1->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* barNode =
|
|
|
|
GetChild(env->GetIsolate(), nativeNode1, "bar");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
CHECK_EQ(1, barNode->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* nativeNode2 =
|
|
|
|
GetChild(env->GetIsolate(), barNode, "CallJsFunction2");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
|
|
|
CHECK_EQ(1, nativeNode2->GetChildrenCount());
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), nativeNode2, "foo");
|
2013-07-23 15:01:38 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-07-23 15:01:38 +00:00
|
|
|
}
|
2013-08-07 17:04:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
// [Top down]:
|
|
|
|
// 6 0 (root) #0 1
|
|
|
|
// 3 3 (program) #0 2
|
|
|
|
// 3 3 (idle) #0 3
|
|
|
|
TEST(IdleTime) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::String> profile_name =
|
|
|
|
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
|
2014-03-28 09:24:49 +00:00
|
|
|
cpu_profiler->StartProfiling(profile_name);
|
2013-08-07 17:04:27 +00:00
|
|
|
|
2013-09-19 09:17:13 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
2013-08-07 17:04:27 +00:00
|
|
|
i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor();
|
|
|
|
processor->AddCurrentStack(isolate);
|
|
|
|
|
|
|
|
cpu_profiler->SetIdle(true);
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
processor->AddCurrentStack(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_profiler->SetIdle(false);
|
|
|
|
processor->AddCurrentStack(isolate);
|
|
|
|
|
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
|
2013-08-07 17:04:27 +00:00
|
|
|
CHECK_NE(NULL, profile);
|
|
|
|
// Dump collected profile to have a better diagnostic in case of failure.
|
2014-03-28 09:24:49 +00:00
|
|
|
reinterpret_cast<i::CpuProfile*>(profile)->Print();
|
2013-08-07 17:04:27 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
|
|
|
ScopedVector<v8::Handle<v8::String> > names(3);
|
2013-11-22 12:43:17 +00:00
|
|
|
names[0] = v8::String::NewFromUtf8(
|
|
|
|
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
|
|
|
|
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kProgramEntryName);
|
|
|
|
names[2] = v8::String::NewFromUtf8(env->GetIsolate(),
|
|
|
|
ProfileGenerator::kIdleEntryName);
|
2013-08-07 17:04:27 +00:00
|
|
|
CheckChildrenNames(root, names);
|
|
|
|
|
|
|
|
const v8::CpuProfileNode* programNode =
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName);
|
2013-08-07 17:04:27 +00:00
|
|
|
CHECK_EQ(0, programNode->GetChildrenCount());
|
2013-08-09 07:38:26 +00:00
|
|
|
CHECK_GE(programNode->GetHitCount(), 3);
|
2013-08-07 17:04:27 +00:00
|
|
|
|
|
|
|
const v8::CpuProfileNode* idleNode =
|
2013-11-22 12:43:17 +00:00
|
|
|
GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName);
|
2013-08-07 17:04:27 +00:00
|
|
|
CHECK_EQ(0, idleNode->GetChildrenCount());
|
2013-08-09 07:38:26 +00:00
|
|
|
CHECK_GE(idleNode->GetHitCount(), 3);
|
2013-08-07 17:04:27 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
profile->Delete();
|
2013-08-07 17:04:27 +00:00
|
|
|
}
|
2013-10-10 13:15:47 +00:00
|
|
|
|
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
static void CheckFunctionDetails(v8::Isolate* isolate,
|
|
|
|
const v8::CpuProfileNode* node,
|
|
|
|
const char* name, const char* script_name,
|
|
|
|
int script_id, int line, int column) {
|
|
|
|
CHECK_EQ(v8::String::NewFromUtf8(isolate, name),
|
|
|
|
node->GetFunctionName());
|
|
|
|
CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name),
|
|
|
|
node->GetScriptResourceName());
|
2013-10-10 13:15:47 +00:00
|
|
|
CHECK_EQ(script_id, node->GetScriptId());
|
|
|
|
CHECK_EQ(line, node->GetLineNumber());
|
|
|
|
CHECK_EQ(column, node->GetColumnNumber());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FunctionDetails) {
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
2013-10-10 13:15:47 +00:00
|
|
|
|
2014-03-14 10:20:33 +00:00
|
|
|
v8::Handle<v8::Script> script_a = CompileWithOrigin(
|
2013-11-22 12:43:17 +00:00
|
|
|
" function foo\n() { try { bar(); } catch(e) {} }\n"
|
2014-03-14 10:20:33 +00:00
|
|
|
" function bar() { startProfiling(); }\n",
|
|
|
|
"script_a");
|
2013-10-10 13:15:47 +00:00
|
|
|
script_a->Run();
|
2014-03-14 10:20:33 +00:00
|
|
|
v8::Handle<v8::Script> script_b = CompileWithOrigin(
|
2013-11-22 12:43:17 +00:00
|
|
|
"\n\n function baz() { try { foo(); } catch(e) {} }\n"
|
|
|
|
"\n\nbaz();\n"
|
2014-03-14 10:20:33 +00:00
|
|
|
"stopProfiling();\n",
|
|
|
|
"script_b");
|
2013-10-10 13:15:47 +00:00
|
|
|
script_b->Run();
|
2014-01-17 10:52:00 +00:00
|
|
|
const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
|
2013-10-10 13:15:47 +00:00
|
|
|
const v8::CpuProfileNode* current = profile->GetTopDownRoot();
|
|
|
|
reinterpret_cast<ProfileNode*>(
|
|
|
|
const_cast<v8::CpuProfileNode*>(current))->Print(0);
|
|
|
|
// The tree should look like this:
|
|
|
|
// 0 (root) 0 #1
|
2014-08-05 07:08:39 +00:00
|
|
|
// 0 "" 19 #2 no reason script_b:1
|
2013-10-10 13:15:47 +00:00
|
|
|
// 0 baz 19 #3 TryCatchStatement script_b:3
|
|
|
|
// 0 foo 18 #4 TryCatchStatement script_a:2
|
|
|
|
// 1 bar 18 #5 no reason script_a:3
|
|
|
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
2014-08-05 07:08:39 +00:00
|
|
|
const v8::CpuProfileNode* script = GetChild(env->GetIsolate(), root, "");
|
|
|
|
CheckFunctionDetails(env->GetIsolate(), script, "", "script_b",
|
2014-06-05 13:02:18 +00:00
|
|
|
script_b->GetUnboundScript()->GetId(), 1, 1);
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* baz = GetChild(env->GetIsolate(), script, "baz");
|
|
|
|
CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b",
|
2014-06-05 13:02:18 +00:00
|
|
|
script_b->GetUnboundScript()->GetId(), 3, 16);
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* foo = GetChild(env->GetIsolate(), baz, "foo");
|
|
|
|
CheckFunctionDetails(env->GetIsolate(), foo, "foo", "script_a",
|
2014-06-05 13:02:18 +00:00
|
|
|
script_a->GetUnboundScript()->GetId(), 2, 1);
|
2013-11-22 12:43:17 +00:00
|
|
|
const v8::CpuProfileNode* bar = GetChild(env->GetIsolate(), foo, "bar");
|
|
|
|
CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a",
|
2014-06-05 13:02:18 +00:00
|
|
|
script_a->GetUnboundScript()->GetId(), 3, 14);
|
2013-10-10 13:15:47 +00:00
|
|
|
}
|
2013-12-11 14:39:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(DontStopOnFinishedProfileDelete) {
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
|
|
|
|
v8::Context::Scope context_scope(env);
|
2013-12-11 14:39:18 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
|
|
|
|
v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
|
2013-12-18 08:59:09 +00:00
|
|
|
i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
|
2013-12-11 14:39:18 +00:00
|
|
|
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2013-12-11 14:39:18 +00:00
|
|
|
v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer");
|
2014-03-28 09:24:49 +00:00
|
|
|
profiler->StartProfiling(outer);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2013-12-11 14:39:18 +00:00
|
|
|
|
|
|
|
v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner");
|
2014-03-28 09:24:49 +00:00
|
|
|
profiler->StartProfiling(inner);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2013-12-11 14:39:18 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* inner_profile = profiler->StopProfiling(inner);
|
2013-12-11 14:39:18 +00:00
|
|
|
CHECK(inner_profile);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
2014-03-28 09:24:49 +00:00
|
|
|
inner_profile->Delete();
|
2013-12-11 14:39:18 +00:00
|
|
|
inner_profile = NULL;
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2013-12-11 14:39:18 +00:00
|
|
|
|
2014-03-28 09:24:49 +00:00
|
|
|
v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
|
2013-12-11 14:39:18 +00:00
|
|
|
CHECK(outer_profile);
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
2014-03-28 09:24:49 +00:00
|
|
|
outer_profile->Delete();
|
2013-12-11 14:39:18 +00:00
|
|
|
outer_profile = NULL;
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2013-12-11 14:39:18 +00:00
|
|
|
}
|