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

Side by Side Diff: test/cctest/test-profile-generator.cc

Issue 1582004: C++ profiles processor: wire up to VM. (Closed)
Patch Set: Created 10 years, 8 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
« src/platform-linux.cc ('K') | « test/cctest/test-log.cc ('k') | no next file » | 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 // 2 //
3 // Tests of profiles generator and utilities. 3 // Tests of profiles generator and utilities.
4 4
5 #ifdef ENABLE_CPP_PROFILES_PROCESSOR 5 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
6 6
7 #include "v8.h" 7 #include "v8.h"
8 #include "profile-generator-inl.h" 8 #include "profile-generator-inl.h"
9 #include "cctest.h" 9 #include "cctest.h"
10 10
11 namespace i = v8::internal; 11 namespace i = v8::internal;
12 12
13 using i::CodeEntry; 13 using i::CodeEntry;
14 using i::CodeMap; 14 using i::CodeMap;
15 using i::CpuProfile; 15 using i::CpuProfile;
16 using i::CpuProfilesCollection; 16 using i::CpuProfilesCollection;
17 using i::ProfileNode; 17 using i::ProfileNode;
18 using i::ProfileTree; 18 using i::ProfileTree;
19 using i::ProfileGenerator; 19 using i::ProfileGenerator;
20 using i::TickSample; 20 using i::TickSample;
21 using i::Vector; 21 using i::Vector;
22 22
23 23
24 TEST(ProfileNodeFindOrAddChild) { 24 TEST(ProfileNodeFindOrAddChild) {
25 ProfileNode node(NULL); 25 ProfileNode node(NULL);
26 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); 26 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
27 ProfileNode* childNode1 = node.FindOrAddChild(&entry1); 27 ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
28 CHECK_NE(NULL, childNode1); 28 CHECK_NE(NULL, childNode1);
29 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); 29 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
30 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); 30 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
31 ProfileNode* childNode2 = node.FindOrAddChild(&entry2); 31 ProfileNode* childNode2 = node.FindOrAddChild(&entry2);
32 CHECK_NE(NULL, childNode2); 32 CHECK_NE(NULL, childNode2);
33 CHECK_NE(childNode1, childNode2); 33 CHECK_NE(childNode1, childNode2);
34 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); 34 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
35 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); 35 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2));
36 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); 36 CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
37 ProfileNode* childNode3 = node.FindOrAddChild(&entry3); 37 ProfileNode* childNode3 = node.FindOrAddChild(&entry3);
38 CHECK_NE(NULL, childNode3); 38 CHECK_NE(NULL, childNode3);
39 CHECK_NE(childNode1, childNode3); 39 CHECK_NE(childNode1, childNode3);
40 CHECK_NE(childNode2, childNode3); 40 CHECK_NE(childNode2, childNode3);
41 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); 41 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
42 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); 42 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2));
43 CHECK_EQ(childNode3, node.FindOrAddChild(&entry3)); 43 CHECK_EQ(childNode3, node.FindOrAddChild(&entry3));
44 } 44 }
45 45
46 46
(...skipping 20 matching lines...) Expand all
67 return node; 67 return node;
68 } 68 }
69 69
70 private: 70 private:
71 const ProfileTree* tree_; 71 const ProfileTree* tree_;
72 }; 72 };
73 73
74 } // namespace 74 } // namespace
75 75
76 TEST(ProfileTreeAddPathFromStart) { 76 TEST(ProfileTreeAddPathFromStart) {
77 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); 77 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
78 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); 78 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
79 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); 79 CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
80 ProfileTree tree; 80 ProfileTree tree;
81 ProfileTreeTestHelper helper(&tree); 81 ProfileTreeTestHelper helper(&tree);
82 CHECK_EQ(NULL, helper.Walk(&entry1)); 82 CHECK_EQ(NULL, helper.Walk(&entry1));
83 CHECK_EQ(NULL, helper.Walk(&entry2)); 83 CHECK_EQ(NULL, helper.Walk(&entry2));
84 CHECK_EQ(NULL, helper.Walk(&entry3)); 84 CHECK_EQ(NULL, helper.Walk(&entry3));
85 85
86 CodeEntry* path[] = {NULL, &entry1, NULL, &entry2, NULL, NULL, &entry3, NULL}; 86 CodeEntry* path[] = {NULL, &entry1, NULL, &entry2, NULL, NULL, &entry3, NULL};
87 Vector<CodeEntry*> path_vec(path, sizeof(path) / sizeof(path[0])); 87 Vector<CodeEntry*> path_vec(path, sizeof(path) / sizeof(path[0]));
88 tree.AddPathFromStart(path_vec); 88 tree.AddPathFromStart(path_vec);
89 CHECK_EQ(NULL, helper.Walk(&entry2)); 89 CHECK_EQ(NULL, helper.Walk(&entry2));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 CHECK_EQ(2, node3->self_ticks()); 134 CHECK_EQ(2, node3->self_ticks());
135 ProfileNode* node4 = helper.Walk(&entry1, &entry2, &entry2); 135 ProfileNode* node4 = helper.Walk(&entry1, &entry2, &entry2);
136 CHECK_NE(NULL, node4); 136 CHECK_NE(NULL, node4);
137 CHECK_NE(node3, node4); 137 CHECK_NE(node3, node4);
138 CHECK_EQ(0, node4->total_ticks()); 138 CHECK_EQ(0, node4->total_ticks());
139 CHECK_EQ(1, node4->self_ticks()); 139 CHECK_EQ(1, node4->self_ticks());
140 } 140 }
141 141
142 142
143 TEST(ProfileTreeAddPathFromEnd) { 143 TEST(ProfileTreeAddPathFromEnd) {
144 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); 144 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
145 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); 145 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
146 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); 146 CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
147 ProfileTree tree; 147 ProfileTree tree;
148 ProfileTreeTestHelper helper(&tree); 148 ProfileTreeTestHelper helper(&tree);
149 CHECK_EQ(NULL, helper.Walk(&entry1)); 149 CHECK_EQ(NULL, helper.Walk(&entry1));
150 CHECK_EQ(NULL, helper.Walk(&entry2)); 150 CHECK_EQ(NULL, helper.Walk(&entry2));
151 CHECK_EQ(NULL, helper.Walk(&entry3)); 151 CHECK_EQ(NULL, helper.Walk(&entry3));
152 152
153 CodeEntry* path[] = {NULL, &entry3, NULL, &entry2, NULL, NULL, &entry1, NULL}; 153 CodeEntry* path[] = {NULL, &entry3, NULL, &entry2, NULL, NULL, &entry1, NULL};
154 Vector<CodeEntry*> path_vec(path, sizeof(path) / sizeof(path[0])); 154 Vector<CodeEntry*> path_vec(path, sizeof(path) / sizeof(path[0]));
155 tree.AddPathFromEnd(path_vec); 155 tree.AddPathFromEnd(path_vec);
156 CHECK_EQ(NULL, helper.Walk(&entry2)); 156 CHECK_EQ(NULL, helper.Walk(&entry2));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 empty_tree.CalculateTotalTicks(); 214 empty_tree.CalculateTotalTicks();
215 CHECK_EQ(0, empty_tree.root()->total_ticks()); 215 CHECK_EQ(0, empty_tree.root()->total_ticks());
216 CHECK_EQ(0, empty_tree.root()->self_ticks()); 216 CHECK_EQ(0, empty_tree.root()->self_ticks());
217 empty_tree.root()->IncrementSelfTicks(); 217 empty_tree.root()->IncrementSelfTicks();
218 CHECK_EQ(0, empty_tree.root()->total_ticks()); 218 CHECK_EQ(0, empty_tree.root()->total_ticks());
219 CHECK_EQ(1, empty_tree.root()->self_ticks()); 219 CHECK_EQ(1, empty_tree.root()->self_ticks());
220 empty_tree.CalculateTotalTicks(); 220 empty_tree.CalculateTotalTicks();
221 CHECK_EQ(1, empty_tree.root()->total_ticks()); 221 CHECK_EQ(1, empty_tree.root()->total_ticks());
222 CHECK_EQ(1, empty_tree.root()->self_ticks()); 222 CHECK_EQ(1, empty_tree.root()->self_ticks());
223 223
224 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); 224 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
225 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); 225 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
226 CodeEntry* e1_path[] = {&entry1}; 226 CodeEntry* e1_path[] = {&entry1};
227 Vector<CodeEntry*> e1_path_vec( 227 Vector<CodeEntry*> e1_path_vec(
228 e1_path, sizeof(e1_path) / sizeof(e1_path[0])); 228 e1_path, sizeof(e1_path) / sizeof(e1_path[0]));
229 CodeEntry* e1_e2_path[] = {&entry1, &entry2}; 229 CodeEntry* e1_e2_path[] = {&entry1, &entry2};
230 Vector<CodeEntry*> e1_e2_path_vec( 230 Vector<CodeEntry*> e1_e2_path_vec(
231 e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0])); 231 e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0]));
232 232
233 ProfileTree flat_tree; 233 ProfileTree flat_tree;
234 ProfileTreeTestHelper flat_helper(&flat_tree); 234 ProfileTreeTestHelper flat_helper(&flat_tree);
235 flat_tree.AddPathFromStart(e1_path_vec); 235 flat_tree.AddPathFromStart(e1_path_vec);
(...skipping 17 matching lines...) Expand all
253 CHECK_EQ(5, flat_tree.root()->total_ticks()); 253 CHECK_EQ(5, flat_tree.root()->total_ticks());
254 CHECK_EQ(0, flat_tree.root()->self_ticks()); 254 CHECK_EQ(0, flat_tree.root()->self_ticks());
255 CHECK_EQ(5, node1->total_ticks()); 255 CHECK_EQ(5, node1->total_ticks());
256 CHECK_EQ(2, node1->self_ticks()); 256 CHECK_EQ(2, node1->self_ticks());
257 CHECK_EQ(3, node2->total_ticks()); 257 CHECK_EQ(3, node2->total_ticks());
258 CHECK_EQ(3, node2->self_ticks()); 258 CHECK_EQ(3, node2->self_ticks());
259 259
260 CodeEntry* e2_path[] = {&entry2}; 260 CodeEntry* e2_path[] = {&entry2};
261 Vector<CodeEntry*> e2_path_vec( 261 Vector<CodeEntry*> e2_path_vec(
262 e2_path, sizeof(e2_path) / sizeof(e2_path[0])); 262 e2_path, sizeof(e2_path) / sizeof(e2_path[0]));
263 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); 263 CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
264 CodeEntry* e3_path[] = {&entry3}; 264 CodeEntry* e3_path[] = {&entry3};
265 Vector<CodeEntry*> e3_path_vec( 265 Vector<CodeEntry*> e3_path_vec(
266 e3_path, sizeof(e3_path) / sizeof(e3_path[0])); 266 e3_path, sizeof(e3_path) / sizeof(e3_path[0]));
267 267
268 ProfileTree wide_tree; 268 ProfileTree wide_tree;
269 ProfileTreeTestHelper wide_helper(&wide_tree); 269 ProfileTreeTestHelper wide_helper(&wide_tree);
270 wide_tree.AddPathFromStart(e1_path_vec); 270 wide_tree.AddPathFromStart(e1_path_vec);
271 wide_tree.AddPathFromStart(e1_path_vec); 271 wide_tree.AddPathFromStart(e1_path_vec);
272 wide_tree.AddPathFromStart(e1_e2_path_vec); 272 wide_tree.AddPathFromStart(e1_e2_path_vec);
273 wide_tree.AddPathFromStart(e2_path_vec); 273 wide_tree.AddPathFromStart(e2_path_vec);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 CHECK_EQ(4, node3->self_ticks()); 314 CHECK_EQ(4, node3->self_ticks());
315 } 315 }
316 316
317 317
318 static inline i::Address ToAddress(int n) { 318 static inline i::Address ToAddress(int n) {
319 return reinterpret_cast<i::Address>(n); 319 return reinterpret_cast<i::Address>(n);
320 } 320 }
321 321
322 TEST(CodeMapAddCode) { 322 TEST(CodeMapAddCode) {
323 CodeMap code_map; 323 CodeMap code_map;
324 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); 324 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
325 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); 325 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
326 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", "", 0); 326 CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
327 CodeEntry entry4(i::Logger::FUNCTION_TAG, "ddd", "", 0); 327 CodeEntry entry4(i::Logger::FUNCTION_TAG, "", "ddd", "", 0);
328 code_map.AddCode(ToAddress(0x1500), &entry1, 0x200); 328 code_map.AddCode(ToAddress(0x1500), &entry1, 0x200);
329 code_map.AddCode(ToAddress(0x1700), &entry2, 0x100); 329 code_map.AddCode(ToAddress(0x1700), &entry2, 0x100);
330 code_map.AddCode(ToAddress(0x1900), &entry3, 0x50); 330 code_map.AddCode(ToAddress(0x1900), &entry3, 0x50);
331 code_map.AddCode(ToAddress(0x1950), &entry4, 0x10); 331 code_map.AddCode(ToAddress(0x1950), &entry4, 0x10);
332 CHECK_EQ(NULL, code_map.FindEntry(0)); 332 CHECK_EQ(NULL, code_map.FindEntry(0));
333 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1500 - 1))); 333 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1500 - 1)));
334 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500))); 334 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500)));
335 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500 + 0x100))); 335 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500 + 0x100)));
336 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500 + 0x200 - 1))); 336 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500 + 0x200 - 1)));
337 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700))); 337 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700)));
338 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700 + 0x50))); 338 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700 + 0x50)));
339 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700 + 0x100 - 1))); 339 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700 + 0x100 - 1)));
340 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700 + 0x100))); 340 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700 + 0x100)));
341 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1900 - 1))); 341 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1900 - 1)));
342 CHECK_EQ(&entry3, code_map.FindEntry(ToAddress(0x1900))); 342 CHECK_EQ(&entry3, code_map.FindEntry(ToAddress(0x1900)));
343 CHECK_EQ(&entry3, code_map.FindEntry(ToAddress(0x1900 + 0x28))); 343 CHECK_EQ(&entry3, code_map.FindEntry(ToAddress(0x1900 + 0x28)));
344 CHECK_EQ(&entry4, code_map.FindEntry(ToAddress(0x1950))); 344 CHECK_EQ(&entry4, code_map.FindEntry(ToAddress(0x1950)));
345 CHECK_EQ(&entry4, code_map.FindEntry(ToAddress(0x1950 + 0x7))); 345 CHECK_EQ(&entry4, code_map.FindEntry(ToAddress(0x1950 + 0x7)));
346 CHECK_EQ(&entry4, code_map.FindEntry(ToAddress(0x1950 + 0x10 - 1))); 346 CHECK_EQ(&entry4, code_map.FindEntry(ToAddress(0x1950 + 0x10 - 1)));
347 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1950 + 0x10))); 347 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1950 + 0x10)));
348 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0xFFFFFFFF))); 348 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0xFFFFFFFF)));
349 } 349 }
350 350
351 351
352 TEST(CodeMapMoveAndDeleteCode) { 352 TEST(CodeMapMoveAndDeleteCode) {
353 CodeMap code_map; 353 CodeMap code_map;
354 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", "", 0); 354 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
355 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", "", 0); 355 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
356 code_map.AddCode(ToAddress(0x1500), &entry1, 0x200); 356 code_map.AddCode(ToAddress(0x1500), &entry1, 0x200);
357 code_map.AddCode(ToAddress(0x1700), &entry2, 0x100); 357 code_map.AddCode(ToAddress(0x1700), &entry2, 0x100);
358 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500))); 358 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500)));
359 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700))); 359 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700)));
360 code_map.MoveCode(ToAddress(0x1500), ToAddress(0x1800)); 360 code_map.MoveCode(ToAddress(0x1500), ToAddress(0x1800));
361 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1500))); 361 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1500)));
362 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700))); 362 CHECK_EQ(&entry2, code_map.FindEntry(ToAddress(0x1700)));
363 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1800))); 363 CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1800)));
364 code_map.DeleteCode(ToAddress(0x1700)); 364 code_map.DeleteCode(ToAddress(0x1700));
365 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700))); 365 CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700)));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 CHECK_EQ(entry1, node2->entry()); 417 CHECK_EQ(entry1, node2->entry());
418 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); 418 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3);
419 CHECK_NE(NULL, node3); 419 CHECK_NE(NULL, node3);
420 CHECK_EQ(entry3, node3->entry()); 420 CHECK_EQ(entry3, node3->entry());
421 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); 421 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1);
422 CHECK_NE(NULL, node4); 422 CHECK_NE(NULL, node4);
423 CHECK_EQ(entry1, node4->entry()); 423 CHECK_EQ(entry1, node4->entry());
424 } 424 }
425 425
426 #endif // ENABLE_CPP_PROFILES_PROCESSOR 426 #endif // ENABLE_CPP_PROFILES_PROCESSOR
OLDNEW
« src/platform-linux.cc ('K') | « test/cctest/test-log.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698