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

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

Issue 23093022: Fix crashes of some CPU profiler tests on Windows after r16284 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use SmartPointer Created 7 years, 3 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 | « no previous file | 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 // 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 "smart-pointers.h"
34 #include "utils.h" 35 #include "utils.h"
35 #include "../include/v8-profiler.h" 36 #include "../include/v8-profiler.h"
36 using i::CodeEntry; 37 using i::CodeEntry;
37 using i::CpuProfile; 38 using i::CpuProfile;
38 using i::CpuProfiler; 39 using i::CpuProfiler;
39 using i::CpuProfilesCollection; 40 using i::CpuProfilesCollection;
40 using i::Heap; 41 using i::Heap;
41 using i::ProfileGenerator; 42 using i::ProfileGenerator;
42 using i::ProfileNode; 43 using i::ProfileNode;
43 using i::ProfilerEventsProcessor; 44 using i::ProfilerEventsProcessor;
44 using i::ScopedVector; 45 using i::ScopedVector;
46 using i::SmartPointer;
45 using i::Vector; 47 using i::Vector;
46 48
47 49
48 TEST(StartStop) { 50 TEST(StartStop) {
49 CpuProfilesCollection profiles; 51 CpuProfilesCollection profiles;
50 ProfileGenerator generator(&profiles); 52 ProfileGenerator generator(&profiles);
51 ProfilerEventsProcessor processor(&generator); 53 SmartPointer<ProfilerEventsProcessor> processor(
52 processor.Start(); 54 new ProfilerEventsProcessor(&generator));
53 processor.StopSynchronously(); 55 processor->Start();
54 processor.Join(); 56 processor->StopSynchronously();
55 } 57 }
56 58
57 59
58 static inline i::Address ToAddress(int n) { 60 static inline i::Address ToAddress(int n) {
59 return reinterpret_cast<i::Address>(n); 61 return reinterpret_cast<i::Address>(n);
60 } 62 }
61 63
62 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, 64 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
63 i::Address frame1, 65 i::Address frame1,
64 i::Address frame2 = NULL, 66 i::Address frame2 = NULL,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 i::Code* comment_code = CreateCode(&env); 135 i::Code* comment_code = CreateCode(&env);
134 i::Code* args5_code = CreateCode(&env); 136 i::Code* args5_code = CreateCode(&env);
135 i::Code* comment2_code = CreateCode(&env); 137 i::Code* comment2_code = CreateCode(&env);
136 i::Code* moved_code = CreateCode(&env); 138 i::Code* moved_code = CreateCode(&env);
137 i::Code* args3_code = CreateCode(&env); 139 i::Code* args3_code = CreateCode(&env);
138 i::Code* args4_code = CreateCode(&env); 140 i::Code* args4_code = CreateCode(&env);
139 141
140 CpuProfilesCollection* profiles = new CpuProfilesCollection; 142 CpuProfilesCollection* profiles = new CpuProfilesCollection;
141 profiles->StartProfiling("", 1, false); 143 profiles->StartProfiling("", 1, false);
142 ProfileGenerator generator(profiles); 144 ProfileGenerator generator(profiles);
143 ProfilerEventsProcessor processor(&generator); 145 SmartPointer<ProfilerEventsProcessor> processor(
144 processor.Start(); 146 new ProfilerEventsProcessor(&generator));
145 CpuProfiler profiler(isolate, profiles, &generator, &processor); 147 processor->Start();
148 CpuProfiler profiler(isolate, profiles, &generator, *processor);
146 149
147 // Enqueue code creation events. 150 // Enqueue code creation events.
148 const char* aaa_str = "aaa"; 151 const char* aaa_str = "aaa";
149 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( 152 i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
150 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); 153 i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
151 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); 154 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name);
152 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); 155 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment");
153 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); 156 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
154 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); 157 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2");
155 profiler.CodeMoveEvent(comment2_code->address(), moved_code->address()); 158 profiler.CodeMoveEvent(comment2_code->address(), moved_code->address());
156 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3); 159 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3);
157 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4); 160 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4);
158 161
159 // Enqueue a tick event to enable code events processing. 162 // Enqueue a tick event to enable code events processing.
160 EnqueueTickSampleEvent(&processor, aaa_code->address()); 163 EnqueueTickSampleEvent(*processor, aaa_code->address());
161 164
162 processor.StopSynchronously(); 165 processor->StopSynchronously();
163 processor.Join();
164 166
165 // Check the state of profile generator. 167 // Check the state of profile generator.
166 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address()); 168 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address());
167 CHECK_NE(NULL, aaa); 169 CHECK_NE(NULL, aaa);
168 CHECK_EQ(aaa_str, aaa->name()); 170 CHECK_EQ(aaa_str, aaa->name());
169 171
170 CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address()); 172 CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address());
171 CHECK_NE(NULL, comment); 173 CHECK_NE(NULL, comment);
172 CHECK_EQ("comment", comment->name()); 174 CHECK_EQ("comment", comment->name());
173 175
(...skipping 21 matching lines...) Expand all
195 i::Isolate* isolate = i::Isolate::Current(); 197 i::Isolate* isolate = i::Isolate::Current();
196 i::HandleScope scope(isolate); 198 i::HandleScope scope(isolate);
197 199
198 i::Code* frame1_code = CreateCode(&env); 200 i::Code* frame1_code = CreateCode(&env);
199 i::Code* frame2_code = CreateCode(&env); 201 i::Code* frame2_code = CreateCode(&env);
200 i::Code* frame3_code = CreateCode(&env); 202 i::Code* frame3_code = CreateCode(&env);
201 203
202 CpuProfilesCollection* profiles = new CpuProfilesCollection; 204 CpuProfilesCollection* profiles = new CpuProfilesCollection;
203 profiles->StartProfiling("", 1, false); 205 profiles->StartProfiling("", 1, false);
204 ProfileGenerator generator(profiles); 206 ProfileGenerator generator(profiles);
205 ProfilerEventsProcessor processor(&generator); 207 SmartPointer<ProfilerEventsProcessor> processor(
206 processor.Start(); 208 new ProfilerEventsProcessor(&generator));
207 CpuProfiler profiler(isolate, profiles, &generator, &processor); 209 processor->Start();
210 CpuProfiler profiler(isolate, profiles, &generator, *processor);
208 211
209 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); 212 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb");
210 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); 213 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
211 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); 214 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
212 215
213 EnqueueTickSampleEvent(&processor, frame1_code->instruction_start()); 216 EnqueueTickSampleEvent(*processor, frame1_code->instruction_start());
214 EnqueueTickSampleEvent( 217 EnqueueTickSampleEvent(
215 &processor, 218 *processor,
216 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, 219 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2,
217 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); 220 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2);
218 EnqueueTickSampleEvent( 221 EnqueueTickSampleEvent(
219 &processor, 222 *processor,
220 frame3_code->instruction_end() - 1, 223 frame3_code->instruction_end() - 1,
221 frame2_code->instruction_end() - 1, 224 frame2_code->instruction_end() - 1,
222 frame1_code->instruction_end() - 1); 225 frame1_code->instruction_end() - 1);
223 226
224 processor.StopSynchronously(); 227 processor->StopSynchronously();
225 processor.Join();
226 CpuProfile* profile = profiles->StopProfiling(""); 228 CpuProfile* profile = profiles->StopProfiling("");
227 CHECK_NE(NULL, profile); 229 CHECK_NE(NULL, profile);
228 230
229 // Check call trees. 231 // Check call trees.
230 const i::List<ProfileNode*>* top_down_root_children = 232 const i::List<ProfileNode*>* top_down_root_children =
231 profile->top_down()->root()->children(); 233 profile->top_down()->root()->children();
232 CHECK_EQ(1, top_down_root_children->length()); 234 CHECK_EQ(1, top_down_root_children->length());
233 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name()); 235 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name());
234 const i::List<ProfileNode*>* top_down_bbb_children = 236 const i::List<ProfileNode*>* top_down_bbb_children =
235 top_down_root_children->last()->children(); 237 top_down_root_children->last()->children();
(...skipping 28 matching lines...) Expand all
264 TestSetup test_setup; 266 TestSetup test_setup;
265 LocalContext env; 267 LocalContext env;
266 i::Isolate* isolate = i::Isolate::Current(); 268 i::Isolate* isolate = i::Isolate::Current();
267 i::HandleScope scope(isolate); 269 i::HandleScope scope(isolate);
268 270
269 i::Code* code = CreateCode(&env); 271 i::Code* code = CreateCode(&env);
270 272
271 CpuProfilesCollection* profiles = new CpuProfilesCollection; 273 CpuProfilesCollection* profiles = new CpuProfilesCollection;
272 profiles->StartProfiling("", 1, false); 274 profiles->StartProfiling("", 1, false);
273 ProfileGenerator generator(profiles); 275 ProfileGenerator generator(profiles);
274 ProfilerEventsProcessor processor(&generator); 276 SmartPointer<ProfilerEventsProcessor> processor(
275 processor.Start(); 277 new ProfilerEventsProcessor(&generator));
276 CpuProfiler profiler(isolate, profiles, &generator, &processor); 278 processor->Start();
279 CpuProfiler profiler(isolate, profiles, &generator, *processor);
277 280
278 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); 281 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
279 282
280 i::TickSample* sample = processor.StartTickSample(); 283 i::TickSample* sample = processor->StartTickSample();
281 sample->pc = code->address(); 284 sample->pc = code->address();
282 sample->tos = 0; 285 sample->tos = 0;
283 sample->frames_count = i::TickSample::kMaxFramesCount; 286 sample->frames_count = i::TickSample::kMaxFramesCount;
284 for (int i = 0; i < sample->frames_count; ++i) { 287 for (int i = 0; i < sample->frames_count; ++i) {
285 sample->stack[i] = code->address(); 288 sample->stack[i] = code->address();
286 } 289 }
287 processor.FinishTickSample(); 290 processor->FinishTickSample();
288 291
289 processor.StopSynchronously(); 292 processor->StopSynchronously();
290 processor.Join();
291 CpuProfile* profile = profiles->StopProfiling(""); 293 CpuProfile* profile = profiles->StopProfiling("");
292 CHECK_NE(NULL, profile); 294 CHECK_NE(NULL, profile);
293 295
294 int actual_depth = 0; 296 int actual_depth = 0;
295 const ProfileNode* node = profile->top_down()->root(); 297 const ProfileNode* node = profile->top_down()->root();
296 while (node->children()->length() > 0) { 298 while (node->children()->length() > 0) {
297 node = node->children()->last(); 299 node = node->children()->last();
298 ++actual_depth; 300 ++actual_depth;
299 } 301 }
300 302
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 CHECK_GE(programNode->GetHitCount(), 3); 1376 CHECK_GE(programNode->GetHitCount(), 3);
1375 1377
1376 const v8::CpuProfileNode* idleNode = 1378 const v8::CpuProfileNode* idleNode =
1377 GetChild(root, ProfileGenerator::kIdleEntryName); 1379 GetChild(root, ProfileGenerator::kIdleEntryName);
1378 CHECK_EQ(0, idleNode->GetChildrenCount()); 1380 CHECK_EQ(0, idleNode->GetChildrenCount());
1379 CHECK_GE(idleNode->GetSelfSamplesCount(), 3); 1381 CHECK_GE(idleNode->GetSelfSamplesCount(), 3);
1380 CHECK_GE(idleNode->GetHitCount(), 3); 1382 CHECK_GE(idleNode->GetHitCount(), 3);
1381 1383
1382 cpu_profiler->DeleteAllCpuProfiles(); 1384 cpu_profiler->DeleteAllCpuProfiles();
1383 } 1385 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698