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

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

Issue 1474353002: Remove easy to remove calls to Isolate::Current() from api.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update Created 5 years 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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using i::CpuProfiler; 44 using i::CpuProfiler;
45 using i::CpuProfilesCollection; 45 using i::CpuProfilesCollection;
46 using i::ProfileNode; 46 using i::ProfileNode;
47 using i::ProfileTree; 47 using i::ProfileTree;
48 using i::ProfileGenerator; 48 using i::ProfileGenerator;
49 using i::TickSample; 49 using i::TickSample;
50 using i::Vector; 50 using i::Vector;
51 51
52 52
53 TEST(ProfileNodeFindOrAddChild) { 53 TEST(ProfileNodeFindOrAddChild) {
54 ProfileTree tree; 54 CcTest::InitializeVM();
55 ProfileTree tree(CcTest::i_isolate());
55 ProfileNode* node = tree.root(); 56 ProfileNode* node = tree.root();
56 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa"); 57 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
57 ProfileNode* childNode1 = node->FindOrAddChild(&entry1); 58 ProfileNode* childNode1 = node->FindOrAddChild(&entry1);
58 CHECK(childNode1); 59 CHECK(childNode1);
59 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1)); 60 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
60 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb"); 61 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
61 ProfileNode* childNode2 = node->FindOrAddChild(&entry2); 62 ProfileNode* childNode2 = node->FindOrAddChild(&entry2);
62 CHECK(childNode2); 63 CHECK(childNode2);
63 CHECK_NE(childNode1, childNode2); 64 CHECK_NE(childNode1, childNode2);
64 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1)); 65 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
65 CHECK_EQ(childNode2, node->FindOrAddChild(&entry2)); 66 CHECK_EQ(childNode2, node->FindOrAddChild(&entry2));
66 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc"); 67 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
67 ProfileNode* childNode3 = node->FindOrAddChild(&entry3); 68 ProfileNode* childNode3 = node->FindOrAddChild(&entry3);
68 CHECK(childNode3); 69 CHECK(childNode3);
69 CHECK_NE(childNode1, childNode3); 70 CHECK_NE(childNode1, childNode3);
70 CHECK_NE(childNode2, childNode3); 71 CHECK_NE(childNode2, childNode3);
71 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1)); 72 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
72 CHECK_EQ(childNode2, node->FindOrAddChild(&entry2)); 73 CHECK_EQ(childNode2, node->FindOrAddChild(&entry2));
73 CHECK_EQ(childNode3, node->FindOrAddChild(&entry3)); 74 CHECK_EQ(childNode3, node->FindOrAddChild(&entry3));
74 } 75 }
75 76
76 77
77 TEST(ProfileNodeFindOrAddChildForSameFunction) { 78 TEST(ProfileNodeFindOrAddChildForSameFunction) {
79 CcTest::InitializeVM();
78 const char* aaa = "aaa"; 80 const char* aaa = "aaa";
79 ProfileTree tree; 81 ProfileTree tree(CcTest::i_isolate());
80 ProfileNode* node = tree.root(); 82 ProfileNode* node = tree.root();
81 CodeEntry entry1(i::Logger::FUNCTION_TAG, aaa); 83 CodeEntry entry1(i::Logger::FUNCTION_TAG, aaa);
82 ProfileNode* childNode1 = node->FindOrAddChild(&entry1); 84 ProfileNode* childNode1 = node->FindOrAddChild(&entry1);
83 CHECK(childNode1); 85 CHECK(childNode1);
84 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1)); 86 CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
85 // The same function again. 87 // The same function again.
86 CodeEntry entry2(i::Logger::FUNCTION_TAG, aaa); 88 CodeEntry entry2(i::Logger::FUNCTION_TAG, aaa);
87 CHECK_EQ(childNode1, node->FindOrAddChild(&entry2)); 89 CHECK_EQ(childNode1, node->FindOrAddChild(&entry2));
88 // Now with a different security token. 90 // Now with a different security token.
89 CodeEntry entry3(i::Logger::FUNCTION_TAG, aaa); 91 CodeEntry entry3(i::Logger::FUNCTION_TAG, aaa);
(...skipping 25 matching lines...) Expand all
115 } 117 }
116 118
117 private: 119 private:
118 const ProfileTree* tree_; 120 const ProfileTree* tree_;
119 }; 121 };
120 122
121 } // namespace 123 } // namespace
122 124
123 125
124 TEST(ProfileTreeAddPathFromEnd) { 126 TEST(ProfileTreeAddPathFromEnd) {
127 CcTest::InitializeVM();
125 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa"); 128 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
126 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb"); 129 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
127 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc"); 130 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
128 ProfileTree tree; 131 ProfileTree tree(CcTest::i_isolate());
129 ProfileTreeTestHelper helper(&tree); 132 ProfileTreeTestHelper helper(&tree);
130 CHECK(!helper.Walk(&entry1)); 133 CHECK(!helper.Walk(&entry1));
131 CHECK(!helper.Walk(&entry2)); 134 CHECK(!helper.Walk(&entry2));
132 CHECK(!helper.Walk(&entry3)); 135 CHECK(!helper.Walk(&entry3));
133 136
134 CodeEntry* path[] = {NULL, &entry3, NULL, &entry2, NULL, NULL, &entry1, NULL}; 137 CodeEntry* path[] = {NULL, &entry3, NULL, &entry2, NULL, NULL, &entry1, NULL};
135 Vector<CodeEntry*> path_vec(path, sizeof(path) / sizeof(path[0])); 138 Vector<CodeEntry*> path_vec(path, sizeof(path) / sizeof(path[0]));
136 tree.AddPathFromEnd(path_vec); 139 tree.AddPathFromEnd(path_vec);
137 CHECK(!helper.Walk(&entry2)); 140 CHECK(!helper.Walk(&entry2));
138 CHECK(!helper.Walk(&entry3)); 141 CHECK(!helper.Walk(&entry3));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 CHECK_EQ(node3, helper.Walk(&entry1, &entry2, &entry3)); 177 CHECK_EQ(node3, helper.Walk(&entry1, &entry2, &entry3));
175 CHECK_EQ(2u, node3->self_ticks()); 178 CHECK_EQ(2u, node3->self_ticks());
176 ProfileNode* node4 = helper.Walk(&entry1, &entry2, &entry2); 179 ProfileNode* node4 = helper.Walk(&entry1, &entry2, &entry2);
177 CHECK(node4); 180 CHECK(node4);
178 CHECK_NE(node3, node4); 181 CHECK_NE(node3, node4);
179 CHECK_EQ(1u, node4->self_ticks()); 182 CHECK_EQ(1u, node4->self_ticks());
180 } 183 }
181 184
182 185
183 TEST(ProfileTreeCalculateTotalTicks) { 186 TEST(ProfileTreeCalculateTotalTicks) {
184 ProfileTree empty_tree; 187 CcTest::InitializeVM();
188 ProfileTree empty_tree(CcTest::i_isolate());
185 CHECK_EQ(0u, empty_tree.root()->self_ticks()); 189 CHECK_EQ(0u, empty_tree.root()->self_ticks());
186 empty_tree.root()->IncrementSelfTicks(); 190 empty_tree.root()->IncrementSelfTicks();
187 CHECK_EQ(1u, empty_tree.root()->self_ticks()); 191 CHECK_EQ(1u, empty_tree.root()->self_ticks());
188 192
189 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa"); 193 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
190 CodeEntry* e1_path[] = {&entry1}; 194 CodeEntry* e1_path[] = {&entry1};
191 Vector<CodeEntry*> e1_path_vec( 195 Vector<CodeEntry*> e1_path_vec(
192 e1_path, sizeof(e1_path) / sizeof(e1_path[0])); 196 e1_path, sizeof(e1_path) / sizeof(e1_path[0]));
193 197
194 ProfileTree single_child_tree; 198 ProfileTree single_child_tree(CcTest::i_isolate());
195 single_child_tree.AddPathFromEnd(e1_path_vec); 199 single_child_tree.AddPathFromEnd(e1_path_vec);
196 single_child_tree.root()->IncrementSelfTicks(); 200 single_child_tree.root()->IncrementSelfTicks();
197 CHECK_EQ(1u, single_child_tree.root()->self_ticks()); 201 CHECK_EQ(1u, single_child_tree.root()->self_ticks());
198 ProfileTreeTestHelper single_child_helper(&single_child_tree); 202 ProfileTreeTestHelper single_child_helper(&single_child_tree);
199 ProfileNode* node1 = single_child_helper.Walk(&entry1); 203 ProfileNode* node1 = single_child_helper.Walk(&entry1);
200 CHECK(node1); 204 CHECK(node1);
201 CHECK_EQ(1u, single_child_tree.root()->self_ticks()); 205 CHECK_EQ(1u, single_child_tree.root()->self_ticks());
202 CHECK_EQ(1u, node1->self_ticks()); 206 CHECK_EQ(1u, node1->self_ticks());
203 207
204 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb"); 208 CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
205 CodeEntry* e2_e1_path[] = {&entry2, &entry1}; 209 CodeEntry* e2_e1_path[] = {&entry2, &entry1};
206 Vector<CodeEntry*> e2_e1_path_vec(e2_e1_path, 210 Vector<CodeEntry*> e2_e1_path_vec(e2_e1_path,
207 sizeof(e2_e1_path) / sizeof(e2_e1_path[0])); 211 sizeof(e2_e1_path) / sizeof(e2_e1_path[0]));
208 212
209 ProfileTree flat_tree; 213 ProfileTree flat_tree(CcTest::i_isolate());
210 ProfileTreeTestHelper flat_helper(&flat_tree); 214 ProfileTreeTestHelper flat_helper(&flat_tree);
211 flat_tree.AddPathFromEnd(e1_path_vec); 215 flat_tree.AddPathFromEnd(e1_path_vec);
212 flat_tree.AddPathFromEnd(e1_path_vec); 216 flat_tree.AddPathFromEnd(e1_path_vec);
213 flat_tree.AddPathFromEnd(e2_e1_path_vec); 217 flat_tree.AddPathFromEnd(e2_e1_path_vec);
214 flat_tree.AddPathFromEnd(e2_e1_path_vec); 218 flat_tree.AddPathFromEnd(e2_e1_path_vec);
215 flat_tree.AddPathFromEnd(e2_e1_path_vec); 219 flat_tree.AddPathFromEnd(e2_e1_path_vec);
216 // Results in {root,0,0} -> {entry1,0,2} -> {entry2,0,3} 220 // Results in {root,0,0} -> {entry1,0,2} -> {entry2,0,3}
217 CHECK_EQ(0u, flat_tree.root()->self_ticks()); 221 CHECK_EQ(0u, flat_tree.root()->self_ticks());
218 node1 = flat_helper.Walk(&entry1); 222 node1 = flat_helper.Walk(&entry1);
219 CHECK(node1); 223 CHECK(node1);
220 CHECK_EQ(2u, node1->self_ticks()); 224 CHECK_EQ(2u, node1->self_ticks());
221 ProfileNode* node2 = flat_helper.Walk(&entry1, &entry2); 225 ProfileNode* node2 = flat_helper.Walk(&entry1, &entry2);
222 CHECK(node2); 226 CHECK(node2);
223 CHECK_EQ(3u, node2->self_ticks()); 227 CHECK_EQ(3u, node2->self_ticks());
224 // Must calculate {root,5,0} -> {entry1,5,2} -> {entry2,3,3} 228 // Must calculate {root,5,0} -> {entry1,5,2} -> {entry2,3,3}
225 CHECK_EQ(0u, flat_tree.root()->self_ticks()); 229 CHECK_EQ(0u, flat_tree.root()->self_ticks());
226 CHECK_EQ(2u, node1->self_ticks()); 230 CHECK_EQ(2u, node1->self_ticks());
227 231
228 CodeEntry* e2_path[] = {&entry2}; 232 CodeEntry* e2_path[] = {&entry2};
229 Vector<CodeEntry*> e2_path_vec( 233 Vector<CodeEntry*> e2_path_vec(
230 e2_path, sizeof(e2_path) / sizeof(e2_path[0])); 234 e2_path, sizeof(e2_path) / sizeof(e2_path[0]));
231 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc"); 235 CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
232 CodeEntry* e3_path[] = {&entry3}; 236 CodeEntry* e3_path[] = {&entry3};
233 Vector<CodeEntry*> e3_path_vec( 237 Vector<CodeEntry*> e3_path_vec(
234 e3_path, sizeof(e3_path) / sizeof(e3_path[0])); 238 e3_path, sizeof(e3_path) / sizeof(e3_path[0]));
235 239
236 ProfileTree wide_tree; 240 ProfileTree wide_tree(CcTest::i_isolate());
237 ProfileTreeTestHelper wide_helper(&wide_tree); 241 ProfileTreeTestHelper wide_helper(&wide_tree);
238 wide_tree.AddPathFromEnd(e1_path_vec); 242 wide_tree.AddPathFromEnd(e1_path_vec);
239 wide_tree.AddPathFromEnd(e1_path_vec); 243 wide_tree.AddPathFromEnd(e1_path_vec);
240 wide_tree.AddPathFromEnd(e2_e1_path_vec); 244 wide_tree.AddPathFromEnd(e2_e1_path_vec);
241 wide_tree.AddPathFromEnd(e2_path_vec); 245 wide_tree.AddPathFromEnd(e2_path_vec);
242 wide_tree.AddPathFromEnd(e2_path_vec); 246 wide_tree.AddPathFromEnd(e2_path_vec);
243 wide_tree.AddPathFromEnd(e2_path_vec); 247 wide_tree.AddPathFromEnd(e2_path_vec);
244 wide_tree.AddPathFromEnd(e3_path_vec); 248 wide_tree.AddPathFromEnd(e3_path_vec);
245 wide_tree.AddPathFromEnd(e3_path_vec); 249 wide_tree.AddPathFromEnd(e3_path_vec);
246 wide_tree.AddPathFromEnd(e3_path_vec); 250 wide_tree.AddPathFromEnd(e3_path_vec);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 CHECK(const_cast<v8::CpuProfileNode*>(current)); 721 CHECK(const_cast<v8::CpuProfileNode*>(current));
718 722
719 current = PickChild(current, "TryFinally"); 723 current = PickChild(current, "TryFinally");
720 CHECK(const_cast<v8::CpuProfileNode*>(current)); 724 CHECK(const_cast<v8::CpuProfileNode*>(current));
721 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason())); 725 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason()));
722 726
723 current = PickChild(current, "Debugger"); 727 current = PickChild(current, "Debugger");
724 CHECK(const_cast<v8::CpuProfileNode*>(current)); 728 CHECK(const_cast<v8::CpuProfileNode*>(current));
725 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); 729 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason()));
726 } 730 }
OLDNEW
« include/v8.h ('K') | « test/cctest/test-heap-profiler.cc ('k') | tools/v8heapconst.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698