|
1 | 1 | #ifndef SRC_NSOLID_NSOLID_CPU_PROFILER_H_
|
2 | 2 | #define SRC_NSOLID_NSOLID_CPU_PROFILER_H_
|
3 | 3 |
|
4 |
| -#include <nsolid/nsolid_api.h> |
5 |
| -#include <nsolid/nsolid_util.h> |
6 |
| -#include <v8.h> |
7 |
| -#include <v8-profiler.h> |
8 |
| -#include <tuple> |
9 | 4 | #include <map>
|
| 5 | +#include "nsolid.h" |
| 6 | +#include "nsolid/nsolid_util.h" |
| 7 | +#include "nsuv-inl.h" |
10 | 8 |
|
11 |
| -#include "asserts-cpp/asserts.h" |
| 9 | +// pre-declarations. |
| 10 | +namespace v8 { |
| 11 | +class CpuProfiler; |
| 12 | +class CpuProfile; |
| 13 | +} // namespace v8 |
12 | 14 |
|
13 | 15 | namespace node {
|
14 | 16 | namespace nsolid {
|
15 | 17 |
|
16 |
| - |
17 |
| -class NSolidCpuProfiler { |
| 18 | +struct CpuProfilerStor { |
18 | 19 | public:
|
19 |
| - struct CpuProfilerStor { |
20 |
| - CpuProfilerStor(uint64_t thread_id, |
21 |
| - uint64_t timeout, |
22 |
| - const std::string& title, |
23 |
| - void* data, |
24 |
| - CpuProfiler::cpu_profiler_proxy_sig proxy, |
25 |
| - internal::deleter_sig deleter): |
26 |
| - status_(0), |
27 |
| - thread_id_(thread_id), |
28 |
| - timeout_(timeout), |
29 |
| - title_(title), |
30 |
| - profiler_(nullptr), |
31 |
| - profile_(nullptr), |
32 |
| - proxy_(proxy), |
33 |
| - data_(data, deleter) { |
34 |
| - } |
35 |
| - |
36 |
| - ~CpuProfilerStor() { |
37 |
| - // Don't try to access the profile if the Isolate it comes from is gone |
38 |
| - SharedEnvInst envinst = GetEnvInst(thread_id_); |
39 |
| - if (!envinst) { |
40 |
| - return; |
41 |
| - } |
42 |
| - |
43 |
| - // Keep the Isolate alive while diposing the profiler and profile |
44 |
| - EnvInst::Scope scp(envinst); |
45 |
| - if (!scp.Success()) { |
46 |
| - return; |
47 |
| - } |
48 |
| - |
49 |
| - if (profile_) { |
50 |
| - profile_->Delete(); |
51 |
| - profile_ = nullptr; |
52 |
| - } |
53 |
| - |
54 |
| - if (profiler_) { |
55 |
| - profiler_->Dispose(); |
56 |
| - profiler_ = nullptr; |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - int status_; |
61 |
| - uint64_t thread_id_; |
62 |
| - uint64_t timeout_; |
63 |
| - std::string title_; |
64 |
| - v8::CpuProfiler* profiler_; |
65 |
| - v8::CpuProfile* profile_; |
66 |
| - CpuProfiler::cpu_profiler_proxy_sig proxy_; |
67 |
| - internal::user_data data_; |
68 |
| - }; |
| 20 | + explicit CpuProfilerStor(uint64_t thread_id, |
| 21 | + uint64_t timeout, |
| 22 | + const std::string& title, |
| 23 | + void* data, |
| 24 | + CpuProfiler::cpu_profiler_proxy_sig proxy, |
| 25 | + internal::deleter_sig deleter); |
| 26 | + NSOLID_DELETE_DEFAULT_CONSTRUCTORS(CpuProfilerStor) |
| 27 | + ~CpuProfilerStor(); |
69 | 28 |
|
| 29 | + private: |
| 30 | + friend class NSolidCpuProfiler; |
| 31 | + uint64_t thread_id_; |
| 32 | + uint64_t timeout_; |
| 33 | + std::string title_; |
| 34 | + v8::CpuProfiler* profiler_; |
| 35 | + v8::CpuProfile* profile_; |
| 36 | + CpuProfiler::cpu_profiler_proxy_sig proxy_; |
| 37 | + internal::user_data data_; |
| 38 | +}; |
70 | 39 |
|
| 40 | +class NSolidCpuProfiler { |
| 41 | + public: |
71 | 42 | static NSolidCpuProfiler* Inst();
|
72 | 43 |
|
73 | 44 | int TakeCpuProfile(SharedEnvInst envinst,
|
@@ -114,7 +85,6 @@ class NSolidCpuProfiler {
|
114 | 85 | ~NSolidCpuProfiler();
|
115 | 86 | };
|
116 | 87 |
|
117 |
| - |
118 | 88 | } // namespace nsolid
|
119 | 89 | } // namespace node
|
120 | 90 |
|
|
0 commit comments