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

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 157503002: A64: Synchronize with r18444. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 // 27 //
28 // Tests of profiles generator and utilities. 28 // Tests of profiles generator and utilities.
29 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "cpu-profiler-inl.h" 31 #include "cpu-profiler-inl.h"
32 #include "cctest.h" 32 #include "cctest.h"
33 #include "platform.h" 33 #include "platform.h"
34 #include "profiler-extension.h"
34 #include "smart-pointers.h" 35 #include "smart-pointers.h"
35 #include "utils.h" 36 #include "utils.h"
36 #include "../include/v8-profiler.h" 37 #include "../include/v8-profiler.h"
37 using i::CodeEntry; 38 using i::CodeEntry;
38 using i::CpuProfile; 39 using i::CpuProfile;
39 using i::CpuProfiler; 40 using i::CpuProfiler;
40 using i::CpuProfilesCollection; 41 using i::CpuProfilesCollection;
41 using i::Heap; 42 using i::Heap;
42 using i::ProfileGenerator; 43 using i::ProfileGenerator;
43 using i::ProfileNode; 44 using i::ProfileNode;
44 using i::ProfilerEventsProcessor; 45 using i::ProfilerEventsProcessor;
45 using i::ScopedVector; 46 using i::ScopedVector;
46 using i::SmartPointer; 47 using i::SmartPointer;
47 using i::TimeDelta; 48 using i::TimeDelta;
48 using i::Vector; 49 using i::Vector;
49 50
50 51
51 TEST(StartStop) { 52 TEST(StartStop) {
52 i::Isolate* isolate = CcTest::i_isolate(); 53 i::Isolate* isolate = CcTest::i_isolate();
53 CpuProfilesCollection profiles(isolate->heap()); 54 CpuProfilesCollection profiles(isolate->heap());
54 ProfileGenerator generator(&profiles); 55 ProfileGenerator generator(&profiles);
55 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 56 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
56 &generator, NULL, TimeDelta::FromMicroseconds(100))); 57 &generator, NULL, TimeDelta::FromMicroseconds(100)));
57 processor->Start(); 58 processor->Start();
58 processor->StopSynchronously(); 59 processor->StopSynchronously();
59 } 60 }
60 61
61 62
62 static inline i::Address ToAddress(int n) {
63 return reinterpret_cast<i::Address>(n);
64 }
65
66 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, 63 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
67 i::Address frame1, 64 i::Address frame1,
68 i::Address frame2 = NULL, 65 i::Address frame2 = NULL,
69 i::Address frame3 = NULL) { 66 i::Address frame3 = NULL) {
70 i::TickSample* sample = proc->StartTickSample(); 67 i::TickSample* sample = proc->StartTickSample();
71 sample->pc = frame1; 68 sample->pc = frame1;
72 sample->tos = frame1; 69 sample->tos = frame1;
73 sample->frames_count = 0; 70 sample->frames_count = 0;
74 if (frame2 != NULL) { 71 if (frame2 != NULL) {
75 sample->stack[0] = frame2; 72 sample->stack[0] = frame2;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 132
136 i::Code* aaa_code = CreateCode(&env); 133 i::Code* aaa_code = CreateCode(&env);
137 i::Code* comment_code = CreateCode(&env); 134 i::Code* comment_code = CreateCode(&env);
138 i::Code* args5_code = CreateCode(&env); 135 i::Code* args5_code = CreateCode(&env);
139 i::Code* comment2_code = CreateCode(&env); 136 i::Code* comment2_code = CreateCode(&env);
140 i::Code* moved_code = CreateCode(&env); 137 i::Code* moved_code = CreateCode(&env);
141 i::Code* args3_code = CreateCode(&env); 138 i::Code* args3_code = CreateCode(&env);
142 i::Code* args4_code = CreateCode(&env); 139 i::Code* args4_code = CreateCode(&env);
143 140
144 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 141 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
145 profiles->StartProfiling("", 1, false); 142 profiles->StartProfiling("", false);
146 ProfileGenerator generator(profiles); 143 ProfileGenerator generator(profiles);
147 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 144 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
148 &generator, NULL, TimeDelta::FromMicroseconds(100))); 145 &generator, NULL, TimeDelta::FromMicroseconds(100)));
149 processor->Start(); 146 processor->Start();
150 CpuProfiler profiler(isolate, profiles, &generator, *processor); 147 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
151 148
152 // Enqueue code creation events. 149 // Enqueue code creation events.
153 const char* aaa_str = "aaa"; 150 const char* aaa_str = "aaa";
154 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( 151 i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
155 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); 152 i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
156 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); 153 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name);
157 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); 154 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment");
158 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); 155 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
159 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); 156 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2");
160 profiler.CodeMoveEvent(comment2_code->address(), moved_code->address()); 157 profiler.CodeMoveEvent(comment2_code->address(), moved_code->address());
161 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3); 158 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3);
162 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4); 159 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4);
163 160
164 // Enqueue a tick event to enable code events processing. 161 // Enqueue a tick event to enable code events processing.
165 EnqueueTickSampleEvent(*processor, aaa_code->address()); 162 EnqueueTickSampleEvent(processor.get(), aaa_code->address());
166 163
167 processor->StopSynchronously(); 164 processor->StopSynchronously();
168 165
169 // Check the state of profile generator. 166 // Check the state of profile generator.
170 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address()); 167 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address());
171 CHECK_NE(NULL, aaa); 168 CHECK_NE(NULL, aaa);
172 CHECK_EQ(aaa_str, aaa->name()); 169 CHECK_EQ(aaa_str, aaa->name());
173 170
174 CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address()); 171 CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address());
175 CHECK_NE(NULL, comment); 172 CHECK_NE(NULL, comment);
(...skipping 21 matching lines...) Expand all
197 TestSetup test_setup; 194 TestSetup test_setup;
198 LocalContext env; 195 LocalContext env;
199 i::Isolate* isolate = CcTest::i_isolate(); 196 i::Isolate* isolate = CcTest::i_isolate();
200 i::HandleScope scope(isolate); 197 i::HandleScope scope(isolate);
201 198
202 i::Code* frame1_code = CreateCode(&env); 199 i::Code* frame1_code = CreateCode(&env);
203 i::Code* frame2_code = CreateCode(&env); 200 i::Code* frame2_code = CreateCode(&env);
204 i::Code* frame3_code = CreateCode(&env); 201 i::Code* frame3_code = CreateCode(&env);
205 202
206 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 203 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
207 profiles->StartProfiling("", 1, false); 204 profiles->StartProfiling("", false);
208 ProfileGenerator generator(profiles); 205 ProfileGenerator generator(profiles);
209 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 206 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
210 &generator, NULL, TimeDelta::FromMicroseconds(100))); 207 &generator, NULL, TimeDelta::FromMicroseconds(100)));
211 processor->Start(); 208 processor->Start();
212 CpuProfiler profiler(isolate, profiles, &generator, *processor); 209 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
213 210
214 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); 211 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb");
215 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); 212 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
216 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); 213 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
217 214
218 EnqueueTickSampleEvent(*processor, frame1_code->instruction_start()); 215 EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start());
219 EnqueueTickSampleEvent( 216 EnqueueTickSampleEvent(
220 *processor, 217 processor.get(),
221 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, 218 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2,
222 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); 219 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2);
223 EnqueueTickSampleEvent( 220 EnqueueTickSampleEvent(
224 *processor, 221 processor.get(),
225 frame3_code->instruction_end() - 1, 222 frame3_code->instruction_end() - 1,
226 frame2_code->instruction_end() - 1, 223 frame2_code->instruction_end() - 1,
227 frame1_code->instruction_end() - 1); 224 frame1_code->instruction_end() - 1);
228 225
229 processor->StopSynchronously(); 226 processor->StopSynchronously();
230 CpuProfile* profile = profiles->StopProfiling(""); 227 CpuProfile* profile = profiles->StopProfiling("");
231 CHECK_NE(NULL, profile); 228 CHECK_NE(NULL, profile);
232 229
233 // Check call trees. 230 // Check call trees.
234 const i::List<ProfileNode*>* top_down_root_children = 231 const i::List<ProfileNode*>* top_down_root_children =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Long stacks (exceeding max frames limit) must not be erased. 263 // Long stacks (exceeding max frames limit) must not be erased.
267 TEST(Issue1398) { 264 TEST(Issue1398) {
268 TestSetup test_setup; 265 TestSetup test_setup;
269 LocalContext env; 266 LocalContext env;
270 i::Isolate* isolate = CcTest::i_isolate(); 267 i::Isolate* isolate = CcTest::i_isolate();
271 i::HandleScope scope(isolate); 268 i::HandleScope scope(isolate);
272 269
273 i::Code* code = CreateCode(&env); 270 i::Code* code = CreateCode(&env);
274 271
275 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 272 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
276 profiles->StartProfiling("", 1, false); 273 profiles->StartProfiling("", false);
277 ProfileGenerator generator(profiles); 274 ProfileGenerator generator(profiles);
278 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 275 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
279 &generator, NULL, TimeDelta::FromMicroseconds(100))); 276 &generator, NULL, TimeDelta::FromMicroseconds(100)));
280 processor->Start(); 277 processor->Start();
281 CpuProfiler profiler(isolate, profiles, &generator, *processor); 278 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
282 279
283 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); 280 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
284 281
285 i::TickSample* sample = processor->StartTickSample(); 282 i::TickSample* sample = processor->StartTickSample();
286 sample->pc = code->address(); 283 sample->pc = code->address();
287 sample->tos = 0; 284 sample->tos = 0;
288 sample->frames_count = i::TickSample::kMaxFramesCount; 285 sample->frames_count = i::TickSample::kMaxFramesCount;
289 for (int i = 0; i < sample->frames_count; ++i) { 286 for (int i = 0; i < sample->frames_count; ++i) {
290 sample->stack[i] = code->address(); 287 sample->stack[i] = code->address();
291 } 288 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 326
330 // Test profiling cancellation by the 'delete' command. 327 // Test profiling cancellation by the 'delete' command.
331 profiler->StartProfiling("1"); 328 profiler->StartProfiling("1");
332 profiler->StartProfiling("2"); 329 profiler->StartProfiling("2");
333 CHECK_EQ(0, profiler->GetProfilesCount()); 330 CHECK_EQ(0, profiler->GetProfilesCount());
334 profiler->DeleteAllProfiles(); 331 profiler->DeleteAllProfiles();
335 CHECK_EQ(0, profiler->GetProfilesCount()); 332 CHECK_EQ(0, profiler->GetProfilesCount());
336 } 333 }
337 334
338 335
339 static const v8::CpuProfile* FindCpuProfile(v8::CpuProfiler* profiler, 336 static bool FindCpuProfile(v8::CpuProfiler* v8profiler,
340 unsigned uid) { 337 const v8::CpuProfile* v8profile) {
341 int length = profiler->GetProfileCount(); 338 i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(v8profiler);
339 const i::CpuProfile* profile =
340 reinterpret_cast<const i::CpuProfile*>(v8profile);
341 int length = profiler->GetProfilesCount();
342 for (int i = 0; i < length; i++) { 342 for (int i = 0; i < length; i++) {
343 const v8::CpuProfile* profile = profiler->GetCpuProfile(i); 343 if (profile == profiler->GetProfile(i))
344 if (profile->GetUid() == uid) { 344 return true;
345 return profile;
346 }
347 } 345 }
348 return NULL; 346 return false;
349 } 347 }
350 348
351 349
352 TEST(DeleteCpuProfile) { 350 TEST(DeleteCpuProfile) {
353 LocalContext env; 351 LocalContext env;
354 v8::HandleScope scope(env->GetIsolate()); 352 v8::HandleScope scope(env->GetIsolate());
355 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 353 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
354 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler);
356 355
357 CHECK_EQ(0, cpu_profiler->GetProfileCount()); 356 CHECK_EQ(0, iprofiler->GetProfilesCount());
358 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1"); 357 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1");
359 cpu_profiler->StartCpuProfiling(name1); 358 cpu_profiler->StartCpuProfiling(name1);
360 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); 359 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
361 CHECK_NE(NULL, p1); 360 CHECK_NE(NULL, p1);
362 CHECK_EQ(1, cpu_profiler->GetProfileCount()); 361 CHECK_EQ(1, iprofiler->GetProfilesCount());
363 unsigned uid1 = p1->GetUid(); 362 CHECK(FindCpuProfile(cpu_profiler, p1));
364 CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1));
365 const_cast<v8::CpuProfile*>(p1)->Delete(); 363 const_cast<v8::CpuProfile*>(p1)->Delete();
366 CHECK_EQ(0, cpu_profiler->GetProfileCount()); 364 CHECK_EQ(0, iprofiler->GetProfilesCount());
367 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
368 365
369 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2"); 366 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2");
370 cpu_profiler->StartCpuProfiling(name2); 367 cpu_profiler->StartCpuProfiling(name2);
371 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2); 368 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2);
372 CHECK_NE(NULL, p2); 369 CHECK_NE(NULL, p2);
373 CHECK_EQ(1, cpu_profiler->GetProfileCount()); 370 CHECK_EQ(1, iprofiler->GetProfilesCount());
374 unsigned uid2 = p2->GetUid(); 371 CHECK(FindCpuProfile(cpu_profiler, p2));
375 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
376 CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2));
377 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
378 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3"); 372 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3");
379 cpu_profiler->StartCpuProfiling(name3); 373 cpu_profiler->StartCpuProfiling(name3);
380 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); 374 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
381 CHECK_NE(NULL, p3); 375 CHECK_NE(NULL, p3);
382 CHECK_EQ(2, cpu_profiler->GetProfileCount()); 376 CHECK_EQ(2, iprofiler->GetProfilesCount());
383 unsigned uid3 = p3->GetUid(); 377 CHECK_NE(p2, p3);
384 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); 378 CHECK(FindCpuProfile(cpu_profiler, p3));
385 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); 379 CHECK(FindCpuProfile(cpu_profiler, p2));
386 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
387 const_cast<v8::CpuProfile*>(p2)->Delete(); 380 const_cast<v8::CpuProfile*>(p2)->Delete();
388 CHECK_EQ(1, cpu_profiler->GetProfileCount()); 381 CHECK_EQ(1, iprofiler->GetProfilesCount());
389 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); 382 CHECK(!FindCpuProfile(cpu_profiler, p2));
390 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); 383 CHECK(FindCpuProfile(cpu_profiler, p3));
391 const_cast<v8::CpuProfile*>(p3)->Delete(); 384 const_cast<v8::CpuProfile*>(p3)->Delete();
392 CHECK_EQ(0, cpu_profiler->GetProfileCount()); 385 CHECK_EQ(0, iprofiler->GetProfilesCount());
393 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3));
394 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2));
395 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
396 } 386 }
397 387
398 388
399 TEST(ProfileStartEndTime) { 389 TEST(ProfileStartEndTime) {
400 LocalContext env; 390 LocalContext env;
401 v8::HandleScope scope(env->GetIsolate()); 391 v8::HandleScope scope(env->GetIsolate());
402 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 392 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
403 393
404 v8::Local<v8::String> profile_name = 394 v8::Local<v8::String> profile_name =
405 v8::String::NewFromUtf8(env->GetIsolate(), "test"); 395 v8::String::NewFromUtf8(env->GetIsolate(), "test");
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 const char* barBranch[] = { "bar", "delay", "loop" }; 576 const char* barBranch[] = { "bar", "delay", "loop" };
587 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, 577 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch,
588 ARRAY_SIZE(barBranch)); 578 ARRAY_SIZE(barBranch));
589 const char* bazBranch[] = { "baz", "delay", "loop" }; 579 const char* bazBranch[] = { "baz", "delay", "loop" };
590 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, 580 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch,
591 ARRAY_SIZE(bazBranch)); 581 ARRAY_SIZE(bazBranch));
592 const char* delayBranch[] = { "delay", "loop" }; 582 const char* delayBranch[] = { "delay", "loop" };
593 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, 583 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch,
594 ARRAY_SIZE(delayBranch)); 584 ARRAY_SIZE(delayBranch));
595 585
596 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 586 const_cast<v8::CpuProfile*>(profile)->Delete();
597 cpu_profiler->DeleteAllCpuProfiles();
598 } 587 }
599 588
600 589
601 590
602 static const char* cpu_profiler_test_source2 = "function loop() {}\n" 591 static const char* cpu_profiler_test_source2 = "function loop() {}\n"
603 "function delay() { loop(); }\n" 592 "function delay() { loop(); }\n"
604 "function start(count) {\n" 593 "function start(count) {\n"
605 " var k = 0;\n" 594 " var k = 0;\n"
606 " do {\n" 595 " do {\n"
607 " delay();\n" 596 " delay();\n"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 if (startNode && startNode->GetChildrenCount() > 0) { 643 if (startNode && startNode->GetChildrenCount() > 0) {
655 CHECK_EQ(1, startNode->GetChildrenCount()); 644 CHECK_EQ(1, startNode->GetChildrenCount());
656 const v8::CpuProfileNode* delayNode = 645 const v8::CpuProfileNode* delayNode =
657 GetChild(env->GetIsolate(), startNode, "delay"); 646 GetChild(env->GetIsolate(), startNode, "delay");
658 if (delayNode->GetChildrenCount() > 0) { 647 if (delayNode->GetChildrenCount() > 0) {
659 CHECK_EQ(1, delayNode->GetChildrenCount()); 648 CHECK_EQ(1, delayNode->GetChildrenCount());
660 GetChild(env->GetIsolate(), delayNode, "loop"); 649 GetChild(env->GetIsolate(), delayNode, "loop");
661 } 650 }
662 } 651 }
663 652
664 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 653 const_cast<v8::CpuProfile*>(profile)->Delete();
665 cpu_profiler->DeleteAllCpuProfiles();
666 } 654 }
667 655
668 656
669 static const char* native_accessor_test_source = "function start(count) {\n" 657 static const char* native_accessor_test_source = "function start(count) {\n"
670 " for (var i = 0; i < count; i++) {\n" 658 " for (var i = 0; i < count; i++) {\n"
671 " var o = instance.foo;\n" 659 " var o = instance.foo;\n"
672 " instance.foo = o + 1;\n" 660 " instance.foo = o + 1;\n"
673 " }\n" 661 " }\n"
674 "}\n"; 662 "}\n";
675 663
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 bool is_warming_up_; 709 bool is_warming_up_;
722 }; 710 };
723 711
724 712
725 // Test that native accessors are properly reported in the CPU profile. 713 // Test that native accessors are properly reported in the CPU profile.
726 // This test checks the case when the long-running accessors are called 714 // This test checks the case when the long-running accessors are called
727 // only once and the optimizer doesn't have chance to change the invocation 715 // only once and the optimizer doesn't have chance to change the invocation
728 // code. 716 // code.
729 TEST(NativeAccessorUninitializedIC) { 717 TEST(NativeAccessorUninitializedIC) {
730 LocalContext env; 718 LocalContext env;
731 v8::HandleScope scope(env->GetIsolate()); 719 v8::Isolate* isolate = env->GetIsolate();
720 v8::HandleScope scope(isolate);
732 721
733 722 v8::Local<v8::FunctionTemplate> func_template =
734 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 723 v8::FunctionTemplate::New(isolate);
735 v8::Local<v8::ObjectTemplate> instance_template = 724 v8::Local<v8::ObjectTemplate> instance_template =
736 func_template->InstanceTemplate(); 725 func_template->InstanceTemplate();
737 726
738 TestApiCallbacks accessors(100); 727 TestApiCallbacks accessors(100);
739 v8::Local<v8::External> data = 728 v8::Local<v8::External> data =
740 v8::External::New(env->GetIsolate(), &accessors); 729 v8::External::New(isolate, &accessors);
741 instance_template->SetAccessor( 730 instance_template->SetAccessor(
742 v8::String::NewFromUtf8(env->GetIsolate(), "foo"), 731 v8::String::NewFromUtf8(isolate, "foo"),
743 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); 732 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data);
744 v8::Local<v8::Function> func = func_template->GetFunction(); 733 v8::Local<v8::Function> func = func_template->GetFunction();
745 v8::Local<v8::Object> instance = func->NewInstance(); 734 v8::Local<v8::Object> instance = func->NewInstance();
746 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), 735 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
747 instance); 736 instance);
748 737
749 v8::Script::Compile( 738 v8::Script::Compile(
750 v8::String::NewFromUtf8(env->GetIsolate(), native_accessor_test_source)) 739 v8::String::NewFromUtf8(isolate, native_accessor_test_source))
751 ->Run(); 740 ->Run();
752 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 741 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
753 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 742 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
754 743
755 int32_t repeat_count = 1; 744 int32_t repeat_count = 1;
756 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 745 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
757 const v8::CpuProfile* profile = 746 const v8::CpuProfile* profile =
758 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); 747 RunProfiler(env, function, args, ARRAY_SIZE(args), 180);
759 748
760 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 749 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
761 const v8::CpuProfileNode* startNode = 750 const v8::CpuProfileNode* startNode =
762 GetChild(env->GetIsolate(), root, "start"); 751 GetChild(isolate, root, "start");
763 GetChild(env->GetIsolate(), startNode, "get foo"); 752 GetChild(isolate, startNode, "get foo");
764 GetChild(env->GetIsolate(), startNode, "set foo"); 753 GetChild(isolate, startNode, "set foo");
765 754
766 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 755 const_cast<v8::CpuProfile*>(profile)->Delete();
767 cpu_profiler->DeleteAllCpuProfiles();
768 } 756 }
769 757
770 758
771 // Test that native accessors are properly reported in the CPU profile. 759 // Test that native accessors are properly reported in the CPU profile.
772 // This test makes sure that the accessors are called enough times to become 760 // This test makes sure that the accessors are called enough times to become
773 // hot and to trigger optimizations. 761 // hot and to trigger optimizations.
774 TEST(NativeAccessorMonomorphicIC) { 762 TEST(NativeAccessorMonomorphicIC) {
775 LocalContext env; 763 LocalContext env;
776 v8::HandleScope scope(env->GetIsolate()); 764 v8::Isolate* isolate = env->GetIsolate();
765 v8::HandleScope scope(isolate);
777 766
778 767 v8::Local<v8::FunctionTemplate> func_template =
779 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 768 v8::FunctionTemplate::New(isolate);
780 v8::Local<v8::ObjectTemplate> instance_template = 769 v8::Local<v8::ObjectTemplate> instance_template =
781 func_template->InstanceTemplate(); 770 func_template->InstanceTemplate();
782 771
783 TestApiCallbacks accessors(1); 772 TestApiCallbacks accessors(1);
784 v8::Local<v8::External> data = 773 v8::Local<v8::External> data =
785 v8::External::New(env->GetIsolate(), &accessors); 774 v8::External::New(isolate, &accessors);
786 instance_template->SetAccessor( 775 instance_template->SetAccessor(
787 v8::String::NewFromUtf8(env->GetIsolate(), "foo"), 776 v8::String::NewFromUtf8(isolate, "foo"),
788 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); 777 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data);
789 v8::Local<v8::Function> func = func_template->GetFunction(); 778 v8::Local<v8::Function> func = func_template->GetFunction();
790 v8::Local<v8::Object> instance = func->NewInstance(); 779 v8::Local<v8::Object> instance = func->NewInstance();
791 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), 780 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
792 instance); 781 instance);
793 782
794 v8::Script::Compile( 783 v8::Script::Compile(
795 v8::String::NewFromUtf8(env->GetIsolate(), native_accessor_test_source)) 784 v8::String::NewFromUtf8(isolate, native_accessor_test_source))
796 ->Run(); 785 ->Run();
797 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 786 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
798 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 787 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
799 788
800 { 789 {
801 // Make sure accessors ICs are in monomorphic state before starting 790 // Make sure accessors ICs are in monomorphic state before starting
802 // profiling. 791 // profiling.
803 accessors.set_warming_up(true); 792 accessors.set_warming_up(true);
804 int32_t warm_up_iterations = 3; 793 int32_t warm_up_iterations = 3;
805 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; 794 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) };
806 function->Call(env->Global(), ARRAY_SIZE(args), args); 795 function->Call(env->Global(), ARRAY_SIZE(args), args);
807 accessors.set_warming_up(false); 796 accessors.set_warming_up(false);
808 } 797 }
809 798
810 int32_t repeat_count = 100; 799 int32_t repeat_count = 100;
811 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 800 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
812 const v8::CpuProfile* profile = 801 const v8::CpuProfile* profile =
813 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); 802 RunProfiler(env, function, args, ARRAY_SIZE(args), 200);
814 803
815 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 804 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
816 const v8::CpuProfileNode* startNode = 805 const v8::CpuProfileNode* startNode =
817 GetChild(env->GetIsolate(), root, "start"); 806 GetChild(isolate, root, "start");
818 GetChild(env->GetIsolate(), startNode, "get foo"); 807 GetChild(isolate, startNode, "get foo");
819 GetChild(env->GetIsolate(), startNode, "set foo"); 808 GetChild(isolate, startNode, "set foo");
820 809
821 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 810 const_cast<v8::CpuProfile*>(profile)->Delete();
822 cpu_profiler->DeleteAllCpuProfiles();
823 } 811 }
824 812
825 813
826 static const char* native_method_test_source = "function start(count) {\n" 814 static const char* native_method_test_source = "function start(count) {\n"
827 " for (var i = 0; i < count; i++) {\n" 815 " for (var i = 0; i < count; i++) {\n"
828 " instance.fooMethod();\n" 816 " instance.fooMethod();\n"
829 " }\n" 817 " }\n"
830 "}\n"; 818 "}\n";
831 819
832 820
833 TEST(NativeMethodUninitializedIC) { 821 TEST(NativeMethodUninitializedIC) {
834 LocalContext env; 822 LocalContext env;
835 v8::HandleScope scope(env->GetIsolate()); 823 v8::Isolate* isolate = env->GetIsolate();
824 v8::HandleScope scope(isolate);
836 825
837 TestApiCallbacks callbacks(100); 826 TestApiCallbacks callbacks(100);
838 v8::Local<v8::External> data = 827 v8::Local<v8::External> data =
839 v8::External::New(env->GetIsolate(), &callbacks); 828 v8::External::New(isolate, &callbacks);
840 829
841 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 830 v8::Local<v8::FunctionTemplate> func_template =
831 v8::FunctionTemplate::New(isolate);
842 func_template->SetClassName( 832 func_template->SetClassName(
843 v8::String::NewFromUtf8(env->GetIsolate(), "Test_InstanceCostructor")); 833 v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor"));
844 v8::Local<v8::ObjectTemplate> proto_template = 834 v8::Local<v8::ObjectTemplate> proto_template =
845 func_template->PrototypeTemplate(); 835 func_template->PrototypeTemplate();
846 v8::Local<v8::Signature> signature = 836 v8::Local<v8::Signature> signature =
847 v8::Signature::New(env->GetIsolate(), func_template); 837 v8::Signature::New(isolate, func_template);
848 proto_template->Set(v8::String::NewFromUtf8(env->GetIsolate(), "fooMethod"), 838 proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"),
849 v8::FunctionTemplate::New(&TestApiCallbacks::Callback, 839 v8::FunctionTemplate::New(isolate,
840 &TestApiCallbacks::Callback,
850 data, signature, 0)); 841 data, signature, 0));
851 842
852 v8::Local<v8::Function> func = func_template->GetFunction(); 843 v8::Local<v8::Function> func = func_template->GetFunction();
853 v8::Local<v8::Object> instance = func->NewInstance(); 844 v8::Local<v8::Object> instance = func->NewInstance();
854 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), 845 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
855 instance); 846 instance);
856 847
857 v8::Script::Compile(v8::String::NewFromUtf8( 848 v8::Script::Compile(v8::String::NewFromUtf8(
858 env->GetIsolate(), native_method_test_source))->Run(); 849 isolate, native_method_test_source))->Run();
859 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 850 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
860 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 851 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
861 852
862 int32_t repeat_count = 1; 853 int32_t repeat_count = 1;
863 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 854 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
864 const v8::CpuProfile* profile = 855 const v8::CpuProfile* profile =
865 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); 856 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
866 857
867 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 858 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
868 const v8::CpuProfileNode* startNode = 859 const v8::CpuProfileNode* startNode =
869 GetChild(env->GetIsolate(), root, "start"); 860 GetChild(isolate, root, "start");
870 GetChild(env->GetIsolate(), startNode, "fooMethod"); 861 GetChild(isolate, startNode, "fooMethod");
871 862
872 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 863 const_cast<v8::CpuProfile*>(profile)->Delete();
873 cpu_profiler->DeleteAllCpuProfiles();
874 } 864 }
875 865
876 866
877 TEST(NativeMethodMonomorphicIC) { 867 TEST(NativeMethodMonomorphicIC) {
878 LocalContext env; 868 LocalContext env;
879 v8::HandleScope scope(env->GetIsolate()); 869 v8::Isolate* isolate = env->GetIsolate();
870 v8::HandleScope scope(isolate);
880 871
881 TestApiCallbacks callbacks(1); 872 TestApiCallbacks callbacks(1);
882 v8::Local<v8::External> data = 873 v8::Local<v8::External> data =
883 v8::External::New(env->GetIsolate(), &callbacks); 874 v8::External::New(isolate, &callbacks);
884 875
885 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 876 v8::Local<v8::FunctionTemplate> func_template =
877 v8::FunctionTemplate::New(isolate);
886 func_template->SetClassName( 878 func_template->SetClassName(
887 v8::String::NewFromUtf8(env->GetIsolate(), "Test_InstanceCostructor")); 879 v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor"));
888 v8::Local<v8::ObjectTemplate> proto_template = 880 v8::Local<v8::ObjectTemplate> proto_template =
889 func_template->PrototypeTemplate(); 881 func_template->PrototypeTemplate();
890 v8::Local<v8::Signature> signature = 882 v8::Local<v8::Signature> signature =
891 v8::Signature::New(env->GetIsolate(), func_template); 883 v8::Signature::New(isolate, func_template);
892 proto_template->Set(v8::String::NewFromUtf8(env->GetIsolate(), "fooMethod"), 884 proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"),
893 v8::FunctionTemplate::New(&TestApiCallbacks::Callback, 885 v8::FunctionTemplate::New(isolate,
886 &TestApiCallbacks::Callback,
894 data, signature, 0)); 887 data, signature, 0));
895 888
896 v8::Local<v8::Function> func = func_template->GetFunction(); 889 v8::Local<v8::Function> func = func_template->GetFunction();
897 v8::Local<v8::Object> instance = func->NewInstance(); 890 v8::Local<v8::Object> instance = func->NewInstance();
898 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), 891 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
899 instance); 892 instance);
900 893
901 v8::Script::Compile(v8::String::NewFromUtf8( 894 v8::Script::Compile(v8::String::NewFromUtf8(
902 env->GetIsolate(), native_method_test_source))->Run(); 895 isolate, native_method_test_source))->Run();
903 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 896 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
904 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 897 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
905 { 898 {
906 // Make sure method ICs are in monomorphic state before starting 899 // Make sure method ICs are in monomorphic state before starting
907 // profiling. 900 // profiling.
908 callbacks.set_warming_up(true); 901 callbacks.set_warming_up(true);
909 int32_t warm_up_iterations = 3; 902 int32_t warm_up_iterations = 3;
910 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; 903 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) };
911 function->Call(env->Global(), ARRAY_SIZE(args), args); 904 function->Call(env->Global(), ARRAY_SIZE(args), args);
912 callbacks.set_warming_up(false); 905 callbacks.set_warming_up(false);
913 } 906 }
914 907
915 int32_t repeat_count = 100; 908 int32_t repeat_count = 100;
916 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 909 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
917 const v8::CpuProfile* profile = 910 const v8::CpuProfile* profile =
918 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); 911 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
919 912
920 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 913 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
921 GetChild(env->GetIsolate(), root, "start"); 914 GetChild(isolate, root, "start");
922 const v8::CpuProfileNode* startNode = 915 const v8::CpuProfileNode* startNode =
923 GetChild(env->GetIsolate(), root, "start"); 916 GetChild(isolate, root, "start");
924 GetChild(env->GetIsolate(), startNode, "fooMethod"); 917 GetChild(isolate, startNode, "fooMethod");
925 918
926 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 919 const_cast<v8::CpuProfile*>(profile)->Delete();
927 cpu_profiler->DeleteAllCpuProfiles();
928 } 920 }
929 921
930 922
931 static const char* bound_function_test_source = "function foo(iterations) {\n" 923 static const char* bound_function_test_source = "function foo(iterations) {\n"
932 " var r = 0;\n" 924 " var r = 0;\n"
933 " for (var i = 0; i < iterations; i++) { r += i; }\n" 925 " for (var i = 0; i < iterations; i++) { r += i; }\n"
934 " return r;\n" 926 " return r;\n"
935 "}\n" 927 "}\n"
936 "function start(duration) {\n" 928 "function start(duration) {\n"
937 " var callback = foo.bind(this);\n" 929 " var callback = foo.bind(this);\n"
(...skipping 26 matching lines...) Expand all
964 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), 956 names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
965 ProfileGenerator::kProgramEntryName); 957 ProfileGenerator::kProgramEntryName);
966 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); 958 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
967 // Don't allow |foo| node to be at the top level. 959 // Don't allow |foo| node to be at the top level.
968 CheckChildrenNames(root, names); 960 CheckChildrenNames(root, names);
969 961
970 const v8::CpuProfileNode* startNode = 962 const v8::CpuProfileNode* startNode =
971 GetChild(env->GetIsolate(), root, "start"); 963 GetChild(env->GetIsolate(), root, "start");
972 GetChild(env->GetIsolate(), startNode, "foo"); 964 GetChild(env->GetIsolate(), startNode, "foo");
973 965
974 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 966 const_cast<v8::CpuProfile*>(profile)->Delete();
975 cpu_profiler->DeleteAllCpuProfiles();
976 } 967 }
977 968
978 969
979 static const char* call_function_test_source = "function bar(iterations) {\n" 970 static const char* call_function_test_source = "function bar(iterations) {\n"
980 "}\n" 971 "}\n"
981 "function start(duration) {\n" 972 "function start(duration) {\n"
982 " var start = Date.now();\n" 973 " var start = Date.now();\n"
983 " while (Date.now() - start < duration) {\n" 974 " while (Date.now() - start < duration) {\n"
984 " try {\n" 975 " try {\n"
985 " bar.call(this, 10 * 1000);\n" 976 " bar.call(this, 10 * 1000);\n"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 } 1037 }
1047 1038
1048 const v8::CpuProfileNode* unresolvedNode = FindChild( 1039 const v8::CpuProfileNode* unresolvedNode = FindChild(
1049 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); 1040 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName);
1050 if (unresolvedNode) { 1041 if (unresolvedNode) {
1051 ScopedVector<v8::Handle<v8::String> > names(1); 1042 ScopedVector<v8::Handle<v8::String> > names(1);
1052 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); 1043 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call");
1053 CheckChildrenNames(unresolvedNode, names); 1044 CheckChildrenNames(unresolvedNode, names);
1054 } 1045 }
1055 1046
1056 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1047 const_cast<v8::CpuProfile*>(profile)->Delete();
1057 cpu_profiler->DeleteAllCpuProfiles();
1058 } 1048 }
1059 1049
1060 1050
1061 static const char* function_apply_test_source = "function bar(iterations) {\n" 1051 static const char* function_apply_test_source = "function bar(iterations) {\n"
1062 "}\n" 1052 "}\n"
1063 "function test() {\n" 1053 "function test() {\n"
1064 " bar.apply(this, [10 * 1000]);\n" 1054 " bar.apply(this, [10 * 1000]);\n"
1065 "}\n" 1055 "}\n"
1066 "function start(duration) {\n" 1056 "function start(duration) {\n"
1067 " var start = Date.now();\n" 1057 " var start = Date.now();\n"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 if (const v8::CpuProfileNode* unresolvedNode = 1124 if (const v8::CpuProfileNode* unresolvedNode =
1135 FindChild(env->GetIsolate(), startNode, 1125 FindChild(env->GetIsolate(), startNode,
1136 ProfileGenerator::kUnresolvedFunctionName)) { 1126 ProfileGenerator::kUnresolvedFunctionName)) {
1137 ScopedVector<v8::Handle<v8::String> > names(1); 1127 ScopedVector<v8::Handle<v8::String> > names(1);
1138 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); 1128 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply");
1139 CheckChildrenNames(unresolvedNode, names); 1129 CheckChildrenNames(unresolvedNode, names);
1140 GetChild(env->GetIsolate(), unresolvedNode, "apply"); 1130 GetChild(env->GetIsolate(), unresolvedNode, "apply");
1141 } 1131 }
1142 } 1132 }
1143 1133
1144 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1134 const_cast<v8::CpuProfile*>(profile)->Delete();
1145 cpu_profiler->DeleteAllCpuProfiles();
1146 } 1135 }
1147 1136
1148 1137
1149 static const char* js_native_js_test_source = 1138 static const char* js_native_js_test_source =
1150 "var is_profiling = false;\n" 1139 "var is_profiling = false;\n"
1151 "function foo(iterations) {\n" 1140 "function foo(iterations) {\n"
1152 " if (!is_profiling) {\n" 1141 " if (!is_profiling) {\n"
1153 " is_profiling = true;\n" 1142 " is_profiling = true;\n"
1154 " startProfiling('my_profile');\n" 1143 " startProfiling('my_profile');\n"
1155 " }\n" 1144 " }\n"
(...skipping 27 matching lines...) Expand all
1183 // 55 0 CallJsFunction #0 4 1172 // 55 0 CallJsFunction #0 4
1184 // 55 1 bar #16 5 1173 // 55 1 bar #16 5
1185 // 54 54 foo #16 6 1174 // 54 54 foo #16 6
1186 TEST(JsNativeJsSample) { 1175 TEST(JsNativeJsSample) {
1187 const char* extensions[] = { "v8/profiler" }; 1176 const char* extensions[] = { "v8/profiler" };
1188 v8::ExtensionConfiguration config(1, extensions); 1177 v8::ExtensionConfiguration config(1, extensions);
1189 LocalContext env(&config); 1178 LocalContext env(&config);
1190 v8::HandleScope scope(env->GetIsolate()); 1179 v8::HandleScope scope(env->GetIsolate());
1191 1180
1192 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1181 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1193 CallJsFunction); 1182 env->GetIsolate(), CallJsFunction);
1194 v8::Local<v8::Function> func = func_template->GetFunction(); 1183 v8::Local<v8::Function> func = func_template->GetFunction();
1195 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); 1184 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
1196 env->Global()->Set( 1185 env->Global()->Set(
1197 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); 1186 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
1198 1187
1199 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), 1188 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
1200 js_native_js_test_source))->Run(); 1189 js_native_js_test_source))->Run();
1201 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1190 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1202 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1191 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
1203 1192
(...skipping 19 matching lines...) Expand all
1223 const v8::CpuProfileNode* nativeFunctionNode = 1212 const v8::CpuProfileNode* nativeFunctionNode =
1224 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); 1213 GetChild(env->GetIsolate(), startNode, "CallJsFunction");
1225 1214
1226 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); 1215 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
1227 const v8::CpuProfileNode* barNode = 1216 const v8::CpuProfileNode* barNode =
1228 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); 1217 GetChild(env->GetIsolate(), nativeFunctionNode, "bar");
1229 1218
1230 CHECK_EQ(1, barNode->GetChildrenCount()); 1219 CHECK_EQ(1, barNode->GetChildrenCount());
1231 GetChild(env->GetIsolate(), barNode, "foo"); 1220 GetChild(env->GetIsolate(), barNode, "foo");
1232 1221
1233 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1222 const_cast<v8::CpuProfile*>(profile)->Delete();
1234 cpu_profiler->DeleteAllCpuProfiles();
1235 } 1223 }
1236 1224
1237 1225
1238 static const char* js_native_js_runtime_js_test_source = 1226 static const char* js_native_js_runtime_js_test_source =
1239 "var is_profiling = false;\n" 1227 "var is_profiling = false;\n"
1240 "function foo(iterations) {\n" 1228 "function foo(iterations) {\n"
1241 " if (!is_profiling) {\n" 1229 " if (!is_profiling) {\n"
1242 " is_profiling = true;\n" 1230 " is_profiling = true;\n"
1243 " startProfiling('my_profile');\n" 1231 " startProfiling('my_profile');\n"
1244 " }\n" 1232 " }\n"
(...skipping 22 matching lines...) Expand all
1267 // 54 3 bar #16 5 1255 // 54 3 bar #16 5
1268 // 51 51 foo #16 6 1256 // 51 51 foo #16 6
1269 // 2 2 (program) #0 2 1257 // 2 2 (program) #0 2
1270 TEST(JsNativeJsRuntimeJsSample) { 1258 TEST(JsNativeJsRuntimeJsSample) {
1271 const char* extensions[] = { "v8/profiler" }; 1259 const char* extensions[] = { "v8/profiler" };
1272 v8::ExtensionConfiguration config(1, extensions); 1260 v8::ExtensionConfiguration config(1, extensions);
1273 LocalContext env(&config); 1261 LocalContext env(&config);
1274 v8::HandleScope scope(env->GetIsolate()); 1262 v8::HandleScope scope(env->GetIsolate());
1275 1263
1276 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1264 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1277 CallJsFunction); 1265 env->GetIsolate(), CallJsFunction);
1278 v8::Local<v8::Function> func = func_template->GetFunction(); 1266 v8::Local<v8::Function> func = func_template->GetFunction();
1279 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); 1267 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
1280 env->Global()->Set( 1268 env->Global()->Set(
1281 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); 1269 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
1282 1270
1283 v8::Script::Compile( 1271 v8::Script::Compile(
1284 v8::String::NewFromUtf8(env->GetIsolate(), 1272 v8::String::NewFromUtf8(env->GetIsolate(),
1285 js_native_js_runtime_js_test_source))->Run(); 1273 js_native_js_runtime_js_test_source))->Run();
1286 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1274 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1287 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1275 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
(...skipping 18 matching lines...) Expand all
1306 const v8::CpuProfileNode* nativeFunctionNode = 1294 const v8::CpuProfileNode* nativeFunctionNode =
1307 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); 1295 GetChild(env->GetIsolate(), startNode, "CallJsFunction");
1308 1296
1309 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); 1297 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
1310 const v8::CpuProfileNode* barNode = 1298 const v8::CpuProfileNode* barNode =
1311 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); 1299 GetChild(env->GetIsolate(), nativeFunctionNode, "bar");
1312 1300
1313 CHECK_EQ(1, barNode->GetChildrenCount()); 1301 CHECK_EQ(1, barNode->GetChildrenCount());
1314 GetChild(env->GetIsolate(), barNode, "foo"); 1302 GetChild(env->GetIsolate(), barNode, "foo");
1315 1303
1316 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1304 const_cast<v8::CpuProfile*>(profile)->Delete();
1317 cpu_profiler->DeleteAllCpuProfiles();
1318 } 1305 }
1319 1306
1320 1307
1321 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { 1308 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
1322 CallJsFunction(info); 1309 CallJsFunction(info);
1323 } 1310 }
1324 1311
1325 1312
1326 static const char* js_native1_js_native2_js_test_source = 1313 static const char* js_native1_js_native2_js_test_source =
1327 "var is_profiling = false;\n" 1314 "var is_profiling = false;\n"
(...skipping 27 matching lines...) Expand all
1355 // 54 0 CallJsFunction2 #0 6 1342 // 54 0 CallJsFunction2 #0 6
1356 // 54 54 foo #16 7 1343 // 54 54 foo #16 7
1357 // 2 2 (program) #0 2 1344 // 2 2 (program) #0 2
1358 TEST(JsNative1JsNative2JsSample) { 1345 TEST(JsNative1JsNative2JsSample) {
1359 const char* extensions[] = { "v8/profiler" }; 1346 const char* extensions[] = { "v8/profiler" };
1360 v8::ExtensionConfiguration config(1, extensions); 1347 v8::ExtensionConfiguration config(1, extensions);
1361 LocalContext env(&config); 1348 LocalContext env(&config);
1362 v8::HandleScope scope(env->GetIsolate()); 1349 v8::HandleScope scope(env->GetIsolate());
1363 1350
1364 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1351 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1365 CallJsFunction); 1352 env->GetIsolate(), CallJsFunction);
1366 v8::Local<v8::Function> func1 = func_template->GetFunction(); 1353 v8::Local<v8::Function> func1 = func_template->GetFunction();
1367 func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1")); 1354 func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"));
1368 env->Global()->Set( 1355 env->Global()->Set(
1369 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1); 1356 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1);
1370 1357
1371 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( 1358 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New(
1372 CallJsFunction2)->GetFunction(); 1359 env->GetIsolate(), CallJsFunction2)->GetFunction();
1373 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); 1360 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"));
1374 env->Global()->Set( 1361 env->Global()->Set(
1375 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); 1362 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2);
1376 1363
1377 v8::Script::Compile( 1364 v8::Script::Compile(
1378 v8::String::NewFromUtf8(env->GetIsolate(), 1365 v8::String::NewFromUtf8(env->GetIsolate(),
1379 js_native1_js_native2_js_test_source))->Run(); 1366 js_native1_js_native2_js_test_source))->Run();
1380 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1367 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1381 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1368 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
1382 1369
(...skipping 21 matching lines...) Expand all
1404 const v8::CpuProfileNode* barNode = 1391 const v8::CpuProfileNode* barNode =
1405 GetChild(env->GetIsolate(), nativeNode1, "bar"); 1392 GetChild(env->GetIsolate(), nativeNode1, "bar");
1406 1393
1407 CHECK_EQ(1, barNode->GetChildrenCount()); 1394 CHECK_EQ(1, barNode->GetChildrenCount());
1408 const v8::CpuProfileNode* nativeNode2 = 1395 const v8::CpuProfileNode* nativeNode2 =
1409 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); 1396 GetChild(env->GetIsolate(), barNode, "CallJsFunction2");
1410 1397
1411 CHECK_EQ(1, nativeNode2->GetChildrenCount()); 1398 CHECK_EQ(1, nativeNode2->GetChildrenCount());
1412 GetChild(env->GetIsolate(), nativeNode2, "foo"); 1399 GetChild(env->GetIsolate(), nativeNode2, "foo");
1413 1400
1414 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1401 const_cast<v8::CpuProfile*>(profile)->Delete();
1415 cpu_profiler->DeleteAllCpuProfiles();
1416 } 1402 }
1417 1403
1418 1404
1419 // [Top down]: 1405 // [Top down]:
1420 // 6 0 (root) #0 1 1406 // 6 0 (root) #0 1
1421 // 3 3 (program) #0 2 1407 // 3 3 (program) #0 2
1422 // 3 3 (idle) #0 3 1408 // 3 3 (idle) #0 3
1423 TEST(IdleTime) { 1409 TEST(IdleTime) {
1424 LocalContext env; 1410 LocalContext env;
1425 v8::HandleScope scope(env->GetIsolate()); 1411 v8::HandleScope scope(env->GetIsolate());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 const v8::CpuProfileNode* programNode = 1448 const v8::CpuProfileNode* programNode =
1463 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); 1449 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName);
1464 CHECK_EQ(0, programNode->GetChildrenCount()); 1450 CHECK_EQ(0, programNode->GetChildrenCount());
1465 CHECK_GE(programNode->GetHitCount(), 3); 1451 CHECK_GE(programNode->GetHitCount(), 3);
1466 1452
1467 const v8::CpuProfileNode* idleNode = 1453 const v8::CpuProfileNode* idleNode =
1468 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); 1454 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName);
1469 CHECK_EQ(0, idleNode->GetChildrenCount()); 1455 CHECK_EQ(0, idleNode->GetChildrenCount());
1470 CHECK_GE(idleNode->GetHitCount(), 3); 1456 CHECK_GE(idleNode->GetHitCount(), 3);
1471 1457
1472 cpu_profiler->DeleteAllCpuProfiles(); 1458 const_cast<v8::CpuProfile*>(profile)->Delete();
1473 } 1459 }
1474 1460
1475 1461
1476 static void CheckFunctionDetails(v8::Isolate* isolate, 1462 static void CheckFunctionDetails(v8::Isolate* isolate,
1477 const v8::CpuProfileNode* node, 1463 const v8::CpuProfileNode* node,
1478 const char* name, const char* script_name, 1464 const char* name, const char* script_name,
1479 int script_id, int line, int column) { 1465 int script_id, int line, int column) {
1480 CHECK_EQ(v8::String::NewFromUtf8(isolate, name), 1466 CHECK_EQ(v8::String::NewFromUtf8(isolate, name),
1481 node->GetFunctionName()); 1467 node->GetFunctionName());
1482 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name), 1468 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name),
1483 node->GetScriptResourceName()); 1469 node->GetScriptResourceName());
1484 CHECK_EQ(script_id, node->GetScriptId()); 1470 CHECK_EQ(script_id, node->GetScriptId());
1485 CHECK_EQ(line, node->GetLineNumber()); 1471 CHECK_EQ(line, node->GetLineNumber());
1486 CHECK_EQ(column, node->GetColumnNumber()); 1472 CHECK_EQ(column, node->GetColumnNumber());
1487 } 1473 }
1488 1474
1489 1475
1490 TEST(FunctionDetails) { 1476 TEST(FunctionDetails) {
1491 const char* extensions[] = { "v8/profiler" }; 1477 const char* extensions[] = { "v8/profiler" };
1492 v8::ExtensionConfiguration config(1, extensions); 1478 v8::ExtensionConfiguration config(1, extensions);
1493 LocalContext env(&config); 1479 LocalContext env(&config);
1494 v8::HandleScope handleScope(env->GetIsolate()); 1480 v8::HandleScope handleScope(env->GetIsolate());
1495 1481
1496 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
1497 CHECK_EQ(0, profiler->GetProfileCount());
1498 v8::Handle<v8::Script> script_a = v8::Script::Compile( 1482 v8::Handle<v8::Script> script_a = v8::Script::Compile(
1499 v8::String::NewFromUtf8( 1483 v8::String::NewFromUtf8(
1500 env->GetIsolate(), 1484 env->GetIsolate(),
1501 " function foo\n() { try { bar(); } catch(e) {} }\n" 1485 " function foo\n() { try { bar(); } catch(e) {} }\n"
1502 " function bar() { startProfiling(); }\n"), 1486 " function bar() { startProfiling(); }\n"),
1503 v8::String::NewFromUtf8(env->GetIsolate(), "script_a")); 1487 v8::String::NewFromUtf8(env->GetIsolate(), "script_a"));
1504 script_a->Run(); 1488 script_a->Run();
1505 v8::Handle<v8::Script> script_b = v8::Script::Compile( 1489 v8::Handle<v8::Script> script_b = v8::Script::Compile(
1506 v8::String::NewFromUtf8( 1490 v8::String::NewFromUtf8(
1507 env->GetIsolate(), 1491 env->GetIsolate(),
1508 "\n\n function baz() { try { foo(); } catch(e) {} }\n" 1492 "\n\n function baz() { try { foo(); } catch(e) {} }\n"
1509 "\n\nbaz();\n" 1493 "\n\nbaz();\n"
1510 "stopProfiling();\n"), 1494 "stopProfiling();\n"),
1511 v8::String::NewFromUtf8(env->GetIsolate(), "script_b")); 1495 v8::String::NewFromUtf8(env->GetIsolate(), "script_b"));
1512 script_b->Run(); 1496 script_b->Run();
1513 CHECK_EQ(1, profiler->GetProfileCount()); 1497 const v8::CpuProfile* profile = ProfilerExtension::last_profile;
1514 const v8::CpuProfile* profile = profiler->GetCpuProfile(0);
1515 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 1498 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
1516 reinterpret_cast<ProfileNode*>( 1499 reinterpret_cast<ProfileNode*>(
1517 const_cast<v8::CpuProfileNode*>(current))->Print(0); 1500 const_cast<v8::CpuProfileNode*>(current))->Print(0);
1518 // The tree should look like this: 1501 // The tree should look like this:
1519 // 0 (root) 0 #1 1502 // 0 (root) 0 #1
1520 // 0 (anonymous function) 19 #2 no reason script_b:1 1503 // 0 (anonymous function) 19 #2 no reason script_b:1
1521 // 0 baz 19 #3 TryCatchStatement script_b:3 1504 // 0 baz 19 #3 TryCatchStatement script_b:3
1522 // 0 foo 18 #4 TryCatchStatement script_a:2 1505 // 0 foo 18 #4 TryCatchStatement script_a:2
1523 // 1 bar 18 #5 no reason script_a:3 1506 // 1 bar 18 #5 no reason script_a:3
1524 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1507 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1525 const v8::CpuProfileNode* script = GetChild(env->GetIsolate(), root, 1508 const v8::CpuProfileNode* script = GetChild(env->GetIsolate(), root,
1526 ProfileGenerator::kAnonymousFunctionName); 1509 ProfileGenerator::kAnonymousFunctionName);
1527 CheckFunctionDetails(env->GetIsolate(), script, 1510 CheckFunctionDetails(env->GetIsolate(), script,
1528 ProfileGenerator::kAnonymousFunctionName, "script_b", 1511 ProfileGenerator::kAnonymousFunctionName, "script_b",
1529 script_b->GetId(), 1, 1); 1512 script_b->GetId(), 1, 1);
1530 const v8::CpuProfileNode* baz = GetChild(env->GetIsolate(), script, "baz"); 1513 const v8::CpuProfileNode* baz = GetChild(env->GetIsolate(), script, "baz");
1531 CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b", 1514 CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b",
1532 script_b->GetId(), 3, 16); 1515 script_b->GetId(), 3, 16);
1533 const v8::CpuProfileNode* foo = GetChild(env->GetIsolate(), baz, "foo"); 1516 const v8::CpuProfileNode* foo = GetChild(env->GetIsolate(), baz, "foo");
1534 CheckFunctionDetails(env->GetIsolate(), foo, "foo", "script_a", 1517 CheckFunctionDetails(env->GetIsolate(), foo, "foo", "script_a",
1535 script_a->GetId(), 2, 1); 1518 script_a->GetId(), 2, 1);
1536 const v8::CpuProfileNode* bar = GetChild(env->GetIsolate(), foo, "bar"); 1519 const v8::CpuProfileNode* bar = GetChild(env->GetIsolate(), foo, "bar");
1537 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a", 1520 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a",
1538 script_a->GetId(), 3, 14); 1521 script_a->GetId(), 3, 14);
1539 } 1522 }
1523
1524
1525 TEST(DontStopOnFinishedProfileDelete) {
1526 const char* extensions[] = { "v8/profiler" };
1527 v8::ExtensionConfiguration config(1, extensions);
1528 LocalContext env(&config);
1529 v8::Isolate* isolate = env->GetIsolate();
1530 v8::HandleScope handleScope(isolate);
1531
1532 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
1533 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
1534
1535 CHECK_EQ(0, iprofiler->GetProfilesCount());
1536 v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer");
1537 profiler->StartCpuProfiling(outer);
1538 CHECK_EQ(0, iprofiler->GetProfilesCount());
1539
1540 v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner");
1541 profiler->StartCpuProfiling(inner);
1542 CHECK_EQ(0, iprofiler->GetProfilesCount());
1543
1544 const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(inner);
1545 CHECK(inner_profile);
1546 CHECK_EQ(1, iprofiler->GetProfilesCount());
1547 const_cast<v8::CpuProfile*>(inner_profile)->Delete();
1548 inner_profile = NULL;
1549 CHECK_EQ(0, iprofiler->GetProfilesCount());
1550
1551 const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer);
1552 CHECK(outer_profile);
1553 CHECK_EQ(1, iprofiler->GetProfilesCount());
1554 const_cast<v8::CpuProfile*>(outer_profile)->Delete();
1555 outer_profile = NULL;
1556 CHECK_EQ(0, iprofiler->GetProfilesCount());
1557 }
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698