Skip to content

Commit 40931c4

Browse files
santigimenotrevnorris
authored andcommitted
src: move CpuProfilerStor impl to cc file
PR-URL: #18 Reviewed-by: Trevor Norris <[email protected]>
1 parent ac7b0a0 commit 40931c4

File tree

2 files changed

+71
-46
lines changed

2 files changed

+71
-46
lines changed

src/nsolid/nsolid_cpu_profiler.cc

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,52 @@
1-
#include <nsolid/nsolid_output_stream.h>
2-
#include "env-inl.h"
31
#include "nsolid_cpu_profiler.h"
2+
#include "asserts-cpp/asserts.h"
3+
#include "nsolid/nsolid_api.h"
4+
#include "nsolid/nsolid_output_stream.h"
5+
#include "v8-profiler.h"
46

57
namespace node {
68
namespace nsolid {
79

810
std::atomic<bool> NSolidCpuProfiler::is_running = { false };
911

12+
CpuProfilerStor::CpuProfilerStor(uint64_t thread_id,
13+
uint64_t timeout,
14+
const std::string& title,
15+
void* data,
16+
CpuProfiler::cpu_profiler_proxy_sig proxy,
17+
internal::deleter_sig deleter)
18+
: thread_id_(thread_id),
19+
timeout_(timeout),
20+
title_(title),
21+
profiler_(nullptr),
22+
profile_(nullptr),
23+
proxy_(proxy),
24+
data_(data, deleter) {}
25+
26+
CpuProfilerStor::~CpuProfilerStor() {
27+
// Don't try to access the profile if the Isolate it comes from is gone
28+
SharedEnvInst envinst = GetEnvInst(thread_id_);
29+
if (!envinst) {
30+
return;
31+
}
32+
33+
// Keep the Isolate alive while diposing the profiler and profile
34+
EnvInst::Scope scp(envinst);
35+
if (!scp.Success()) {
36+
return;
37+
}
38+
39+
if (profile_) {
40+
profile_->Delete();
41+
profile_ = nullptr;
42+
}
43+
44+
if (profiler_) {
45+
profiler_->Dispose();
46+
profiler_ = nullptr;
47+
}
48+
}
49+
1050
NSolidCpuProfiler::NSolidCpuProfiler(): dummy_stub_(nullptr, nullptr) {
1151
is_running = true;
1252
ASSERT_EQ(0, blocked_cpu_profilers_.init(true));

src/nsolid/nsolid_cpu_profiler.h

+29-44
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,44 @@
11
#ifndef SRC_NSOLID_NSOLID_CPU_PROFILER_H_
22
#define SRC_NSOLID_NSOLID_CPU_PROFILER_H_
33

4-
#include <nsolid/nsolid_api.h>
5-
#include <nsolid/nsolid_util.h>
6-
#include <v8.h>
7-
#include <v8-profiler.h>
8-
#include <tuple>
94
#include <map>
5+
#include "nsolid.h"
6+
#include "nsolid/nsolid_util.h"
7+
#include "nsuv-inl.h"
108

11-
#include "asserts-cpp/asserts.h"
9+
// pre-declarations.
10+
namespace v8 {
11+
class CpuProfiler;
12+
class CpuProfile;
13+
} // namespace v8
1214

1315
namespace node {
1416
namespace nsolid {
1517

16-
17-
class NSolidCpuProfiler {
18+
struct CpuProfilerStor {
1819
public:
19-
struct CpuProfilerStor {
20-
CpuProfilerStor(uint64_t timeout,
21-
const std::string& title,
22-
void* data,
23-
CpuProfiler::cpu_profiler_proxy_sig proxy,
24-
internal::deleter_sig deleter):
25-
status_(0),
26-
timeout_(timeout),
27-
title_(title),
28-
profiler_(nullptr),
29-
profile_(nullptr),
30-
proxy_(proxy),
31-
data_(data, deleter) {
32-
}
33-
34-
~CpuProfilerStor() {
35-
if (profile_) {
36-
profile_->Delete();
37-
profile_ = nullptr;
38-
}
39-
40-
if (profiler_) {
41-
profiler_->Dispose();
42-
profiler_ = nullptr;
43-
}
44-
}
45-
46-
int status_;
47-
uint64_t timeout_;
48-
std::string title_;
49-
v8::CpuProfiler* profiler_;
50-
v8::CpuProfile* profile_;
51-
CpuProfiler::cpu_profiler_proxy_sig proxy_;
52-
internal::user_data data_;
53-
};
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();
5428

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+
};
5539

40+
class NSolidCpuProfiler {
41+
public:
5642
static NSolidCpuProfiler* Inst();
5743

5844
int TakeCpuProfile(SharedEnvInst envinst,
@@ -99,7 +85,6 @@ class NSolidCpuProfiler {
9985
~NSolidCpuProfiler();
10086
};
10187

102-
10388
} // namespace nsolid
10489
} // namespace node
10590

0 commit comments

Comments
 (0)