| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Tests the sampling API in include/v8.h | 5 // Tests the sampling API in include/v8.h |
| 6 | 6 |
| 7 // TODO(mythria): Remove this define after this flag is turned on globally | 7 // TODO(mythria): Remove this define after this flag is turned on globally |
| 8 #define V8_IMMINENT_DEPRECATION_WARNINGS | 8 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 // The captured sample should have three pc values. | 222 // The captured sample should have three pc values. |
| 223 // They should fall in the range where the compiled code resides. | 223 // They should fall in the range where the compiled code resides. |
| 224 // The expected stack is: | 224 // The expected stack is: |
| 225 // bottom of stack [{anon script}, outer, inner] top of stack | 225 // bottom of stack [{anon script}, outer, inner] top of stack |
| 226 // ^ ^ ^ | 226 // ^ ^ ^ |
| 227 // sample.stack indices 2 1 0 | 227 // sample.stack indices 2 1 0 |
| 228 TEST(StackFramesConsistent) { | 228 TEST(StackFramesConsistent) { |
| 229 // Note: The arguments.callee stuff is there so that the | 229 i::FLAG_allow_natives_syntax = true; |
| 230 // functions are not optimized away. | |
| 231 const char* test_script = | 230 const char* test_script = |
| 232 "function test_sampler_api_inner() {" | 231 "function test_sampler_api_inner() {" |
| 233 " CollectSample();" | 232 " CollectSample();" |
| 234 " return arguments.callee.toString();" | 233 " return 0;" |
| 235 "}" | 234 "}" |
| 236 "function test_sampler_api_outer() {" | 235 "function test_sampler_api_outer() {" |
| 237 " return test_sampler_api_inner() + arguments.callee.toString();" | 236 " return test_sampler_api_inner();" |
| 238 "}" | 237 "}" |
| 238 "%NeverOptimizeFunction(test_sampler_api_inner);" |
| 239 "%NeverOptimizeFunction(test_sampler_api_outer);" |
| 239 "test_sampler_api_outer();"; | 240 "test_sampler_api_outer();"; |
| 240 | 241 |
| 241 SamplingTestHelper helper(test_script); | 242 SamplingTestHelper helper(test_script); |
| 242 Sample& sample = helper.sample(); | 243 Sample& sample = helper.sample(); |
| 243 CHECK_EQ(3, sample.size()); | 244 CHECK_EQ(3, sample.size()); |
| 244 | 245 |
| 245 const SamplingTestHelper::CodeEventEntry* entry; | 246 const SamplingTestHelper::CodeEventEntry* entry; |
| 246 entry = helper.FindEventEntry(sample.begin()[0]); | 247 entry = helper.FindEventEntry(sample.begin()[0]); |
| 247 CHECK(entry); | 248 CHECK(entry); |
| 248 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); | 249 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); |
| 249 | 250 |
| 250 entry = helper.FindEventEntry(sample.begin()[1]); | 251 entry = helper.FindEventEntry(sample.begin()[1]); |
| 251 CHECK(entry); | 252 CHECK(entry); |
| 252 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); | 253 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); |
| 253 } | 254 } |
| OLD | NEW |