|
4 | 4 |
|
5 | 5 | #include "src/profiler/cpu-profiler.h" |
6 | 6 |
|
| 7 | +#include <unordered_map> |
| 8 | +#include <utility> |
| 9 | + |
| 10 | +#include "src/base/lazy-instance.h" |
| 11 | +#include "src/base/platform/mutex.h" |
| 12 | +#include "src/base/template-utils.h" |
7 | 13 | #include "src/debug/debug.h" |
8 | 14 | #include "src/deoptimizer.h" |
9 | 15 | #include "src/frames-inl.h" |
@@ -275,20 +281,19 @@ void CpuProfiler::set_sampling_interval(base::TimeDelta value) { |
275 | 281 | void CpuProfiler::ResetProfiles() { |
276 | 282 | profiles_.reset(new CpuProfilesCollection(isolate_)); |
277 | 283 | profiles_->set_cpu_profiler(this); |
| 284 | + profiler_listener_.reset(); |
| 285 | + generator_.reset(); |
278 | 286 | } |
279 | 287 |
|
280 | 288 | void CpuProfiler::CreateEntriesForRuntimeCallStats() { |
281 | | - static_entries_.clear(); |
282 | 289 | RuntimeCallStats* rcs = isolate_->counters()->runtime_call_stats(); |
283 | 290 | CodeMap* code_map = generator_->code_map(); |
284 | 291 | for (int i = 0; i < RuntimeCallStats::counters_count; ++i) { |
285 | 292 | RuntimeCallCounter* counter = &(rcs->*(RuntimeCallStats::counters[i])); |
286 | 293 | DCHECK(counter->name()); |
287 | | - std::unique_ptr<CodeEntry> entry( |
288 | | - new CodeEntry(CodeEventListener::FUNCTION_TAG, counter->name(), |
289 | | - CodeEntry::kEmptyNamePrefix, "native V8Runtime")); |
290 | | - code_map->AddCode(reinterpret_cast<Address>(counter), entry.get(), 1); |
291 | | - static_entries_.push_back(std::move(entry)); |
| 294 | + auto entry = new CodeEntry(CodeEventListener::FUNCTION_TAG, counter->name(), |
| 295 | + "native V8Runtime"); |
| 296 | + code_map->AddCode(reinterpret_cast<Address>(counter), entry, 1); |
292 | 297 | } |
293 | 298 | } |
294 | 299 |
|
@@ -321,13 +326,17 @@ void CpuProfiler::StartProcessorIfNotStarted() { |
321 | 326 | // Disable logging when using the new implementation. |
322 | 327 | saved_is_logging_ = logger->is_logging_; |
323 | 328 | logger->is_logging_ = false; |
324 | | - generator_.reset(new ProfileGenerator(profiles_.get())); |
| 329 | + if (!generator_) { |
| 330 | + generator_.reset(new ProfileGenerator(profiles_.get())); |
| 331 | + CreateEntriesForRuntimeCallStats(); |
| 332 | + } |
325 | 333 | processor_.reset(new ProfilerEventsProcessor(isolate_, generator_.get(), |
326 | 334 | sampling_interval_)); |
327 | | - CreateEntriesForRuntimeCallStats(); |
328 | | - logger->SetUpProfilerListener(); |
329 | | - ProfilerListener* profiler_listener = logger->profiler_listener(); |
330 | | - profiler_listener->AddObserver(this); |
| 335 | + if (!profiler_listener_) { |
| 336 | + profiler_listener_.reset(new ProfilerListener(isolate_, this)); |
| 337 | + } |
| 338 | + logger->addCodeEventListener(profiler_listener_.get()); |
| 339 | + |
331 | 340 | is_profiling_ = true; |
332 | 341 | isolate_->set_is_profiling(true); |
333 | 342 | // Enumerate stuff we already have in the heap. |
@@ -362,12 +371,9 @@ void CpuProfiler::StopProcessor() { |
362 | 371 | Logger* logger = isolate_->logger(); |
363 | 372 | is_profiling_ = false; |
364 | 373 | isolate_->set_is_profiling(false); |
365 | | - ProfilerListener* profiler_listener = logger->profiler_listener(); |
366 | | - profiler_listener->RemoveObserver(this); |
| 374 | + logger->removeCodeEventListener(profiler_listener_.get()); |
367 | 375 | processor_->StopSynchronously(); |
368 | | - logger->TearDownProfilerListener(); |
369 | 376 | processor_.reset(); |
370 | | - generator_.reset(); |
371 | 377 | logger->is_logging_ = saved_is_logging_; |
372 | 378 | } |
373 | 379 |
|
|
0 commit comments