Skip to content

Commit 6e37c40

Browse files
committed
src: move CpuProfilerStor impl to cc file
PR-URL: #18 Reviewed-by: Trevor Norris <[email protected]>
1 parent 877b3a3 commit 6e37c40

File tree

2 files changed

+71
-61
lines changed

2 files changed

+71
-61
lines changed

src/nsolid/nsolid_cpu_profiler.cc

Lines changed: 42 additions & 2 deletions
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

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +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 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();
6928

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

40+
class NSolidCpuProfiler {
41+
public:
7142
static NSolidCpuProfiler* Inst();
7243

7344
int TakeCpuProfile(SharedEnvInst envinst,
@@ -114,7 +85,6 @@ class NSolidCpuProfiler {
11485
~NSolidCpuProfiler();
11586
};
11687

117-
11888
} // namespace nsolid
11989
} // namespace node
12090

0 commit comments

Comments
 (0)