Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1650)

Unified Diff: test/cctest/test-cpu-profiler.cc

Issue 18053004: CpuProfiler: eliminate 2 layers of 4 for CodeCreateEvent calls. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: all tests were fixed Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc
index 2184122717770be2eb0203fd9933394828e7f0e5..c5d47c6d72193779f0e230b7e42f244966671300 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -97,64 +97,87 @@ class TestSetup {
} // namespace
+
+i::Code* CreateCode(LocalContext* env) {
+ static int counter = 0;
+ char script[256];
+ char name[32];
+ snprintf(name, sizeof(name), "function_%d", ++counter);
+ snprintf(script, sizeof(script),
+ "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, counter, name, name);
+ CompileRun(script);
+ i::Handle<i::JSFunction> fun = v8::Utils::OpenHandle(
+ *v8::Local<v8::Function>::Cast((*env)->Global()->Get(v8_str(name))));
+ fprintf(stderr, "code size: %d\n", fun->code()->ExecutableSize());
+ return fun->code();
+}
+
+
TEST(CodeEvents) {
CcTest::InitializeVM();
+ LocalContext env;
i::Isolate* isolate = i::Isolate::Current();
- i::Heap* heap = isolate->heap();
i::Factory* factory = isolate->factory();
TestSetup test_setup;
- CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
- ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator, &profiles);
+
+ 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);
+
+ CpuProfilesCollection* profiles = new CpuProfilesCollection;
+ profiles->StartProfiling("", 1, false);
+ ProfileGenerator generator(profiles);
+ ProfilerEventsProcessor processor(&generator, profiles);
processor.Start();
+ CpuProfiler profiler(isolate, profiles, &generator, &processor);
// Enqueue code creation events.
- i::HandleScope scope(isolate);
const char* aaa_str = "aaa";
i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
- processor.CodeCreateEvent(i::Logger::FUNCTION_TAG,
- *aaa_name,
- heap->empty_string(),
- 0,
- ToAddress(0x1000),
- 0x100,
- ToAddress(0x10000),
- NULL);
- processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
- "bbb",
- ToAddress(0x1200),
- 0x80);
- processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
- processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
- "ddd",
- ToAddress(0x1400),
- 0x80);
- processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500));
- processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10);
- processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10);
+ 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);
+
// Enqueue a tick event to enable code events processing.
- EnqueueTickSampleEvent(&processor, ToAddress(0x1000));
+ EnqueueTickSampleEvent(&processor, aaa_code->address());
processor.Stop();
processor.Join();
// Check the state of profile generator.
- CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000));
- CHECK_NE(NULL, entry1);
- CHECK_EQ(aaa_str, entry1->name());
- CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200));
- CHECK_NE(NULL, entry2);
- CHECK_EQ("bbb", entry2->name());
- CodeEntry* entry3 = generator.code_map()->FindEntry(ToAddress(0x1300));
- CHECK_NE(NULL, entry3);
- CHECK_EQ("5", entry3->name());
- CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1400)));
- CodeEntry* entry4 = generator.code_map()->FindEntry(ToAddress(0x1500));
- CHECK_NE(NULL, entry4);
- CHECK_EQ("ddd", entry4->name());
- CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1600)));
+ 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());
}
@@ -165,32 +188,39 @@ static int CompareProfileNodes(const T* p1, const T* p2) {
TEST(TickEvents) {
TestSetup test_setup;
- CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
- ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator, &profiles);
+ LocalContext env;
+ i::Isolate* isolate = i::Isolate::Current();
+ i::HandleScope scope(isolate);
+
+ i::Code* frame1_code = CreateCode(&env);
+ i::Code* frame2_code = CreateCode(&env);
+ i::Code* frame3_code = CreateCode(&env);
+
+ CpuProfilesCollection* profiles = new CpuProfilesCollection;
+ profiles->StartProfiling("", 1, false);
+ ProfileGenerator generator(profiles);
+ ProfilerEventsProcessor processor(&generator, profiles);
processor.Start();
+ CpuProfiler profiler(isolate, profiles, &generator, &processor);
- processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
- "bbb",
- ToAddress(0x1200),
- 0x80);
- processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
- processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
- "ddd",
- ToAddress(0x1400),
- 0x80);
- EnqueueTickSampleEvent(&processor, ToAddress(0x1210));
- EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220));
+ 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");
+
+ EnqueueTickSampleEvent(&processor,
+ frame1_code->address() + 0x10);
yurys 2013/06/28 11:33:43 frame1_code->address() + 0x10 -> (frame1_code->ins
EnqueueTickSampleEvent(&processor,
- ToAddress(0x1404),
- ToAddress(0x1305),
- ToAddress(0x1230));
+ frame2_code->address() + 0x5,
+ frame1_code->address() + 0x20);
+ EnqueueTickSampleEvent(&processor,
+ frame3_code->address() + 0x3,
+ frame2_code->address() + 0x5,
+ frame1_code->address() + 0x20);
processor.Stop();
processor.Join();
CpuProfile* profile =
- profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
+ profiles->StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
CHECK_NE(NULL, profile);
// Check call trees.
@@ -229,29 +259,33 @@ TEST(CrashIfStoppingLastNonExistentProfile) {
// Long stacks (exceeding max frames limit) must not be erased.
TEST(Issue1398) {
TestSetup test_setup;
- CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
- ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator, &profiles);
+ LocalContext env;
+ i::Isolate* isolate = i::Isolate::Current();
+ i::HandleScope scope(isolate);
+
+ i::Code* code = CreateCode(&env);
+
+ CpuProfilesCollection* profiles = new CpuProfilesCollection;
+ profiles->StartProfiling("", 1, false);
+ ProfileGenerator generator(profiles);
+ ProfilerEventsProcessor processor(&generator, profiles);
processor.Start();
+ CpuProfiler profiler(isolate, profiles, &generator, &processor);
- processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
- "bbb",
- ToAddress(0x1200),
- 0x80);
+ profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
i::TickSample* sample = processor.TickSampleEvent();
- sample->pc = ToAddress(0x1200);
+ sample->pc = code->address();
sample->tos = 0;
sample->frames_count = i::TickSample::kMaxFramesCount;
for (int i = 0; i < sample->frames_count; ++i) {
- sample->stack[i] = ToAddress(0x1200);
+ sample->stack[i] = code->address();
}
processor.Stop();
processor.Join();
CpuProfile* profile =
- profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
+ profiles->StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
CHECK_NE(NULL, profile);
int actual_depth = 0;

Powered by Google App Engine
This is Rietveld 408576698