whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 27 | // |
| 28 | // Tests of profiles generator and utilities. |
| 29 | |
| 30 | #include "v8.h" |
| 31 | #include "cpu-profiler-inl.h" |
| 32 | #include "cctest.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 33 | #include "../include/v8-profiler.h" |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 34 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 35 | using i::CodeEntry; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 36 | using i::CpuProfile; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 37 | using i::CpuProfiler; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 38 | using i::CpuProfilesCollection; |
| 39 | using i::ProfileGenerator; |
| 40 | using i::ProfileNode; |
| 41 | using i::ProfilerEventsProcessor; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 42 | using i::TokenEnumerator; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | TEST(StartStop) { |
| 46 | CpuProfilesCollection profiles; |
| 47 | ProfileGenerator generator(&profiles); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 48 | ProfilerEventsProcessor processor(&generator); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 49 | processor.Start(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 50 | processor.Stop(); |
| 51 | processor.Join(); |
| 52 | } |
| 53 | |
| 54 | static v8::Persistent<v8::Context> env; |
| 55 | |
| 56 | static void InitializeVM() { |
| 57 | if (env.IsEmpty()) env = v8::Context::New(); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 58 | v8::HandleScope scope(env->GetIsolate()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 59 | env->Enter(); |
| 60 | } |
| 61 | |
| 62 | static inline i::Address ToAddress(int n) { |
| 63 | return reinterpret_cast<i::Address>(n); |
| 64 | } |
| 65 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 66 | static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, |
| 67 | i::Address frame1, |
| 68 | i::Address frame2 = NULL, |
| 69 | i::Address frame3 = NULL) { |
| 70 | i::TickSample* sample = proc->TickSampleEvent(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 71 | sample->pc = frame1; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 72 | sample->tos = frame1; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 73 | sample->frames_count = 0; |
| 74 | if (frame2 != NULL) { |
| 75 | sample->stack[0] = frame2; |
| 76 | sample->frames_count = 1; |
| 77 | } |
| 78 | if (frame3 != NULL) { |
| 79 | sample->stack[1] = frame3; |
| 80 | sample->frames_count = 2; |
| 81 | } |
| 82 | } |
| 83 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 84 | namespace { |
| 85 | |
| 86 | class TestSetup { |
| 87 | public: |
| 88 | TestSetup() |
| 89 | : old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) { |
| 90 | i::FLAG_prof_browser_mode = false; |
| 91 | } |
| 92 | |
| 93 | ~TestSetup() { |
| 94 | i::FLAG_prof_browser_mode = old_flag_prof_browser_mode_; |
| 95 | } |
| 96 | |
| 97 | private: |
| 98 | bool old_flag_prof_browser_mode_; |
| 99 | }; |
| 100 | |
| 101 | } // namespace |
| 102 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 103 | TEST(CodeEvents) { |
| 104 | InitializeVM(); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 105 | i::Isolate* isolate = i::Isolate::Current(); |
| 106 | i::Heap* heap = isolate->heap(); |
| 107 | i::Factory* factory = isolate->factory(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 108 | TestSetup test_setup; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 109 | CpuProfilesCollection profiles; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 110 | profiles.StartProfiling("", 1); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 111 | ProfileGenerator generator(&profiles); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 112 | ProfilerEventsProcessor processor(&generator); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 113 | processor.Start(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 114 | |
| 115 | // Enqueue code creation events. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 116 | i::HandleScope scope(isolate); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 117 | const char* aaa_str = "aaa"; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 118 | i::Handle<i::String> aaa_name = factory->NewStringFromAscii( |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 119 | i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 120 | processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, |
| 121 | *aaa_name, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 122 | heap->empty_string(), |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 123 | 0, |
| 124 | ToAddress(0x1000), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 125 | 0x100, |
| 126 | ToAddress(0x10000)); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 127 | processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 128 | "bbb", |
| 129 | ToAddress(0x1200), |
| 130 | 0x80); |
| 131 | processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); |
| 132 | processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 133 | "ddd", |
| 134 | ToAddress(0x1400), |
| 135 | 0x80); |
| 136 | processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500)); |
| 137 | processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 138 | processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 139 | // Enqueue a tick event to enable code events processing. |
| 140 | EnqueueTickSampleEvent(&processor, ToAddress(0x1000)); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 141 | |
| 142 | processor.Stop(); |
| 143 | processor.Join(); |
| 144 | |
| 145 | // Check the state of profile generator. |
| 146 | CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000)); |
| 147 | CHECK_NE(NULL, entry1); |
| 148 | CHECK_EQ(aaa_str, entry1->name()); |
| 149 | CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200)); |
| 150 | CHECK_NE(NULL, entry2); |
| 151 | CHECK_EQ("bbb", entry2->name()); |
| 152 | CodeEntry* entry3 = generator.code_map()->FindEntry(ToAddress(0x1300)); |
| 153 | CHECK_NE(NULL, entry3); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 154 | CHECK_EQ("5", entry3->name()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 155 | CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1400))); |
| 156 | CodeEntry* entry4 = generator.code_map()->FindEntry(ToAddress(0x1500)); |
| 157 | CHECK_NE(NULL, entry4); |
| 158 | CHECK_EQ("ddd", entry4->name()); |
| 159 | CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1600))); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | template<typename T> |
| 164 | static int CompareProfileNodes(const T* p1, const T* p2) { |
| 165 | return strcmp((*p1)->entry()->name(), (*p2)->entry()->name()); |
| 166 | } |
| 167 | |
| 168 | TEST(TickEvents) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 169 | TestSetup test_setup; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 170 | CpuProfilesCollection profiles; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 171 | profiles.StartProfiling("", 1); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 172 | ProfileGenerator generator(&profiles); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 173 | ProfilerEventsProcessor processor(&generator); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 174 | processor.Start(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 175 | |
| 176 | processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 177 | "bbb", |
| 178 | ToAddress(0x1200), |
| 179 | 0x80); |
| 180 | processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); |
| 181 | processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 182 | "ddd", |
| 183 | ToAddress(0x1400), |
| 184 | 0x80); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 185 | EnqueueTickSampleEvent(&processor, ToAddress(0x1210)); |
| 186 | EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220)); |
| 187 | EnqueueTickSampleEvent(&processor, |
| 188 | ToAddress(0x1404), |
| 189 | ToAddress(0x1305), |
| 190 | ToAddress(0x1230)); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 191 | |
| 192 | processor.Stop(); |
| 193 | processor.Join(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 194 | CpuProfile* profile = |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 195 | profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 196 | CHECK_NE(NULL, profile); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 197 | |
| 198 | // Check call trees. |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 199 | const i::List<ProfileNode*>* top_down_root_children = |
| 200 | profile->top_down()->root()->children(); |
| 201 | CHECK_EQ(1, top_down_root_children->length()); |
| 202 | CHECK_EQ("bbb", top_down_root_children->last()->entry()->name()); |
| 203 | const i::List<ProfileNode*>* top_down_bbb_children = |
| 204 | top_down_root_children->last()->children(); |
| 205 | CHECK_EQ(1, top_down_bbb_children->length()); |
| 206 | CHECK_EQ("5", top_down_bbb_children->last()->entry()->name()); |
| 207 | const i::List<ProfileNode*>* top_down_stub_children = |
| 208 | top_down_bbb_children->last()->children(); |
| 209 | CHECK_EQ(1, top_down_stub_children->length()); |
| 210 | CHECK_EQ("ddd", top_down_stub_children->last()->entry()->name()); |
| 211 | const i::List<ProfileNode*>* top_down_ddd_children = |
| 212 | top_down_stub_children->last()->children(); |
| 213 | CHECK_EQ(0, top_down_ddd_children->length()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 214 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 215 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 216 | |
| 217 | // http://crbug/51594 |
| 218 | // This test must not crash. |
| 219 | TEST(CrashIfStoppingLastNonExistentProfile) { |
| 220 | InitializeVM(); |
| 221 | TestSetup test_setup; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 222 | CpuProfiler::SetUp(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 223 | CpuProfiler::StartProfiling("1"); |
| 224 | CpuProfiler::StopProfiling("2"); |
| 225 | CpuProfiler::StartProfiling("1"); |
| 226 | CpuProfiler::StopProfiling(""); |
| 227 | CpuProfiler::TearDown(); |
| 228 | } |
| 229 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 230 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 231 | // http://code.google.com/p/v8/issues/detail?id=1398 |
| 232 | // Long stacks (exceeding max frames limit) must not be erased. |
| 233 | TEST(Issue1398) { |
| 234 | TestSetup test_setup; |
| 235 | CpuProfilesCollection profiles; |
| 236 | profiles.StartProfiling("", 1); |
| 237 | ProfileGenerator generator(&profiles); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 238 | ProfilerEventsProcessor processor(&generator); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 239 | processor.Start(); |
| 240 | |
| 241 | processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
| 242 | "bbb", |
| 243 | ToAddress(0x1200), |
| 244 | 0x80); |
| 245 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 246 | i::TickSample* sample = processor.TickSampleEvent(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 247 | sample->pc = ToAddress(0x1200); |
| 248 | sample->tos = 0; |
| 249 | sample->frames_count = i::TickSample::kMaxFramesCount; |
| 250 | for (int i = 0; i < sample->frames_count; ++i) { |
| 251 | sample->stack[i] = ToAddress(0x1200); |
| 252 | } |
| 253 | |
| 254 | processor.Stop(); |
| 255 | processor.Join(); |
| 256 | CpuProfile* profile = |
| 257 | profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); |
| 258 | CHECK_NE(NULL, profile); |
| 259 | |
| 260 | int actual_depth = 0; |
| 261 | const ProfileNode* node = profile->top_down()->root(); |
| 262 | while (node->children()->length() > 0) { |
| 263 | node = node->children()->last(); |
| 264 | ++actual_depth; |
| 265 | } |
| 266 | |
| 267 | CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. |
| 268 | } |
| 269 | |
| 270 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 271 | TEST(DeleteAllCpuProfiles) { |
| 272 | InitializeVM(); |
| 273 | TestSetup test_setup; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 274 | CpuProfiler::SetUp(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 275 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 276 | CpuProfiler::DeleteAllProfiles(); |
| 277 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 278 | |
| 279 | CpuProfiler::StartProfiling("1"); |
| 280 | CpuProfiler::StopProfiling("1"); |
| 281 | CHECK_EQ(1, CpuProfiler::GetProfilesCount()); |
| 282 | CpuProfiler::DeleteAllProfiles(); |
| 283 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 284 | CpuProfiler::StartProfiling("1"); |
| 285 | CpuProfiler::StartProfiling("2"); |
| 286 | CpuProfiler::StopProfiling("2"); |
| 287 | CpuProfiler::StopProfiling("1"); |
| 288 | CHECK_EQ(2, CpuProfiler::GetProfilesCount()); |
| 289 | CpuProfiler::DeleteAllProfiles(); |
| 290 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 291 | |
| 292 | // Test profiling cancellation by the 'delete' command. |
| 293 | CpuProfiler::StartProfiling("1"); |
| 294 | CpuProfiler::StartProfiling("2"); |
| 295 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 296 | CpuProfiler::DeleteAllProfiles(); |
| 297 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 298 | |
| 299 | CpuProfiler::TearDown(); |
| 300 | } |
| 301 | |
| 302 | |
| 303 | TEST(DeleteCpuProfile) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 304 | LocalContext env; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 305 | v8::HandleScope scope(env->GetIsolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 306 | |
| 307 | CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount()); |
| 308 | v8::Local<v8::String> name1 = v8::String::New("1"); |
| 309 | v8::CpuProfiler::StartProfiling(name1); |
| 310 | const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1); |
| 311 | CHECK_NE(NULL, p1); |
| 312 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 313 | unsigned uid1 = p1->GetUid(); |
| 314 | CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1)); |
| 315 | const_cast<v8::CpuProfile*>(p1)->Delete(); |
| 316 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 317 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); |
| 318 | |
| 319 | v8::Local<v8::String> name2 = v8::String::New("2"); |
| 320 | v8::CpuProfiler::StartProfiling(name2); |
| 321 | const v8::CpuProfile* p2 = v8::CpuProfiler::StopProfiling(name2); |
| 322 | CHECK_NE(NULL, p2); |
| 323 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 324 | unsigned uid2 = p2->GetUid(); |
| 325 | CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); |
| 326 | CHECK_EQ(p2, v8::CpuProfiler::FindProfile(uid2)); |
| 327 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); |
| 328 | v8::Local<v8::String> name3 = v8::String::New("3"); |
| 329 | v8::CpuProfiler::StartProfiling(name3); |
| 330 | const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3); |
| 331 | CHECK_NE(NULL, p3); |
| 332 | CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount()); |
| 333 | unsigned uid3 = p3->GetUid(); |
| 334 | CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); |
| 335 | CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 336 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); |
| 337 | const_cast<v8::CpuProfile*>(p2)->Delete(); |
| 338 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 339 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
| 340 | CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 341 | const_cast<v8::CpuProfile*>(p3)->Delete(); |
| 342 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 343 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); |
| 344 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
| 345 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | TEST(DeleteCpuProfileDifferentTokens) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 350 | LocalContext env; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 351 | v8::HandleScope scope(env->GetIsolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 352 | |
| 353 | CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount()); |
| 354 | v8::Local<v8::String> name1 = v8::String::New("1"); |
| 355 | v8::CpuProfiler::StartProfiling(name1); |
| 356 | const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1); |
| 357 | CHECK_NE(NULL, p1); |
| 358 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 359 | unsigned uid1 = p1->GetUid(); |
| 360 | CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1)); |
| 361 | v8::Local<v8::String> token1 = v8::String::New("token1"); |
| 362 | const v8::CpuProfile* p1_t1 = v8::CpuProfiler::FindProfile(uid1, token1); |
| 363 | CHECK_NE(NULL, p1_t1); |
| 364 | CHECK_NE(p1, p1_t1); |
| 365 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 366 | const_cast<v8::CpuProfile*>(p1)->Delete(); |
| 367 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 368 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1)); |
| 369 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1, token1)); |
| 370 | const_cast<v8::CpuProfile*>(p1_t1)->Delete(); |
| 371 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 372 | |
| 373 | v8::Local<v8::String> name2 = v8::String::New("2"); |
| 374 | v8::CpuProfiler::StartProfiling(name2); |
| 375 | v8::Local<v8::String> token2 = v8::String::New("token2"); |
| 376 | const v8::CpuProfile* p2_t2 = v8::CpuProfiler::StopProfiling(name2, token2); |
| 377 | CHECK_NE(NULL, p2_t2); |
| 378 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 379 | unsigned uid2 = p2_t2->GetUid(); |
| 380 | CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); |
| 381 | const v8::CpuProfile* p2 = v8::CpuProfiler::FindProfile(uid2); |
| 382 | CHECK_NE(p2_t2, p2); |
| 383 | v8::Local<v8::String> name3 = v8::String::New("3"); |
| 384 | v8::CpuProfiler::StartProfiling(name3); |
| 385 | const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3); |
| 386 | CHECK_NE(NULL, p3); |
| 387 | CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount()); |
| 388 | unsigned uid3 = p3->GetUid(); |
| 389 | CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); |
| 390 | CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 391 | const_cast<v8::CpuProfile*>(p2_t2)->Delete(); |
| 392 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 393 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
| 394 | CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 395 | const_cast<v8::CpuProfile*>(p2)->Delete(); |
| 396 | CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
| 397 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
| 398 | CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
| 399 | const_cast<v8::CpuProfile*>(p3)->Delete(); |
| 400 | CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
| 401 | CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); |
| 402 | } |