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 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include "include/v8.h" | 9 #include "include/v8.h" |
10 #include "src/simulator.h" | 10 #include "src/simulator.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 public: | 78 public: |
79 struct CodeEventEntry { | 79 struct CodeEventEntry { |
80 std::string name; | 80 std::string name; |
81 const void* code_start; | 81 const void* code_start; |
82 size_t code_len; | 82 size_t code_len; |
83 }; | 83 }; |
84 typedef std::map<const void*, CodeEventEntry> CodeEntries; | 84 typedef std::map<const void*, CodeEventEntry> CodeEntries; |
85 | 85 |
86 explicit SamplingTestHelper(const std::string& test_function) | 86 explicit SamplingTestHelper(const std::string& test_function) |
87 : sample_is_taken_(false), isolate_(CcTest::isolate()) { | 87 : sample_is_taken_(false), isolate_(CcTest::isolate()) { |
88 DCHECK_EQ(NULL, instance_); | 88 DCHECK(!instance_); |
89 instance_ = this; | 89 instance_ = this; |
90 v8::HandleScope scope(isolate_); | 90 v8::HandleScope scope(isolate_); |
91 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_); | 91 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_); |
92 global->Set(v8::String::NewFromUtf8(isolate_, "CollectSample"), | 92 global->Set(v8::String::NewFromUtf8(isolate_, "CollectSample"), |
93 v8::FunctionTemplate::New(isolate_, CollectSample)); | 93 v8::FunctionTemplate::New(isolate_, CollectSample)); |
94 LocalContext env(isolate_, NULL, global); | 94 LocalContext env(isolate_, NULL, global); |
95 isolate_->SetJitCodeEventHandler(v8::kJitCodeEventDefault, | 95 isolate_->SetJitCodeEventHandler(v8::kJitCodeEventDefault, |
96 JitCodeEventHandler); | 96 JitCodeEventHandler); |
97 v8::Script::Compile( | 97 v8::Script::Compile( |
98 v8::String::NewFromUtf8(isolate_, test_function.c_str()))->Run(); | 98 v8::String::NewFromUtf8(isolate_, test_function.c_str()))->Run(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 " return test_sampler_api_inner() + arguments.callee.toString();" | 229 " return test_sampler_api_inner() + arguments.callee.toString();" |
230 "}" | 230 "}" |
231 "test_sampler_api_outer();"; | 231 "test_sampler_api_outer();"; |
232 | 232 |
233 SamplingTestHelper helper(test_script); | 233 SamplingTestHelper helper(test_script); |
234 Sample& sample = helper.sample(); | 234 Sample& sample = helper.sample(); |
235 CHECK_EQ(3, sample.size()); | 235 CHECK_EQ(3, sample.size()); |
236 | 236 |
237 const SamplingTestHelper::CodeEventEntry* entry; | 237 const SamplingTestHelper::CodeEventEntry* entry; |
238 entry = helper.FindEventEntry(sample.begin()[0]); | 238 entry = helper.FindEventEntry(sample.begin()[0]); |
239 CHECK_NE(NULL, entry); | 239 CHECK(entry); |
240 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); | 240 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); |
241 | 241 |
242 entry = helper.FindEventEntry(sample.begin()[1]); | 242 entry = helper.FindEventEntry(sample.begin()[1]); |
243 CHECK_NE(NULL, entry); | 243 CHECK(entry); |
244 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); | 244 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); |
245 } | 245 } |
OLD | NEW |