OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests of profiles generator and utilities. | 3 // Tests of profiles generator and utilities. |
4 | 4 |
| 5 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 6 |
5 #include "v8.h" | 7 #include "v8.h" |
6 #include "profile-generator-inl.h" | 8 #include "profile-generator-inl.h" |
7 #include "cctest.h" | 9 #include "cctest.h" |
8 | 10 |
9 namespace i = v8::internal; | 11 namespace i = v8::internal; |
10 | 12 |
11 using i::CodeEntry; | 13 using i::CodeEntry; |
12 using i::CodeMap; | 14 using i::CodeMap; |
| 15 using i::CpuProfile; |
13 using i::CpuProfilesCollection; | 16 using i::CpuProfilesCollection; |
14 using i::ProfileNode; | 17 using i::ProfileNode; |
15 using i::ProfileTree; | 18 using i::ProfileTree; |
16 using i::ProfileGenerator; | 19 using i::ProfileGenerator; |
17 using i::TickSample; | 20 using i::TickSample; |
18 using i::Vector; | 21 using i::Vector; |
19 | 22 |
20 | 23 |
21 TEST(ProfileNodeFindOrAddChild) { | 24 TEST(ProfileNodeFindOrAddChild) { |
22 ProfileNode node(NULL); | 25 ProfileNode node(NULL); |
(...skipping 15 matching lines...) Expand all Loading... |
38 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); | 41 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); |
39 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); | 42 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); |
40 CHECK_EQ(childNode3, node.FindOrAddChild(&entry3)); | 43 CHECK_EQ(childNode3, node.FindOrAddChild(&entry3)); |
41 } | 44 } |
42 | 45 |
43 | 46 |
44 namespace { | 47 namespace { |
45 | 48 |
46 class ProfileTreeTestHelper { | 49 class ProfileTreeTestHelper { |
47 public: | 50 public: |
48 explicit ProfileTreeTestHelper(ProfileTree* tree) | 51 explicit ProfileTreeTestHelper(const ProfileTree* tree) |
49 : tree_(tree) { } | 52 : tree_(tree) { } |
50 | 53 |
51 ProfileNode* Walk(CodeEntry* entry1, | 54 ProfileNode* Walk(CodeEntry* entry1, |
52 CodeEntry* entry2 = NULL, | 55 CodeEntry* entry2 = NULL, |
53 CodeEntry* entry3 = NULL) { | 56 CodeEntry* entry3 = NULL) { |
54 ProfileNode* node = tree_->root(); | 57 ProfileNode* node = tree_->root(); |
55 node = node->FindChild(entry1); | 58 node = node->FindChild(entry1); |
56 if (node == NULL) return NULL; | 59 if (node == NULL) return NULL; |
57 if (entry2 != NULL) { | 60 if (entry2 != NULL) { |
58 node = node->FindChild(entry2); | 61 node = node->FindChild(entry2); |
59 if (node == NULL) return NULL; | 62 if (node == NULL) return NULL; |
60 } | 63 } |
61 if (entry3 != NULL) { | 64 if (entry3 != NULL) { |
62 node = node->FindChild(entry3); | 65 node = node->FindChild(entry3); |
63 } | 66 } |
64 return node; | 67 return node; |
65 } | 68 } |
66 | 69 |
67 private: | 70 private: |
68 ProfileTree* tree_; | 71 const ProfileTree* tree_; |
69 }; | 72 }; |
70 | 73 |
71 } // namespace | 74 } // namespace |
72 | 75 |
73 TEST(ProfileTreeAddPathFromStart) { | 76 TEST(ProfileTreeAddPathFromStart) { |
74 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); | 77 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); |
75 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); | 78 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); |
76 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); | 79 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); |
77 ProfileTree tree; | 80 ProfileTree tree; |
78 ProfileTreeTestHelper helper(&tree); | 81 ProfileTreeTestHelper helper(&tree); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700))); | 362 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700))); |
360 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1800))); | 363 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1800))); |
361 code_map.DeleteCode(ToAddress(0x1700)); | 364 code_map.DeleteCode(ToAddress(0x1700)); |
362 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700))); | 365 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700))); |
363 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1800))); | 366 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1800))); |
364 } | 367 } |
365 | 368 |
366 | 369 |
367 TEST(RecordTickSample) { | 370 TEST(RecordTickSample) { |
368 CpuProfilesCollection profiles; | 371 CpuProfilesCollection profiles; |
369 profiles.AddProfile(0); | 372 profiles.StartProfiling("", 1); |
370 ProfileGenerator generator(&profiles); | 373 ProfileGenerator generator(&profiles); |
371 CodeEntry* entry1 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 374 CodeEntry* entry1 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
372 CodeEntry* entry2 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); | 375 CodeEntry* entry2 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); |
373 CodeEntry* entry3 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); | 376 CodeEntry* entry3 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); |
374 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 377 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
375 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); | 378 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); |
376 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); | 379 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); |
377 | 380 |
378 ProfileTreeTestHelper top_down_test_helper(profiles.profile()->top_down()); | |
379 CHECK_EQ(NULL, top_down_test_helper.Walk(entry1)); | |
380 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); | |
381 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); | |
382 | |
383 // We are building the following calls tree: | 381 // We are building the following calls tree: |
384 // -> aaa - sample1 | 382 // -> aaa - sample1 |
385 // aaa -> bbb -> ccc - sample2 | 383 // aaa -> bbb -> ccc - sample2 |
386 // -> ccc -> aaa - sample3 | 384 // -> ccc -> aaa - sample3 |
387 TickSample sample1; | 385 TickSample sample1; |
388 sample1.pc = ToAddress(0x1600); | 386 sample1.pc = ToAddress(0x1600); |
389 sample1.function = ToAddress(0x1500); | 387 sample1.function = ToAddress(0x1500); |
390 sample1.stack[0] = ToAddress(0x1510); | 388 sample1.stack[0] = ToAddress(0x1510); |
391 sample1.frames_count = 1; | 389 sample1.frames_count = 1; |
392 generator.RecordTickSample(sample1); | 390 generator.RecordTickSample(sample1); |
393 TickSample sample2; | 391 TickSample sample2; |
394 sample2.pc = ToAddress(0x1925); | 392 sample2.pc = ToAddress(0x1925); |
395 sample2.function = ToAddress(0x1900); | 393 sample2.function = ToAddress(0x1900); |
396 sample2.stack[0] = ToAddress(0x1780); | 394 sample2.stack[0] = ToAddress(0x1780); |
397 sample2.stack[1] = ToAddress(0x10000); // non-existent. | 395 sample2.stack[1] = ToAddress(0x10000); // non-existent. |
398 sample2.stack[2] = ToAddress(0x1620); | 396 sample2.stack[2] = ToAddress(0x1620); |
399 sample2.frames_count = 3; | 397 sample2.frames_count = 3; |
400 generator.RecordTickSample(sample2); | 398 generator.RecordTickSample(sample2); |
401 TickSample sample3; | 399 TickSample sample3; |
402 sample3.pc = ToAddress(0x1510); | 400 sample3.pc = ToAddress(0x1510); |
403 sample3.function = ToAddress(0x1500); | 401 sample3.function = ToAddress(0x1500); |
404 sample3.stack[0] = ToAddress(0x1910); | 402 sample3.stack[0] = ToAddress(0x1910); |
405 sample3.stack[1] = ToAddress(0x1610); | 403 sample3.stack[1] = ToAddress(0x1610); |
406 sample3.frames_count = 2; | 404 sample3.frames_count = 2; |
407 generator.RecordTickSample(sample3); | 405 generator.RecordTickSample(sample3); |
408 | 406 |
| 407 CpuProfile* profile = profiles.StopProfiling(""); |
| 408 CHECK_NE(NULL, profile); |
| 409 ProfileTreeTestHelper top_down_test_helper(profile->top_down()); |
| 410 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); |
| 411 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); |
409 ProfileNode* node1 = top_down_test_helper.Walk(entry1); | 412 ProfileNode* node1 = top_down_test_helper.Walk(entry1); |
410 CHECK_NE(NULL, node1); | 413 CHECK_NE(NULL, node1); |
411 CHECK_EQ(entry1, node1->entry()); | 414 CHECK_EQ(entry1, node1->entry()); |
412 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); | 415 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); |
413 CHECK_NE(NULL, node2); | 416 CHECK_NE(NULL, node2); |
414 CHECK_EQ(entry1, node2->entry()); | 417 CHECK_EQ(entry1, node2->entry()); |
415 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); | 418 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); |
416 CHECK_NE(NULL, node3); | 419 CHECK_NE(NULL, node3); |
417 CHECK_EQ(entry3, node3->entry()); | 420 CHECK_EQ(entry3, node3->entry()); |
418 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); | 421 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); |
419 CHECK_NE(NULL, node4); | 422 CHECK_NE(NULL, node4); |
420 CHECK_EQ(entry1, node4->entry()); | 423 CHECK_EQ(entry1, node4->entry()); |
421 } | 424 } |
| 425 |
| 426 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
OLD | NEW |