Chromium Code Reviews| 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 #include "v8.h" | 5 #include "v8.h" |
| 6 #include "cpu-profiler-inl.h" | 6 #include "cpu-profiler-inl.h" |
| 7 #include "cctest.h" | 7 #include "cctest.h" |
| 8 #include "platform.h" | |
| 8 #include "../include/v8-profiler.h" | 9 #include "../include/v8-profiler.h" |
| 9 | 10 |
| 10 using i::CodeEntry; | 11 using i::CodeEntry; |
| 11 using i::CpuProfile; | 12 using i::CpuProfile; |
| 12 using i::CpuProfiler; | 13 using i::CpuProfiler; |
| 13 using i::CpuProfilesCollection; | 14 using i::CpuProfilesCollection; |
| 14 using i::ProfileGenerator; | 15 using i::ProfileGenerator; |
| 15 using i::ProfileNode; | 16 using i::ProfileNode; |
| 16 using i::ProfilerEventsProcessor; | 17 using i::ProfilerEventsProcessor; |
| 17 using i::TokenEnumerator; | 18 using i::TokenEnumerator; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 31 static void InitializeVM() { | 32 static void InitializeVM() { |
| 32 if (env.IsEmpty()) env = v8::Context::New(); | 33 if (env.IsEmpty()) env = v8::Context::New(); |
| 33 v8::HandleScope scope; | 34 v8::HandleScope scope; |
| 34 env->Enter(); | 35 env->Enter(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 static inline i::Address ToAddress(int n) { | 38 static inline i::Address ToAddress(int n) { |
| 38 return reinterpret_cast<i::Address>(n); | 39 return reinterpret_cast<i::Address>(n); |
| 39 } | 40 } |
| 40 | 41 |
| 41 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, | 42 static void AddTickSampleEvent(ProfilerEventsProcessor* processor, |
| 42 i::Address frame1, | 43 i::Address frame1, |
|
Jakob Kummerow
2012/09/04 17:44:46
indentation
| |
| 43 i::Address frame2 = NULL, | 44 i::Address frame2 = NULL, |
| 44 i::Address frame3 = NULL) { | 45 i::Address frame3 = NULL) { |
| 45 i::TickSample* sample = proc->TickSampleEvent(); | 46 i::TickSample* sample; |
| 47 while ((sample = processor->StartTickSampleEvent()) == NULL) i::OS::Sleep(1); | |
| 46 sample->pc = frame1; | 48 sample->pc = frame1; |
| 47 sample->tos = frame1; | 49 sample->tos = frame1; |
| 48 sample->frames_count = 0; | 50 sample->frames_count = 0; |
| 49 if (frame2 != NULL) { | 51 if (frame2 != NULL) { |
| 50 sample->stack[0] = frame2; | 52 sample->stack[0] = frame2; |
| 51 sample->frames_count = 1; | 53 sample->frames_count = 1; |
| 52 } | 54 } |
| 53 if (frame3 != NULL) { | 55 if (frame3 != NULL) { |
| 54 sample->stack[1] = frame3; | 56 sample->stack[1] = frame3; |
| 55 sample->frames_count = 2; | 57 sample->frames_count = 2; |
| 56 } | 58 } |
| 59 processor->FinishTickSampleEvent(); | |
| 57 } | 60 } |
| 58 | 61 |
| 59 namespace { | 62 namespace { |
| 60 | 63 |
| 61 class TestSetup { | 64 class TestSetup { |
| 62 public: | 65 public: |
| 63 TestSetup() | 66 TestSetup() |
| 64 : old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) { | 67 : old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) { |
| 65 i::FLAG_prof_browser_mode = false; | 68 i::FLAG_prof_browser_mode = false; |
| 66 } | 69 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 ToAddress(0x1200), | 104 ToAddress(0x1200), |
| 102 0x80); | 105 0x80); |
| 103 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); | 106 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); |
| 104 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 107 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 105 "ddd", | 108 "ddd", |
| 106 ToAddress(0x1400), | 109 ToAddress(0x1400), |
| 107 0x80); | 110 0x80); |
| 108 processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500)); | 111 processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500)); |
| 109 processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10); | 112 processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10); |
| 110 processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10); | 113 processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10); |
| 111 // Enqueue a tick event to enable code events processing. | 114 // Add a tick event to enable code events processing. |
| 112 EnqueueTickSampleEvent(&processor, ToAddress(0x1000)); | 115 AddTickSampleEvent(&processor, ToAddress(0x1000)); |
| 113 | 116 |
| 114 processor.Stop(); | 117 processor.Stop(); |
| 115 processor.Join(); | 118 processor.Join(); |
| 116 | 119 |
| 117 // Check the state of profile generator. | 120 // Check the state of profile generator. |
| 118 CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000)); | 121 CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000)); |
| 119 CHECK_NE(NULL, entry1); | 122 CHECK_NE(NULL, entry1); |
| 120 CHECK_EQ(aaa_str, entry1->name()); | 123 CHECK_EQ(aaa_str, entry1->name()); |
| 121 CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200)); | 124 CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200)); |
| 122 CHECK_NE(NULL, entry2); | 125 CHECK_NE(NULL, entry2); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 147 | 150 |
| 148 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 151 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 149 "bbb", | 152 "bbb", |
| 150 ToAddress(0x1200), | 153 ToAddress(0x1200), |
| 151 0x80); | 154 0x80); |
| 152 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); | 155 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); |
| 153 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 156 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 154 "ddd", | 157 "ddd", |
| 155 ToAddress(0x1400), | 158 ToAddress(0x1400), |
| 156 0x80); | 159 0x80); |
| 157 EnqueueTickSampleEvent(&processor, ToAddress(0x1210)); | 160 AddTickSampleEvent(&processor, ToAddress(0x1210)); |
| 158 EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220)); | 161 AddTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220)); |
| 159 EnqueueTickSampleEvent(&processor, | 162 AddTickSampleEvent(&processor, |
| 160 ToAddress(0x1404), | 163 ToAddress(0x1404), |
|
Jakob Kummerow
2012/09/04 17:44:46
indentation
| |
| 161 ToAddress(0x1305), | 164 ToAddress(0x1305), |
| 162 ToAddress(0x1230)); | 165 ToAddress(0x1230)); |
| 163 | 166 |
| 164 processor.Stop(); | 167 processor.Stop(); |
| 165 processor.Join(); | 168 processor.Join(); |
| 166 CpuProfile* profile = | 169 CpuProfile* profile = |
| 167 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); | 170 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); |
| 168 CHECK_NE(NULL, profile); | 171 CHECK_NE(NULL, profile); |
| 169 | 172 |
| 170 // Check call trees. | 173 // Check call trees. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 profiles.StartProfiling("", 1); | 236 profiles.StartProfiling("", 1); |
| 234 ProfileGenerator generator(&profiles); | 237 ProfileGenerator generator(&profiles); |
| 235 ProfilerEventsProcessor processor(&generator, NULL, 1000); | 238 ProfilerEventsProcessor processor(&generator, NULL, 1000); |
| 236 processor.Start(); | 239 processor.Start(); |
| 237 | 240 |
| 238 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 241 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 239 "bbb", | 242 "bbb", |
| 240 ToAddress(0x1200), | 243 ToAddress(0x1200), |
| 241 0x80); | 244 0x80); |
| 242 | 245 |
| 243 i::TickSample* sample = processor.TickSampleEvent(); | 246 i::TickSample* sample = processor.StartTickSampleEvent(); |
| 244 sample->pc = ToAddress(0x1200); | 247 sample->pc = ToAddress(0x1200); |
| 245 sample->tos = 0; | 248 sample->tos = 0; |
| 246 sample->frames_count = i::TickSample::kMaxFramesCount; | 249 sample->frames_count = i::TickSample::kMaxFramesCount; |
| 247 for (int i = 0; i < sample->frames_count; ++i) { | 250 for (int i = 0; i < sample->frames_count; ++i) { |
| 248 sample->stack[i] = ToAddress(0x1200); | 251 sample->stack[i] = ToAddress(0x1200); |
| 249 } | 252 } |
| 253 processor.FinishTickSampleEvent(); | |
| 250 | 254 |
| 251 processor.Stop(); | 255 processor.Stop(); |
| 252 processor.Join(); | 256 processor.Join(); |
| 253 CpuProfile* profile = | 257 CpuProfile* profile = |
| 254 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); | 258 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); |
| 255 CHECK_NE(NULL, profile); | 259 CHECK_NE(NULL, profile); |
| 256 | 260 |
| 257 int actual_depth = 0; | 261 int actual_depth = 0; |
| 258 const ProfileNode* node = profile->top_down()->root(); | 262 const ProfileNode* node = profile->top_down()->root(); |
| 259 while (node->children()->length() > 0) { | 263 while (node->children()->length() > 0) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); | 394 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
| 391 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); | 395 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 392 const_cast<v8::CpuProfile*>(p2)->Delete(); | 396 const_cast<v8::CpuProfile*>(p2)->Delete(); |
| 393 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); | 397 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 394 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); | 398 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
| 395 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); | 399 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 396 const_cast<v8::CpuProfile*>(p3)->Delete(); | 400 const_cast<v8::CpuProfile*>(p3)->Delete(); |
| 397 CHECK_EQ(0, CpuProfiler::GetProfilesCount()); | 401 CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 398 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); | 402 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); |
| 399 } | 403 } |
| OLD | NEW |