Index: src/cpu-profiler.cc |
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc |
index c0a2c2b4ffe4ae9e1826c6e29416c1e81abafcf0..7387a4c4f88345712a68ba6a705dcda530de3272 100644 |
--- a/src/cpu-profiler.cc |
+++ b/src/cpu-profiler.cc |
@@ -441,6 +441,7 @@ CpuProfiler::CpuProfiler() |
token_enumerator_(new TokenEnumerator()), |
generator_(NULL), |
processor_(NULL), |
+ need_to_stop_sampler_(false), |
is_profiling_(false) { |
} |
@@ -486,7 +487,10 @@ void CpuProfiler::StartProcessorIfNotStarted() { |
} |
// Enable stack sampling. |
Sampler* sampler = reinterpret_cast<Sampler*>(LOGGER->ticker_); |
- if (!sampler->IsActive()) sampler->Start(); |
+ if (!sampler->IsActive()) { |
+ sampler->Start(); |
+ need_to_stop_sampler_ = true; |
+ } |
sampler->IncreaseProfilingDepth(); |
} |
} |
@@ -520,7 +524,10 @@ void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
if (profiles_->IsLastProfile(title)) { |
Sampler* sampler = reinterpret_cast<Sampler*>(LOGGER->ticker_); |
sampler->DecreaseProfilingDepth(); |
- sampler->Stop(); |
+ if (need_to_stop_sampler_) { |
+ sampler->Stop(); |
+ need_to_stop_sampler_ = false; |
+ } |
processor_->Stop(); |
processor_->Join(); |
delete processor_; |