diff --git a/src/nsolid/nsolid_cpu_profiler.cc b/src/nsolid/nsolid_cpu_profiler.cc index e9fe4b6cd5..8f5af8940a 100644 --- a/src/nsolid/nsolid_cpu_profiler.cc +++ b/src/nsolid/nsolid_cpu_profiler.cc @@ -1,12 +1,53 @@ -#include -#include "env-inl.h" #include "nsolid_cpu_profiler.h" +#include "asserts-cpp/asserts.h" +#include "nsolid/nsolid_api.h" +#include "nsolid/nsolid_output_stream.h" +#include "v8-profiler.h" namespace node { namespace nsolid { std::atomic NSolidCpuProfiler::is_running = { false }; +CpuProfilerStor::CpuProfilerStor(uint64_t thread_id, + uint64_t timeout, + const std::string& title, + void* data, + CpuProfiler::cpu_profiler_proxy_sig proxy, + internal::deleter_sig deleter) + : status_(0), + thread_id_(thread_id), + timeout_(timeout), + title_(title), + profiler_(nullptr), + profile_(nullptr), + proxy_(proxy), + data_(data, deleter) {} + +CpuProfilerStor::~CpuProfilerStor() { + // Don't try to access the profile if the Isolate it comes from is gone + SharedEnvInst envinst = GetEnvInst(thread_id_); + if (!envinst) { + return; + } + + // Keep the Isolate alive while diposing the profiler and profile + EnvInst::Scope scp(envinst); + if (!scp.Success()) { + return; + } + + if (profile_) { + profile_->Delete(); + profile_ = nullptr; + } + + if (profiler_) { + profiler_->Dispose(); + profiler_ = nullptr; + } +} + NSolidCpuProfiler::NSolidCpuProfiler(): dummy_stub_(nullptr, nullptr) { is_running = true; ASSERT_EQ(0, blocked_cpu_profilers_.init(true)); diff --git a/src/nsolid/nsolid_cpu_profiler.h b/src/nsolid/nsolid_cpu_profiler.h index 9e52c17685..b6b6fcb7e9 100644 --- a/src/nsolid/nsolid_cpu_profiler.h +++ b/src/nsolid/nsolid_cpu_profiler.h @@ -1,73 +1,45 @@ #ifndef SRC_NSOLID_NSOLID_CPU_PROFILER_H_ #define SRC_NSOLID_NSOLID_CPU_PROFILER_H_ -#include -#include -#include -#include -#include #include +#include "nsolid.h" +#include "nsolid/nsolid_util.h" +#include "nsuv-inl.h" -#include "asserts-cpp/asserts.h" +// pre-declarations. +namespace v8 { +class CpuProfiler; +class CpuProfile; +} // namespace v8 namespace node { namespace nsolid { - -class NSolidCpuProfiler { +struct CpuProfilerStor { public: - struct CpuProfilerStor { - CpuProfilerStor(uint64_t thread_id, - uint64_t timeout, - const std::string& title, - void* data, - CpuProfiler::cpu_profiler_proxy_sig proxy, - internal::deleter_sig deleter): - status_(0), - thread_id_(thread_id), - timeout_(timeout), - title_(title), - profiler_(nullptr), - profile_(nullptr), - proxy_(proxy), - data_(data, deleter) { - } - - ~CpuProfilerStor() { - // Don't try to access the profile if the Isolate it comes from is gone - SharedEnvInst envinst = GetEnvInst(thread_id_); - if (!envinst) { - return; - } - - // Keep the Isolate alive while diposing the profiler and profile - EnvInst::Scope scp(envinst); - if (!scp.Success()) { - return; - } - - if (profile_) { - profile_->Delete(); - profile_ = nullptr; - } - - if (profiler_) { - profiler_->Dispose(); - profiler_ = nullptr; - } - } - - int status_; - uint64_t thread_id_; - uint64_t timeout_; - std::string title_; - v8::CpuProfiler* profiler_; - v8::CpuProfile* profile_; - CpuProfiler::cpu_profiler_proxy_sig proxy_; - internal::user_data data_; - }; + explicit CpuProfilerStor(uint64_t thread_id, + uint64_t timeout, + const std::string& title, + void* data, + CpuProfiler::cpu_profiler_proxy_sig proxy, + internal::deleter_sig deleter); + NSOLID_DELETE_DEFAULT_CONSTRUCTORS(CpuProfilerStor) + ~CpuProfilerStor(); + private: + friend class NSolidCpuProfiler; + int status_; + uint64_t thread_id_; + uint64_t timeout_; + std::string title_; + v8::CpuProfiler* profiler_; + v8::CpuProfile* profile_; + CpuProfiler::cpu_profiler_proxy_sig proxy_; + internal::user_data data_; +}; +class NSolidCpuProfiler { + public: static NSolidCpuProfiler* Inst(); int TakeCpuProfile(SharedEnvInst envinst, @@ -114,7 +86,6 @@ class NSolidCpuProfiler { ~NSolidCpuProfiler(); }; - } // namespace nsolid } // namespace node