@datadog/pprof 0.3.0 → 0.5.1

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 (118) hide show
  1. package/binding.gyp +130 -31
  2. package/bindings/binding.cc +13 -0
  3. package/bindings/code-event-record.cc +115 -0
  4. package/bindings/code-event-record.hh +67 -0
  5. package/bindings/code-map.cc +112 -0
  6. package/bindings/code-map.hh +47 -0
  7. package/bindings/cpu-time.cc +89 -0
  8. package/bindings/cpu-time.hh +35 -0
  9. package/bindings/location.cc +117 -0
  10. package/bindings/location.hh +43 -0
  11. package/bindings/per-isolate-data.cc +42 -0
  12. package/bindings/per-isolate-data.hh +26 -0
  13. package/bindings/profilers/cpu.cc +285 -0
  14. package/bindings/profilers/cpu.hh +78 -0
  15. package/bindings/profilers/heap.cc +112 -0
  16. package/bindings/profilers/heap.hh +40 -0
  17. package/bindings/profilers/wall.cc +306 -0
  18. package/bindings/profilers/wall.hh +28 -0
  19. package/bindings/sample.cc +160 -0
  20. package/bindings/sample.hh +48 -0
  21. package/bindings/test/binding.cc +59 -0
  22. package/bindings/test/code-event-record.test.cc +81 -0
  23. package/bindings/test/code-event-record.test.hh +5 -0
  24. package/bindings/test/code-map.test.cc +77 -0
  25. package/bindings/test/code-map.test.hh +5 -0
  26. package/bindings/test/cpu-time.test.cc +30 -0
  27. package/bindings/test/cpu-time.test.hh +5 -0
  28. package/bindings/test/location.test.cc +39 -0
  29. package/bindings/test/location.test.hh +5 -0
  30. package/bindings/test/profilers/cpu.test.cc +88 -0
  31. package/bindings/test/profilers/cpu.test.hh +5 -0
  32. package/bindings/test/sample.test.cc +128 -0
  33. package/bindings/test/sample.test.hh +5 -0
  34. package/bindings/test/tap.h +830 -0
  35. package/bindings/wrap.hh +20 -0
  36. package/out/src/cpu-profiler-bindings.d.ts +1 -0
  37. package/out/src/cpu-profiler-bindings.js +23 -0
  38. package/out/src/cpu-profiler-bindings.js.map +1 -0
  39. package/out/src/cpu-profiler.d.ts +19 -0
  40. package/out/src/cpu-profiler.js +94 -0
  41. package/out/src/cpu-profiler.js.map +1 -0
  42. package/out/src/index.d.ts +2 -0
  43. package/out/src/index.js +3 -1
  44. package/out/src/index.js.map +1 -1
  45. package/out/src/profile-encoder.js +3 -14
  46. package/out/src/profile-encoder.js.map +1 -1
  47. package/out/src/profile-serializer.d.ts +9 -1
  48. package/out/src/profile-serializer.js +73 -1
  49. package/out/src/profile-serializer.js.map +1 -1
  50. package/out/src/sourcemapper/sourcemapper.js +81 -88
  51. package/out/src/sourcemapper/sourcemapper.js.map +1 -1
  52. package/out/src/time-profiler.js +4 -15
  53. package/out/src/time-profiler.js.map +1 -1
  54. package/out/src/v8-types.d.ts +38 -0
  55. package/out/third_party/cloud-debug-nodejs/src/agent/io/scanner.js +6 -17
  56. package/out/third_party/cloud-debug-nodejs/src/agent/io/scanner.js.map +1 -1
  57. package/package.json +12 -14
  58. package/prebuilds/darwin-arm64/node-102.node +0 -0
  59. package/prebuilds/darwin-arm64/node-108.node +0 -0
  60. package/prebuilds/darwin-arm64/node-72.node +0 -0
  61. package/prebuilds/darwin-arm64/node-79.node +0 -0
  62. package/prebuilds/darwin-arm64/node-83.node +0 -0
  63. package/prebuilds/darwin-arm64/node-88.node +0 -0
  64. package/prebuilds/darwin-arm64/node-93.node +0 -0
  65. package/prebuilds/darwin-ia32/node-102.node +0 -0
  66. package/prebuilds/darwin-ia32/node-108.node +0 -0
  67. package/prebuilds/darwin-ia32/node-72.node +0 -0
  68. package/prebuilds/darwin-ia32/node-79.node +0 -0
  69. package/prebuilds/darwin-ia32/node-83.node +0 -0
  70. package/prebuilds/darwin-ia32/node-88.node +0 -0
  71. package/prebuilds/darwin-ia32/node-93.node +0 -0
  72. package/prebuilds/darwin-x64/node-102.node +0 -0
  73. package/prebuilds/darwin-x64/node-108.node +0 -0
  74. package/prebuilds/darwin-x64/node-72.node +0 -0
  75. package/prebuilds/darwin-x64/node-79.node +0 -0
  76. package/prebuilds/darwin-x64/node-83.node +0 -0
  77. package/prebuilds/darwin-x64/node-88.node +0 -0
  78. package/prebuilds/darwin-x64/node-93.node +0 -0
  79. package/prebuilds/linux-arm/node-102.node +0 -0
  80. package/prebuilds/linux-arm/node-108.node +0 -0
  81. package/prebuilds/linux-arm/node-72.node +0 -0
  82. package/prebuilds/linux-arm/node-79.node +0 -0
  83. package/prebuilds/linux-arm/node-83.node +0 -0
  84. package/prebuilds/linux-arm/node-88.node +0 -0
  85. package/prebuilds/linux-arm/node-93.node +0 -0
  86. package/prebuilds/linux-arm64/node-102.node +0 -0
  87. package/prebuilds/linux-arm64/node-108.node +0 -0
  88. package/prebuilds/linux-arm64/node-72.node +0 -0
  89. package/prebuilds/linux-arm64/node-79.node +0 -0
  90. package/prebuilds/linux-arm64/node-83.node +0 -0
  91. package/prebuilds/linux-arm64/node-88.node +0 -0
  92. package/prebuilds/linux-arm64/node-93.node +0 -0
  93. package/prebuilds/linux-ia32/node-72.node +0 -0
  94. package/prebuilds/linux-ia32/node-79.node +0 -0
  95. package/prebuilds/linux-x64/node-102.node +0 -0
  96. package/prebuilds/linux-x64/node-108.node +0 -0
  97. package/prebuilds/linux-x64/node-72.node +0 -0
  98. package/prebuilds/linux-x64/node-79.node +0 -0
  99. package/prebuilds/linux-x64/node-83.node +0 -0
  100. package/prebuilds/linux-x64/node-88.node +0 -0
  101. package/prebuilds/linux-x64/node-93.node +0 -0
  102. package/prebuilds/win32-ia32/node-102.node +0 -0
  103. package/prebuilds/win32-ia32/node-72.node +0 -0
  104. package/prebuilds/win32-ia32/node-79.node +0 -0
  105. package/prebuilds/win32-ia32/node-83.node +0 -0
  106. package/prebuilds/win32-ia32/node-88.node +0 -0
  107. package/prebuilds/win32-ia32/node-93.node +0 -0
  108. package/prebuilds/win32-x64/node-102.node +0 -0
  109. package/prebuilds/win32-x64/node-108.node +0 -0
  110. package/prebuilds/win32-x64/node-72.node +0 -0
  111. package/prebuilds/win32-x64/node-79.node +0 -0
  112. package/prebuilds/win32-x64/node-83.node +0 -0
  113. package/prebuilds/win32-x64/node-88.node +0 -0
  114. package/prebuilds/win32-x64/node-93.node +0 -0
  115. package/scripts/require-package-json.js +11 -11
  116. package/scripts/should_rebuild.js +3 -3
  117. package/bindings/profiler.cc +0 -406
  118. package/scripts/preinstall.js +0 -36
@@ -1,406 +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 <memory>
18
-
19
- #include <node.h>
20
- #include "nan.h"
21
- #include "v8-profiler.h"
22
-
23
- using namespace v8;
24
-
25
- // Sampling Heap Profiler
26
-
27
- Local<Value> TranslateAllocationProfile(AllocationProfile::Node* node) {
28
- Local<Object> js_node = Nan::New<Object>();
29
-
30
- Nan::Set(js_node, Nan::New<String>("name").ToLocalChecked(), node->name);
31
- Nan::Set(js_node, Nan::New<String>("scriptName").ToLocalChecked(),
32
- node->script_name);
33
- Nan::Set(js_node, Nan::New<String>("scriptId").ToLocalChecked(),
34
- Nan::New<Integer>(node->script_id));
35
- Nan::Set(js_node, Nan::New<String>("lineNumber").ToLocalChecked(),
36
- Nan::New<Integer>(node->line_number));
37
- Nan::Set(js_node, Nan::New<String>("columnNumber").ToLocalChecked(),
38
- Nan::New<Integer>(node->column_number));
39
-
40
- Local<Array> children = Nan::New<Array>(node->children.size());
41
- for (size_t i = 0; i < node->children.size(); i++) {
42
- Nan::Set(children, i, TranslateAllocationProfile(node->children[i]));
43
- }
44
- Nan::Set(js_node, Nan::New<String>("children").ToLocalChecked(), children);
45
- Local<Array> allocations = Nan::New<Array>(node->allocations.size());
46
- for (size_t i = 0; i < node->allocations.size(); i++) {
47
- AllocationProfile::Allocation alloc = node->allocations[i];
48
- Local<Object> js_alloc = Nan::New<Object>();
49
- Nan::Set(js_alloc, Nan::New<String>("sizeBytes").ToLocalChecked(),
50
- Nan::New<Number>(alloc.size));
51
- Nan::Set(js_alloc, Nan::New<String>("count").ToLocalChecked(),
52
- Nan::New<Number>(alloc.count));
53
- Nan::Set(allocations, i, js_alloc);
54
- }
55
- Nan::Set(js_node, Nan::New<String>("allocations").ToLocalChecked(),
56
- allocations);
57
- return js_node;
58
- }
59
-
60
- NAN_METHOD(StartSamplingHeapProfiler) {
61
- if (info.Length() == 2) {
62
- if (!info[0]->IsUint32()) {
63
- return Nan::ThrowTypeError("First argument type must be uint32.");
64
- }
65
- if (!info[1]->IsNumber()) {
66
- return Nan::ThrowTypeError("First argument type must be Integer.");
67
- }
68
-
69
- #if NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION
70
- uint64_t sample_interval = info[0].As<Integer>()->Value();
71
- int stack_depth = info[1].As<Integer>()->Value();
72
- #else
73
- uint64_t sample_interval = info[0].As<Integer>()->Uint32Value();
74
- int stack_depth = info[1].As<Integer>()->IntegerValue();
75
- #endif
76
-
77
- info.GetIsolate()->GetHeapProfiler()->StartSamplingHeapProfiler(
78
- sample_interval, stack_depth);
79
- } else {
80
- info.GetIsolate()->GetHeapProfiler()->StartSamplingHeapProfiler();
81
- }
82
- }
83
-
84
- // Signature:
85
- // stopSamplingHeapProfiler()
86
- NAN_METHOD(StopSamplingHeapProfiler) {
87
- info.GetIsolate()->GetHeapProfiler()->StopSamplingHeapProfiler();
88
- }
89
-
90
- // Signature:
91
- // getAllocationProfile(): AllocationProfileNode
92
- NAN_METHOD(GetAllocationProfile) {
93
- std::unique_ptr<v8::AllocationProfile> profile(
94
- info.GetIsolate()->GetHeapProfiler()->GetAllocationProfile());
95
- AllocationProfile::Node* root = profile->GetRootNode();
96
- info.GetReturnValue().Set(TranslateAllocationProfile(root));
97
- }
98
-
99
- Local<Object> CreateTimeNode(Local<String> name, Local<String> scriptName,
100
- Local<Integer> scriptId, Local<Integer> lineNumber,
101
- Local<Integer> columnNumber,
102
- Local<Integer> hitCount, Local<Array> children) {
103
- Local<Object> js_node = Nan::New<Object>();
104
- Nan::Set(js_node, Nan::New<String>("name").ToLocalChecked(), name);
105
- Nan::Set(js_node, Nan::New<String>("scriptName").ToLocalChecked(),
106
- scriptName);
107
- Nan::Set(js_node, Nan::New<String>("scriptId").ToLocalChecked(), scriptId);
108
- Nan::Set(js_node, Nan::New<String>("lineNumber").ToLocalChecked(),
109
- lineNumber);
110
- Nan::Set(js_node, Nan::New<String>("columnNumber").ToLocalChecked(),
111
- columnNumber);
112
- Nan::Set(js_node, Nan::New<String>("hitCount").ToLocalChecked(), hitCount);
113
- Nan::Set(js_node, Nan::New<String>("children").ToLocalChecked(), children);
114
-
115
- return js_node;
116
- }
117
-
118
- Local<Object> TranslateLineNumbersTimeProfileNode(const CpuProfileNode* parent,
119
- const CpuProfileNode* node);
120
-
121
- Local<Array> GetLineNumberTimeProfileChildren(const CpuProfileNode* parent,
122
- const CpuProfileNode* node) {
123
- unsigned int index = 0;
124
- Local<Array> children;
125
- int32_t count = node->GetChildrenCount();
126
-
127
- unsigned int hitLineCount = node->GetHitLineCount();
128
- unsigned int hitCount = node->GetHitCount();
129
- if (hitLineCount > 0) {
130
- std::vector<CpuProfileNode::LineTick> entries(hitLineCount);
131
- node->GetLineTicks(&entries[0], hitLineCount);
132
- children = Nan::New<Array>(count + hitLineCount);
133
- for (const CpuProfileNode::LineTick entry : entries) {
134
- Nan::Set(children, index++,
135
- CreateTimeNode(
136
- node->GetFunctionName(), node->GetScriptResourceName(),
137
- Nan::New<Integer>(node->GetScriptId()),
138
- Nan::New<Integer>(entry.line), Nan::New<Integer>(0),
139
- Nan::New<Integer>(entry.hit_count), Nan::New<Array>(0)));
140
- }
141
- } else if (hitCount > 0) {
142
- // Handle nodes for pseudo-functions like "process" and "garbage collection"
143
- // which do not have hit line counts.
144
- children = Nan::New<Array>(count + 1);
145
- Nan::Set(
146
- children, index++,
147
- CreateTimeNode(node->GetFunctionName(), node->GetScriptResourceName(),
148
- Nan::New<Integer>(node->GetScriptId()),
149
- Nan::New<Integer>(node->GetLineNumber()),
150
- Nan::New<Integer>(node->GetColumnNumber()),
151
- Nan::New<Integer>(hitCount), Nan::New<Array>(0)));
152
- } else {
153
- children = Nan::New<Array>(count);
154
- }
155
-
156
- for (int32_t i = 0; i < count; i++) {
157
- Nan::Set(children, index++,
158
- TranslateLineNumbersTimeProfileNode(node, node->GetChild(i)));
159
- };
160
-
161
- return children;
162
- }
163
-
164
- Local<Object> TranslateLineNumbersTimeProfileNode(const CpuProfileNode* parent,
165
- const CpuProfileNode* node) {
166
- return CreateTimeNode(
167
- parent->GetFunctionName(), parent->GetScriptResourceName(),
168
- Nan::New<Integer>(parent->GetScriptId()),
169
- Nan::New<Integer>(node->GetLineNumber()),
170
- Nan::New<Integer>(node->GetColumnNumber()), Nan::New<Integer>(0),
171
- GetLineNumberTimeProfileChildren(parent, node));
172
- }
173
-
174
- // In profiles with line level accurate line numbers, a node's line number
175
- // and column number refer to the line/column from which the function was
176
- // called.
177
- Local<Value> TranslateLineNumbersTimeProfileRoot(const CpuProfileNode* node) {
178
- int32_t count = node->GetChildrenCount();
179
- std::vector<Local<Array>> childrenArrs(count);
180
- int32_t childCount = 0;
181
- for (int32_t i = 0; i < count; i++) {
182
- Local<Array> c = GetLineNumberTimeProfileChildren(node, node->GetChild(i));
183
- childCount = childCount + c->Length();
184
- childrenArrs[i] = c;
185
- }
186
-
187
- Local<Array> children = Nan::New<Array>(childCount);
188
- int32_t idx = 0;
189
- for (int32_t i = 0; i < count; i++) {
190
- Local<Array> arr = childrenArrs[i];
191
- for (uint32_t j = 0; j < arr->Length(); j++) {
192
- Nan::Set(children, idx, Nan::Get(arr, j).ToLocalChecked());
193
- idx++;
194
- }
195
- }
196
-
197
- return CreateTimeNode(node->GetFunctionName(), node->GetScriptResourceName(),
198
- Nan::New<Integer>(node->GetScriptId()),
199
- Nan::New<Integer>(node->GetLineNumber()),
200
- Nan::New<Integer>(node->GetColumnNumber()),
201
- Nan::New<Integer>(0), children);
202
- }
203
-
204
- Local<Value> TranslateTimeProfileNode(const CpuProfileNode* node) {
205
- int32_t count = node->GetChildrenCount();
206
- Local<Array> children = Nan::New<Array>(count);
207
- for (int32_t i = 0; i < count; i++) {
208
- Nan::Set(children, i, TranslateTimeProfileNode(node->GetChild(i)));
209
- }
210
-
211
- return CreateTimeNode(node->GetFunctionName(), node->GetScriptResourceName(),
212
- Nan::New<Integer>(node->GetScriptId()),
213
- Nan::New<Integer>(node->GetLineNumber()),
214
- Nan::New<Integer>(node->GetColumnNumber()),
215
- Nan::New<Integer>(node->GetHitCount()), children);
216
- }
217
-
218
- Local<Value> TranslateTimeProfile(const CpuProfile* profile,
219
- bool includeLineInfo) {
220
- Local<Object> js_profile = Nan::New<Object>();
221
- Nan::Set(js_profile, Nan::New<String>("title").ToLocalChecked(),
222
- profile->GetTitle());
223
-
224
- #if NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION
225
- if (includeLineInfo) {
226
- Nan::Set(js_profile, Nan::New<String>("topDownRoot").ToLocalChecked(),
227
- TranslateLineNumbersTimeProfileRoot(profile->GetTopDownRoot()));
228
- } else {
229
- Nan::Set(js_profile, Nan::New<String>("topDownRoot").ToLocalChecked(),
230
- TranslateTimeProfileNode(profile->GetTopDownRoot()));
231
- }
232
- #else
233
- Nan::Set(js_profile, Nan::New<String>("topDownRoot").ToLocalChecked(),
234
- TranslateTimeProfileNode(profile->GetTopDownRoot()));
235
- #endif
236
- Nan::Set(js_profile, Nan::New<String>("startTime").ToLocalChecked(),
237
- Nan::New<Number>(profile->GetStartTime()));
238
- Nan::Set(js_profile, Nan::New<String>("endTime").ToLocalChecked(),
239
- Nan::New<Number>(profile->GetEndTime()));
240
- return js_profile;
241
- }
242
-
243
- class TimeProfiler : public Nan::ObjectWrap {
244
- public:
245
- explicit TimeProfiler(int interval)
246
- : samplingInterval(interval) {}
247
-
248
- void Dispose() {
249
- if (cpuProfiler != nullptr) {
250
- cpuProfiler->Dispose();
251
- cpuProfiler = nullptr;
252
- }
253
- }
254
-
255
- static NAN_METHOD(Dispose) {
256
- TimeProfiler* timeProfiler =
257
- Nan::ObjectWrap::Unwrap<TimeProfiler>(info.Holder());
258
-
259
- timeProfiler->Dispose();
260
- }
261
-
262
- static NAN_METHOD(New) {
263
- if (info.Length() != 1) {
264
- return Nan::ThrowTypeError("TimeProfiler must have one argument.");
265
- }
266
- if (!info[0]->IsNumber()) {
267
- return Nan::ThrowTypeError("Sample rate must be a number.");
268
- }
269
-
270
- if (info.IsConstructCall()) {
271
- int interval =
272
- Nan::MaybeLocal<Integer>(info[0].As<Integer>()).ToLocalChecked()->Value();
273
-
274
- TimeProfiler* obj = new TimeProfiler(interval);
275
- obj->Wrap(info.This());
276
- info.GetReturnValue().Set(info.This());
277
- } else {
278
- const int argc = 1;
279
- v8::Local<v8::Value> argv[argc] = {info[0]};
280
- v8::Local<v8::Function> cons = Nan::New(constructor());
281
- info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
282
- }
283
- }
284
-
285
- void StartProfiling(Local<String> name, bool includeLines) {
286
- // Sample counts and timestamps are not used, so we do not need to record
287
- // samples.
288
- const bool recordSamples = false;
289
-
290
- if (includeLines) {
291
- GetProfiler()->StartProfiling(name, CpuProfilingMode::kCallerLineNumbers,
292
- recordSamples);
293
- } else {
294
- GetProfiler()->StartProfiling(name, recordSamples);
295
- }
296
- }
297
-
298
- static NAN_METHOD(Start) {
299
- TimeProfiler* timeProfiler =
300
- Nan::ObjectWrap::Unwrap<TimeProfiler>(info.Holder());
301
-
302
- if (info.Length() != 2) {
303
- return Nan::ThrowTypeError("Start must have two arguments.");
304
- }
305
- if (!info[0]->IsString()) {
306
- return Nan::ThrowTypeError("Profile name must be a string.");
307
- }
308
- if (!info[1]->IsBoolean()) {
309
- return Nan::ThrowTypeError("Include lines must be a boolean.");
310
- }
311
-
312
- Local<String> name =
313
- Nan::MaybeLocal<String>(info[0].As<String>()).ToLocalChecked();
314
-
315
- bool includeLines =
316
- Nan::MaybeLocal<Boolean>(info[1].As<Boolean>()).ToLocalChecked()->Value();
317
-
318
- timeProfiler->StartProfiling(name, includeLines);
319
- }
320
-
321
- Local<Value> StopProfiling(Local<String> name, bool includeLines) {
322
- CpuProfile* profile = GetProfiler()->StopProfiling(name);
323
- Local<Value> translated_profile =
324
- TranslateTimeProfile(profile, includeLines);
325
- profile->Delete();
326
- return translated_profile;
327
- }
328
-
329
- static NAN_METHOD(Stop) {
330
- TimeProfiler* timeProfiler =
331
- Nan::ObjectWrap::Unwrap<TimeProfiler>(info.Holder());
332
-
333
- if (info.Length() != 2) {
334
- return Nan::ThrowTypeError("Start must have two arguments.");
335
- }
336
- if (!info[0]->IsString()) {
337
- return Nan::ThrowTypeError("Profile name must be a string.");
338
- }
339
- if (!info[1]->IsBoolean()) {
340
- return Nan::ThrowTypeError("Include lines must be a boolean.");
341
- }
342
-
343
- Local<String> name =
344
- Nan::MaybeLocal<String>(info[0].As<String>()).ToLocalChecked();
345
-
346
- bool includeLines =
347
- Nan::MaybeLocal<Boolean>(info[1].As<Boolean>()).ToLocalChecked()->Value();
348
-
349
- Local<Value> profile = timeProfiler->StopProfiling(name, includeLines);
350
- info.GetReturnValue().Set(profile);
351
- }
352
-
353
- static NAN_MODULE_INIT(Init) {
354
- Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
355
- Local<String> className = Nan::New("TimeProfiler").ToLocalChecked();
356
- tpl->SetClassName(className);
357
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
358
-
359
- Nan::SetPrototypeMethod(tpl, "start", Start);
360
- Nan::SetPrototypeMethod(tpl, "dispose", Dispose);
361
- Nan::SetPrototypeMethod(tpl, "stop", Stop);
362
-
363
- constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked());
364
- Nan::Set(target, className, Nan::GetFunction(tpl).ToLocalChecked());
365
- }
366
- private:
367
- int samplingInterval = 0;
368
- CpuProfiler* cpuProfiler = nullptr;
369
-
370
- static inline Nan::Persistent<v8::Function> & constructor() {
371
- static Nan::Persistent<v8::Function> my_constructor;
372
- return my_constructor;
373
- }
374
-
375
- ~TimeProfiler() {
376
- Dispose();
377
- }
378
-
379
- // A new CPU profiler object will be created each time profiling is started
380
- // to work around https://bugs.chromium.org/p/v8/issues/detail?id=11051.
381
- CpuProfiler* GetProfiler() {
382
- if (cpuProfiler == nullptr) {
383
- Isolate* isolate = Isolate::GetCurrent();
384
- cpuProfiler = CpuProfiler::New(isolate);
385
- cpuProfiler->SetSamplingInterval(samplingInterval);
386
- }
387
- return cpuProfiler;
388
- }
389
- };
390
-
391
- extern "C" NODE_MODULE_EXPORT void
392
- NODE_MODULE_INITIALIZER(Local<Object> target,
393
- Local<Value> module,
394
- Local<Context> context) {
395
- TimeProfiler::Init(target);
396
-
397
- Local<Object> heapProfiler = Nan::New<Object>();
398
- Nan::SetMethod(heapProfiler, "startSamplingHeapProfiler",
399
- StartSamplingHeapProfiler);
400
- Nan::SetMethod(heapProfiler, "stopSamplingHeapProfiler",
401
- StopSamplingHeapProfiler);
402
- Nan::SetMethod(heapProfiler, "getAllocationProfile",
403
- GetAllocationProfile);
404
- Nan::Set(target, Nan::New<String>("heapProfiler").ToLocalChecked(),
405
- heapProfiler);
406
- }
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- /* eslint-disable no-console */
4
-
5
- const npmArgv = (() => {
6
- try {
7
- return JSON.parse(process.env.npm_config_argv);
8
- } catch (e) {
9
- return {original: []};
10
- }
11
- })();
12
-
13
- const path = require('path');
14
- const requirePackageJson = require('./require-package-json.js');
15
- const packageJson = requirePackageJson(path.join(__dirname, '..'));
16
-
17
- const nodeMajor = Number(process.versions.node.split('.')[0]);
18
-
19
- const min = Number(packageJson.engines.node.match(/\d+/)[0]);
20
-
21
- const hasIgnoreEngines =
22
- npmArgv && npmArgv.original && npmArgv.original.includes('--ignore-engines');
23
-
24
- if (nodeMajor < min && !hasIgnoreEngines) {
25
- process.exitCode = 1;
26
- console.error(
27
- '\n' +
28
- `
29
- You're using Node.js v${process.versions.node}, which is not supported by
30
- ${packageJson.name}.
31
-
32
- Please upgrade to a more recent version of Node.js.
33
- `.trim() +
34
- '\n'
35
- );
36
- }