summaryrefslogtreecommitdiff
path: root/deps/v8/src/profiler/cpu-profiler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/profiler/cpu-profiler.cc')
-rw-r--r--deps/v8/src/profiler/cpu-profiler.cc64
1 files changed, 55 insertions, 9 deletions
diff --git a/deps/v8/src/profiler/cpu-profiler.cc b/deps/v8/src/profiler/cpu-profiler.cc
index bae592b36d..91617d7231 100644
--- a/deps/v8/src/profiler/cpu-profiler.cc
+++ b/deps/v8/src/profiler/cpu-profiler.cc
@@ -4,6 +4,9 @@
#include "src/profiler/cpu-profiler.h"
+#include "src/base/lazy-instance.h"
+#include "src/base/platform/mutex.h"
+#include "src/base/template-utils.h"
#include "src/debug/debug.h"
#include "src/deoptimizer.h"
#include "src/frames-inl.h"
@@ -129,7 +132,7 @@ ProfilerEventsProcessor::SampleProcessingResult
}
const TickSampleEventRecord* record = ticks_buffer_.Peek();
- if (record == NULL) {
+ if (record == nullptr) {
if (ticks_from_vm_buffer_.IsEmpty()) return NoSamplesInQueue;
return FoundSampleForNextCodeEvent;
}
@@ -171,7 +174,7 @@ void ProfilerEventsProcessor::Run() {
#endif
}
- // Schedule next sample. sampler_ is NULL in tests.
+ // Schedule next sample. sampler_ is nullptr in tests.
if (sampler_) sampler_->DoSample();
}
@@ -241,14 +244,50 @@ void CpuProfiler::CodeEventHandler(const CodeEventsContainer& evt_rec) {
}
}
+namespace {
+
+class CpuProfilersManager {
+ public:
+ void AddProfiler(Isolate* isolate, CpuProfiler* profiler) {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ auto result = profilers_.insert(
+ std::pair<Isolate*, std::unique_ptr<std::set<CpuProfiler*>>>(
+ isolate, base::make_unique<std::set<CpuProfiler*>>()));
+ result.first->second->insert(profiler);
+ }
+
+ void RemoveProfiler(Isolate* isolate, CpuProfiler* profiler) {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ auto it = profilers_.find(isolate);
+ DCHECK(it != profilers_.end());
+ it->second->erase(profiler);
+ if (it->second->empty()) {
+ profilers_.erase(it);
+ }
+ }
+
+ void CallCollectSample(Isolate* isolate) {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ auto profilers = profilers_.find(isolate);
+ if (profilers == profilers_.end()) return;
+ for (auto it : *profilers->second) {
+ it->CollectSample();
+ }
+ }
+
+ private:
+ std::map<Isolate*, std::unique_ptr<std::set<CpuProfiler*>>> profilers_;
+ base::Mutex mutex_;
+};
+
+base::LazyInstance<CpuProfilersManager>::type g_profilers_manager =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
CpuProfiler::CpuProfiler(Isolate* isolate)
- : isolate_(isolate),
- sampling_interval_(base::TimeDelta::FromMicroseconds(
- FLAG_cpu_profiler_sampling_interval)),
- profiles_(new CpuProfilesCollection(isolate)),
- is_profiling_(false) {
- profiles_->set_cpu_profiler(this);
-}
+ : CpuProfiler(isolate, new CpuProfilesCollection(isolate), nullptr,
+ nullptr) {}
CpuProfiler::CpuProfiler(Isolate* isolate, CpuProfilesCollection* test_profiles,
ProfileGenerator* test_generator,
@@ -261,10 +300,12 @@ CpuProfiler::CpuProfiler(Isolate* isolate, CpuProfilesCollection* test_profiles,
processor_(test_processor),
is_profiling_(false) {
profiles_->set_cpu_profiler(this);
+ g_profilers_manager.Pointer()->AddProfiler(isolate, this);
}
CpuProfiler::~CpuProfiler() {
DCHECK(!is_profiling_);
+ g_profilers_manager.Pointer()->RemoveProfiler(isolate_, this);
}
void CpuProfiler::set_sampling_interval(base::TimeDelta value) {
@@ -292,6 +333,11 @@ void CpuProfiler::CreateEntriesForRuntimeCallStats() {
}
}
+// static
+void CpuProfiler::CollectSample(Isolate* isolate) {
+ g_profilers_manager.Pointer()->CallCollectSample(isolate);
+}
+
void CpuProfiler::CollectSample() {
if (processor_) {
processor_->AddCurrentStack(isolate_);