@datadog/pprof 0.5.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/out/src/cpu-profiler-bindings.js +1 -1
  2. package/out/src/cpu-profiler-bindings.js.map +1 -1
  3. package/out/src/cpu-profiler.js +1 -1
  4. package/out/src/cpu-profiler.js.map +1 -1
  5. package/out/src/heap-profiler.js +4 -4
  6. package/out/src/heap-profiler.js.map +1 -1
  7. package/out/src/index.js +2 -2
  8. package/out/src/index.js.map +1 -1
  9. package/out/src/profile-encoder.js +1 -1
  10. package/out/src/profile-encoder.js.map +1 -1
  11. package/out/src/time-profiler-bindings.js +1 -1
  12. package/out/src/time-profiler-bindings.js.map +1 -1
  13. package/out/src/time-profiler.js +3 -3
  14. package/out/src/time-profiler.js.map +1 -1
  15. package/out/third_party/cloud-debug-nodejs/src/agent/io/scanner.js.map +1 -1
  16. package/package.json +15 -18
  17. package/prebuilds/darwin-arm64/node-102.node +0 -0
  18. package/prebuilds/darwin-arm64/node-108.node +0 -0
  19. package/prebuilds/darwin-arm64/node-72.node +0 -0
  20. package/prebuilds/darwin-arm64/node-79.node +0 -0
  21. package/prebuilds/darwin-arm64/node-83.node +0 -0
  22. package/prebuilds/darwin-arm64/node-88.node +0 -0
  23. package/prebuilds/darwin-arm64/node-93.node +0 -0
  24. package/prebuilds/darwin-ia32/node-102.node +0 -0
  25. package/prebuilds/darwin-ia32/node-108.node +0 -0
  26. package/prebuilds/darwin-ia32/node-72.node +0 -0
  27. package/prebuilds/darwin-ia32/node-79.node +0 -0
  28. package/prebuilds/darwin-ia32/node-83.node +0 -0
  29. package/prebuilds/darwin-ia32/node-88.node +0 -0
  30. package/prebuilds/darwin-ia32/node-93.node +0 -0
  31. package/prebuilds/darwin-x64/node-102.node +0 -0
  32. package/prebuilds/darwin-x64/node-108.node +0 -0
  33. package/prebuilds/darwin-x64/node-72.node +0 -0
  34. package/prebuilds/darwin-x64/node-79.node +0 -0
  35. package/prebuilds/darwin-x64/node-83.node +0 -0
  36. package/prebuilds/darwin-x64/node-88.node +0 -0
  37. package/prebuilds/darwin-x64/node-93.node +0 -0
  38. package/prebuilds/linux-ia32/node-72.node +0 -0
  39. package/prebuilds/linux-ia32/node-79.node +0 -0
  40. package/prebuilds/linux-x64/node-102.node +0 -0
  41. package/prebuilds/linux-x64/node-108.node +0 -0
  42. package/prebuilds/linux-x64/node-72.node +0 -0
  43. package/prebuilds/linux-x64/node-79.node +0 -0
  44. package/prebuilds/linux-x64/node-83.node +0 -0
  45. package/prebuilds/linux-x64/node-88.node +0 -0
  46. package/prebuilds/linux-x64/node-93.node +0 -0
  47. package/prebuilds/win32-ia32/node-102.node +0 -0
  48. package/prebuilds/win32-ia32/node-72.node +0 -0
  49. package/prebuilds/win32-ia32/node-79.node +0 -0
  50. package/prebuilds/win32-ia32/node-83.node +0 -0
  51. package/prebuilds/win32-ia32/node-88.node +0 -0
  52. package/prebuilds/win32-ia32/node-93.node +0 -0
  53. package/prebuilds/win32-x64/node-102.node +0 -0
  54. package/prebuilds/win32-x64/node-108.node +0 -0
  55. package/prebuilds/win32-x64/node-72.node +0 -0
  56. package/prebuilds/win32-x64/node-79.node +0 -0
  57. package/prebuilds/win32-x64/node-83.node +0 -0
  58. package/prebuilds/win32-x64/node-88.node +0 -0
  59. package/prebuilds/win32-x64/node-93.node +0 -0
  60. package/binding.gyp +0 -136
  61. package/bindings/binding.cc +0 -13
  62. package/bindings/code-event-record.cc +0 -115
  63. package/bindings/code-event-record.hh +0 -67
  64. package/bindings/code-map.cc +0 -112
  65. package/bindings/code-map.hh +0 -47
  66. package/bindings/cpu-time.cc +0 -89
  67. package/bindings/cpu-time.hh +0 -35
  68. package/bindings/location.cc +0 -117
  69. package/bindings/location.hh +0 -43
  70. package/bindings/per-isolate-data.cc +0 -42
  71. package/bindings/per-isolate-data.hh +0 -26
  72. package/bindings/profilers/cpu.cc +0 -285
  73. package/bindings/profilers/cpu.hh +0 -78
  74. package/bindings/profilers/heap.cc +0 -112
  75. package/bindings/profilers/heap.hh +0 -40
  76. package/bindings/profilers/wall.cc +0 -306
  77. package/bindings/profilers/wall.hh +0 -28
  78. package/bindings/sample.cc +0 -160
  79. package/bindings/sample.hh +0 -48
  80. package/bindings/test/binding.cc +0 -59
  81. package/bindings/test/code-event-record.test.cc +0 -81
  82. package/bindings/test/code-event-record.test.hh +0 -5
  83. package/bindings/test/code-map.test.cc +0 -77
  84. package/bindings/test/code-map.test.hh +0 -5
  85. package/bindings/test/cpu-time.test.cc +0 -30
  86. package/bindings/test/cpu-time.test.hh +0 -5
  87. package/bindings/test/location.test.cc +0 -39
  88. package/bindings/test/location.test.hh +0 -5
  89. package/bindings/test/profilers/cpu.test.cc +0 -88
  90. package/bindings/test/profilers/cpu.test.hh +0 -5
  91. package/bindings/test/sample.test.cc +0 -128
  92. package/bindings/test/sample.test.hh +0 -5
  93. package/bindings/test/tap.h +0 -830
  94. package/bindings/wrap.hh +0 -20
  95. package/prebuilds/linux-arm/node-102.node +0 -0
  96. package/prebuilds/linux-arm/node-108.node +0 -0
  97. package/prebuilds/linux-arm/node-72.node +0 -0
  98. package/prebuilds/linux-arm/node-79.node +0 -0
  99. package/prebuilds/linux-arm/node-83.node +0 -0
  100. package/prebuilds/linux-arm/node-88.node +0 -0
  101. package/prebuilds/linux-arm/node-93.node +0 -0
  102. package/prebuilds/linux-arm64/node-102.node +0 -0
  103. package/prebuilds/linux-arm64/node-108.node +0 -0
  104. package/prebuilds/linux-arm64/node-72.node +0 -0
  105. package/prebuilds/linux-arm64/node-79.node +0 -0
  106. package/prebuilds/linux-arm64/node-83.node +0 -0
  107. package/prebuilds/linux-arm64/node-88.node +0 -0
  108. package/prebuilds/linux-arm64/node-93.node +0 -0
  109. package/scripts/should_rebuild.js +0 -8
@@ -1,285 +0,0 @@
1
- #include <queue>
2
-
3
- #include <v8-profiler.h>
4
- #include <v8.h>
5
- #include <node.h>
6
- #include <uv.h>
7
-
8
- #include "../per-isolate-data.hh"
9
- #include "../location.hh"
10
- #include "cpu.hh"
11
-
12
- namespace dd {
13
-
14
- CpuProfiler::CpuProfiler()
15
- : isolate_(v8::Isolate::GetCurrent()),
16
- async(new uv_async_t()),
17
- code_map(CodeMap::For(isolate_)),
18
- samples(Nan::New<v8::Array>()),
19
- sampler_running(false) {
20
- // TODO: Move symbolizer worker to a separate class?
21
- // Initialize libuv async worker to process samples when JS thread is idle
22
- uv_async_init(Nan::GetCurrentEventLoop(), async, Run);
23
- // Unref the async worker so it won't hold the loop open when there are no
24
- // other tasks. This allows it to clean itself up automatically.
25
- uv_unref(reinterpret_cast<uv_handle_t*>(async));
26
- // The async worker needs a reference to the profiler instance so it can get
27
- // the pending sample and the vector to push symbolized samples to.
28
- async->data = static_cast<void*>(this);
29
- uv_sem_init(&sampler_thread_done, 1);
30
- }
31
-
32
- CpuProfiler::~CpuProfiler() {
33
- uv_close(reinterpret_cast<uv_handle_t*>(async),
34
- [](uv_handle_t* handle){
35
- delete reinterpret_cast<uv_handle_t*>(handle);
36
- });
37
- Stop();
38
-
39
- uv_sem_wait(&sampler_thread_done);
40
- uv_sem_destroy(&sampler_thread_done);
41
- }
42
-
43
- CpuProfiler* CpuProfiler::New() {
44
- auto isolate = v8::Isolate::GetCurrent();
45
- auto per_isolate = PerIsolateData::For(isolate);
46
- v8::Local<v8::Function> cons = Nan::New(
47
- per_isolate->CpuProfilerConstructor());
48
- auto inst = Nan::NewInstance(cons, 0, {}).ToLocalChecked();
49
- return Nan::ObjectWrap::Unwrap<CpuProfiler>(inst);
50
- }
51
-
52
- v8::Local<v8::Number> CpuProfiler::GetFrequency() {
53
- return Nan::New<v8::Number>(frequency);
54
- }
55
-
56
- // NOTE: last sample must be a unique_ptr to ensure it is cleaned up
57
- // when no longer referenced. However when `ProcessSample()` is called
58
- // it will be released from the unique_ptr as it will become owned by
59
- // the JavaScript thread which creates a corresponding handle object,
60
- // making it garbage-collectable.
61
- void CpuProfiler::SetLastSample(std::unique_ptr<Sample> sample) {
62
- lastSample = std::move(sample);
63
- }
64
-
65
- // NOTE: For test/debug purposes only
66
- Sample* CpuProfiler::GetLastSample() {
67
- return lastSample.get();
68
- }
69
-
70
- void CpuProfiler::CaptureSample(v8::Isolate* isolate) {
71
- const std::lock_guard<std::mutex> lock(mutex);
72
- auto diff = cpu_time.Diff();
73
- SetLastSample(
74
- std::make_unique<Sample>(isolate, labels_, diff));
75
- }
76
-
77
- // TODO: Make sampler thread a separate class?
78
- void CpuProfiler::SamplerThread(double hz) {
79
- using hrc = std::chrono::high_resolution_clock;
80
- std::chrono::duration<double> interval(1.0 / hz);
81
- while (sampler_running) {
82
- isolate_->RequestInterrupt([](v8::Isolate* isolate, void* data) {
83
- auto profiler = static_cast<CpuProfiler*>(data);
84
- profiler->CaptureSample(isolate);
85
-
86
- // Notify symbolizer worker that we have a new sample
87
- uv_async_send(profiler->async);
88
- }, this);
89
-
90
- std::this_thread::sleep_for(interval);
91
- }
92
- uv_sem_post(&sampler_thread_done);
93
- }
94
-
95
- void CpuProfiler::ProcessSample() {
96
- v8::HandleScope scope(isolate_);
97
-
98
- Sample* sample;
99
- {
100
- const std::lock_guard<std::mutex> lock(mutex);
101
- sample = lastSample.release();
102
- }
103
-
104
- if (!sample) return;
105
- if (!sample->Symbolize(code_map)->Length()) {
106
- delete sample;
107
- return;
108
- }
109
-
110
- // Append the newly processed sample to the samples array
111
- auto arr = samples.Get(isolate_);
112
- arr->Set(isolate_->GetCurrentContext(), arr->Length(),
113
- sample->ToObject(isolate_)).Check();
114
- }
115
-
116
- void CpuProfiler::Run(uv_async_t* handle) {
117
- auto profiler = static_cast<CpuProfiler*>(handle->data);
118
- profiler->ProcessSample();
119
- }
120
-
121
- void CpuProfiler::Start(double hz) {
122
- if (sampler_running) return;
123
-
124
- frequency = hz;
125
- sampler_running = true;
126
- uv_sem_init(&sampler_thread_done, 0);
127
- uv_thread_create(&sampler_thread, [](void* arg) {
128
- auto profiler = static_cast<CpuProfiler*>(arg);
129
- profiler->SamplerThread(profiler->frequency);
130
- }, this);
131
- start_time = uv_hrtime();
132
- code_map->Enable();
133
- }
134
-
135
- void CpuProfiler::Stop() {
136
- if (!sampler_running) return;
137
-
138
- frequency = 0;
139
- sampler_running = false;
140
- code_map->Disable();
141
- }
142
-
143
- v8::Local<v8::Value> CpuProfiler::GetLabels() {
144
- const std::lock_guard<std::mutex> lock(mutex);
145
- if (!labels_) return Nan::Undefined();
146
- return labels_->handle();
147
- }
148
-
149
- void CpuProfiler::SetLabels(v8::Local<v8::Value> value) {
150
- const std::lock_guard<std::mutex> lock(mutex);
151
- labels_ = std::make_shared<LabelWrap>(value);
152
- }
153
-
154
- uint32_t CpuProfiler::GetSampleCount() {
155
- return samples.Get(isolate_)->Length();
156
- }
157
-
158
- // TODO: Probably should make an explicit clear method rather than
159
- // implicitly clearing whenever getting the samples array
160
- v8::Local<v8::Array> CpuProfiler::GetSamples() {
161
- auto array = samples.Get(isolate_);
162
- samples.Reset(Nan::New<v8::Array>());
163
- return array;
164
- }
165
-
166
- v8::Local<v8::Value> CpuProfiler::GetProfile() {
167
- auto profile = Nan::New<v8::Object>();
168
- auto end_time = uv_hrtime();
169
-
170
- Nan::Set(profile,
171
- Nan::New("name").ToLocalChecked(),
172
- Nan::New("(root)").ToLocalChecked()).Check();
173
- Nan::Set(profile,
174
- Nan::New("startTime").ToLocalChecked(),
175
- v8::BigInt::New(isolate_, start_time)).Check();
176
- Nan::Set(profile,
177
- Nan::New("endTime").ToLocalChecked(),
178
- v8::BigInt::New(isolate_, end_time)).Check();
179
- Nan::Set(profile,
180
- Nan::New("samples").ToLocalChecked(),
181
- GetSamples()).Check();
182
-
183
- start_time = end_time;
184
-
185
- return profile;
186
- }
187
-
188
- NAN_METHOD(CpuProfiler::New) {
189
- if (info.IsConstructCall()) {
190
- CpuProfiler* profiler = new CpuProfiler();
191
- profiler->Wrap(info.This());
192
- info.GetReturnValue().Set(info.This());
193
- } else {
194
- auto per_isolate = PerIsolateData::For(info.GetIsolate());
195
- v8::Local<v8::Function> cons = Nan::New(
196
- per_isolate->CpuProfilerConstructor());
197
- info.GetReturnValue().Set(Nan::NewInstance(cons, 0, {}).ToLocalChecked());
198
- }
199
- }
200
-
201
- NAN_GETTER(CpuProfiler::GetFrequency) {
202
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
203
- info.GetReturnValue().Set(profiler->GetFrequency());
204
- }
205
-
206
- NAN_METHOD(CpuProfiler::Start) {
207
- if (!info[0]->IsNumber()) {
208
- Nan::ThrowTypeError("hz is not a number");
209
- return;
210
- }
211
-
212
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
213
- profiler->Start(Nan::To<double>(info[0]).FromJust());
214
- }
215
-
216
- NAN_METHOD(CpuProfiler::Stop) {
217
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
218
- profiler->Stop();
219
- }
220
-
221
- NAN_METHOD(CpuProfiler::CaptureSample) {
222
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
223
- profiler->CaptureSample(info.GetIsolate());
224
- }
225
-
226
- NAN_METHOD(CpuProfiler::ProcessSample) {
227
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
228
- profiler->ProcessSample();
229
- }
230
-
231
- NAN_GETTER(CpuProfiler::GetLabels) {
232
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
233
- info.GetReturnValue().Set(profiler->GetLabels());
234
- }
235
-
236
- NAN_SETTER(CpuProfiler::SetLabels) {
237
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
238
- profiler->SetLabels(value);
239
- }
240
-
241
- NAN_METHOD(CpuProfiler::GetSamples) {
242
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
243
- info.GetReturnValue().Set(profiler->GetSamples());
244
- }
245
-
246
- NAN_METHOD(CpuProfiler::GetProfile) {
247
- auto profiler = Nan::ObjectWrap::Unwrap<CpuProfiler>(info.Holder());
248
- info.GetReturnValue().Set(profiler->GetProfile());
249
- }
250
-
251
- NAN_MODULE_INIT(CpuProfiler::Init) {
252
- Location::Init(target);
253
- Sample::Init(target);
254
-
255
- auto class_name = Nan::New<v8::String>("CpuProfiler")
256
- .ToLocalChecked();
257
-
258
- auto tpl = Nan::New<v8::FunctionTemplate>(New);
259
- tpl->SetClassName(class_name);
260
- tpl->InstanceTemplate()
261
- ->SetInternalFieldCount(1);
262
-
263
- auto inst = tpl->InstanceTemplate();
264
- Nan::SetAccessor(inst,
265
- Nan::New("labels").ToLocalChecked(),
266
- GetLabels, SetLabels);
267
-
268
- Nan::SetAccessor(inst,
269
- Nan::New("frequency").ToLocalChecked(),
270
- GetFrequency);
271
-
272
- Nan::SetPrototypeMethod(tpl, "start", Start);
273
- Nan::SetPrototypeMethod(tpl, "stop", Stop);
274
- Nan::SetPrototypeMethod(tpl, "captureSample", CaptureSample);
275
- Nan::SetPrototypeMethod(tpl, "processSample", ProcessSample);
276
- Nan::SetPrototypeMethod(tpl, "samples", GetSamples);
277
- Nan::SetPrototypeMethod(tpl, "profile", GetProfile);
278
-
279
- auto fn = Nan::GetFunction(tpl).ToLocalChecked();
280
- Nan::Set(target, class_name, fn);
281
- auto per_isolate = PerIsolateData::For(target->GetIsolate());
282
- per_isolate->CpuProfilerConstructor().Reset(fn);
283
- }
284
-
285
- } // namespace dd
@@ -1,78 +0,0 @@
1
- #pragma once
2
-
3
- #include <atomic>
4
- #include <mutex>
5
- #include <thread>
6
- #include <chrono>
7
-
8
- #include <nan.h>
9
-
10
- #include "../code-map.hh"
11
- #include "../cpu-time.hh"
12
- #include "../sample.hh"
13
- #include "../wrap.hh"
14
-
15
- namespace dd {
16
-
17
- class CpuProfiler : public Nan::ObjectWrap {
18
- friend class CodeMap;
19
-
20
- private:
21
- v8::Isolate* isolate_;
22
- uv_async_t* async;
23
- std::shared_ptr<CodeMap> code_map;
24
- CpuTime cpu_time;
25
- std::unique_ptr<Sample> lastSample;
26
- std::shared_ptr<LabelWrap> labels_;
27
- double frequency = 0;
28
- Nan::Global<v8::Array> samples;
29
- std::mutex mutex;
30
- uint64_t start_time;
31
- uv_sem_t sampler_thread_done;
32
- uv_thread_t sampler_thread;
33
- std::atomic_bool sampler_running;
34
-
35
- public:
36
- CpuProfiler();
37
- ~CpuProfiler();
38
- static CpuProfiler* New();
39
-
40
- // Disable copies and moves
41
- CpuProfiler(const CpuProfiler& other) = delete;
42
- CpuProfiler(CpuProfiler&& other) = delete;
43
- CpuProfiler& operator=(const CpuProfiler& other) = delete;
44
- CpuProfiler& operator=(CpuProfiler&& other) = delete;
45
-
46
- v8::Local<v8::Number> GetFrequency();
47
-
48
- void SetLastSample(std::unique_ptr<Sample> sample);
49
- Sample* GetLastSample();
50
- void CaptureSample(v8::Isolate* isolate);
51
- void SamplerThread(double hz);
52
-
53
- void ProcessSample();
54
- static void Run(uv_async_t* handle);
55
-
56
- v8::Local<v8::Value> GetLabels();
57
- void SetLabels(v8::Local<v8::Value>);
58
- void Start(double hz);
59
- void Stop();
60
- uint32_t GetSampleCount();
61
- v8::Local<v8::Array> GetSamples();
62
- v8::Local<v8::Value> GetProfile();
63
-
64
- static NAN_METHOD(New);
65
- static NAN_GETTER(GetFrequency);
66
- static NAN_GETTER(GetLabels);
67
- static NAN_SETTER(SetLabels);
68
- static NAN_METHOD(Start);
69
- static NAN_METHOD(Stop);
70
- static NAN_METHOD(CaptureSample);
71
- static NAN_METHOD(ProcessSample);
72
- static NAN_METHOD(GetSamples);
73
- static NAN_METHOD(GetProfile);
74
-
75
- static NAN_MODULE_INIT(Init);
76
- };
77
-
78
- } // namespace dd
@@ -1,112 +0,0 @@
1
- /**
2
- * Copyright 2018 Google Inc. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- #include "heap.hh"
18
-
19
- #include <memory>
20
-
21
- #include <node.h>
22
- #include <v8-profiler.h>
23
-
24
- using namespace v8;
25
-
26
- namespace dd {
27
-
28
- Local<Value> TranslateAllocationProfile(AllocationProfile::Node* node) {
29
- Local<Object> js_node = Nan::New<Object>();
30
-
31
- Nan::Set(js_node, Nan::New<String>("name").ToLocalChecked(), node->name);
32
- Nan::Set(js_node, Nan::New<String>("scriptName").ToLocalChecked(),
33
- node->script_name);
34
- Nan::Set(js_node, Nan::New<String>("scriptId").ToLocalChecked(),
35
- Nan::New<Integer>(node->script_id));
36
- Nan::Set(js_node, Nan::New<String>("lineNumber").ToLocalChecked(),
37
- Nan::New<Integer>(node->line_number));
38
- Nan::Set(js_node, Nan::New<String>("columnNumber").ToLocalChecked(),
39
- Nan::New<Integer>(node->column_number));
40
-
41
- Local<Array> children = Nan::New<Array>(node->children.size());
42
- for (size_t i = 0; i < node->children.size(); i++) {
43
- Nan::Set(children, i, TranslateAllocationProfile(node->children[i]));
44
- }
45
- Nan::Set(js_node, Nan::New<String>("children").ToLocalChecked(), children);
46
- Local<Array> allocations = Nan::New<Array>(node->allocations.size());
47
- for (size_t i = 0; i < node->allocations.size(); i++) {
48
- AllocationProfile::Allocation alloc = node->allocations[i];
49
- Local<Object> js_alloc = Nan::New<Object>();
50
- Nan::Set(js_alloc, Nan::New<String>("sizeBytes").ToLocalChecked(),
51
- Nan::New<Number>(alloc.size));
52
- Nan::Set(js_alloc, Nan::New<String>("count").ToLocalChecked(),
53
- Nan::New<Number>(alloc.count));
54
- Nan::Set(allocations, i, js_alloc);
55
- }
56
- Nan::Set(js_node, Nan::New<String>("allocations").ToLocalChecked(),
57
- allocations);
58
- return js_node;
59
- }
60
-
61
- NAN_METHOD(HeapProfiler::StartSamplingHeapProfiler) {
62
- if (info.Length() == 2) {
63
- if (!info[0]->IsUint32()) {
64
- return Nan::ThrowTypeError("First argument type must be uint32.");
65
- }
66
- if (!info[1]->IsNumber()) {
67
- return Nan::ThrowTypeError("First argument type must be Integer.");
68
- }
69
-
70
- #if NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION
71
- uint64_t sample_interval = info[0].As<Integer>()->Value();
72
- int stack_depth = info[1].As<Integer>()->Value();
73
- #else
74
- uint64_t sample_interval = info[0].As<Integer>()->Uint32Value();
75
- int stack_depth = info[1].As<Integer>()->IntegerValue();
76
- #endif
77
-
78
- info.GetIsolate()->GetHeapProfiler()->StartSamplingHeapProfiler(
79
- sample_interval, stack_depth);
80
- } else {
81
- info.GetIsolate()->GetHeapProfiler()->StartSamplingHeapProfiler();
82
- }
83
- }
84
-
85
- // Signature:
86
- // stopSamplingHeapProfiler()
87
- NAN_METHOD(HeapProfiler::StopSamplingHeapProfiler) {
88
- info.GetIsolate()->GetHeapProfiler()->StopSamplingHeapProfiler();
89
- }
90
-
91
- // Signature:
92
- // getAllocationProfile(): AllocationProfileNode
93
- NAN_METHOD(HeapProfiler::GetAllocationProfile) {
94
- std::unique_ptr<v8::AllocationProfile> profile(
95
- info.GetIsolate()->GetHeapProfiler()->GetAllocationProfile());
96
- AllocationProfile::Node* root = profile->GetRootNode();
97
- info.GetReturnValue().Set(TranslateAllocationProfile(root));
98
- }
99
-
100
- NAN_MODULE_INIT(HeapProfiler::Init) {
101
- v8::Local<v8::Object> heapProfiler = Nan::New<v8::Object>();
102
- Nan::SetMethod(heapProfiler, "startSamplingHeapProfiler",
103
- StartSamplingHeapProfiler);
104
- Nan::SetMethod(heapProfiler, "stopSamplingHeapProfiler",
105
- StopSamplingHeapProfiler);
106
- Nan::SetMethod(heapProfiler, "getAllocationProfile",
107
- GetAllocationProfile);
108
- Nan::Set(target, Nan::New<v8::String>("heapProfiler").ToLocalChecked(),
109
- heapProfiler);
110
- }
111
-
112
- } // namespace dd
@@ -1,40 +0,0 @@
1
- /**
2
- * Copyright 2018 Google Inc. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- #pragma once
18
-
19
- #include <nan.h>
20
-
21
- namespace dd {
22
-
23
- class HeapProfiler {
24
- public:
25
- // Signature:
26
- // startSamplingHeapProfiler()
27
- static NAN_METHOD(StartSamplingHeapProfiler);
28
-
29
- // Signature:
30
- // stopSamplingHeapProfiler()
31
- static NAN_METHOD(StopSamplingHeapProfiler);
32
-
33
- // Signature:
34
- // getAllocationProfile(): AllocationProfileNode
35
- static NAN_METHOD(GetAllocationProfile);
36
-
37
- static NAN_MODULE_INIT(Init);
38
- };
39
-
40
- } // namespace dd