@datadog/pprof 0.2.1 → 0.5.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.
- package/binding.gyp +130 -31
- package/bindings/binding.cc +13 -0
- package/bindings/code-event-record.cc +115 -0
- package/bindings/code-event-record.hh +67 -0
- package/bindings/code-map.cc +112 -0
- package/bindings/code-map.hh +47 -0
- package/bindings/cpu-time.cc +89 -0
- package/bindings/cpu-time.hh +35 -0
- package/bindings/location.cc +117 -0
- package/bindings/location.hh +43 -0
- package/bindings/per-isolate-data.cc +42 -0
- package/bindings/per-isolate-data.hh +26 -0
- package/bindings/profilers/cpu.cc +285 -0
- package/bindings/profilers/cpu.hh +78 -0
- package/bindings/profilers/heap.cc +112 -0
- package/bindings/profilers/heap.hh +40 -0
- package/bindings/profilers/wall.cc +306 -0
- package/bindings/profilers/wall.hh +28 -0
- package/bindings/sample.cc +160 -0
- package/bindings/sample.hh +48 -0
- package/bindings/test/binding.cc +59 -0
- package/bindings/test/code-event-record.test.cc +81 -0
- package/bindings/test/code-event-record.test.hh +5 -0
- package/bindings/test/code-map.test.cc +77 -0
- package/bindings/test/code-map.test.hh +5 -0
- package/bindings/test/cpu-time.test.cc +30 -0
- package/bindings/test/cpu-time.test.hh +5 -0
- package/bindings/test/location.test.cc +39 -0
- package/bindings/test/location.test.hh +5 -0
- package/bindings/test/profilers/cpu.test.cc +88 -0
- package/bindings/test/profilers/cpu.test.hh +5 -0
- package/bindings/test/sample.test.cc +128 -0
- package/bindings/test/sample.test.hh +5 -0
- package/bindings/test/tap.h +830 -0
- package/bindings/wrap.hh +20 -0
- package/out/src/cpu-profiler-bindings.d.ts +1 -0
- package/out/src/cpu-profiler-bindings.js +23 -0
- package/out/src/cpu-profiler-bindings.js.map +1 -0
- package/out/src/cpu-profiler.d.ts +19 -0
- package/out/src/cpu-profiler.js +94 -0
- package/out/src/cpu-profiler.js.map +1 -0
- package/out/src/index.d.ts +2 -0
- package/out/src/index.js +3 -1
- package/out/src/index.js.map +1 -1
- package/out/src/profile-encoder.js +3 -14
- package/out/src/profile-encoder.js.map +1 -1
- package/out/src/profile-serializer.d.ts +9 -1
- package/out/src/profile-serializer.js +73 -1
- package/out/src/profile-serializer.js.map +1 -1
- package/out/src/sourcemapper/sourcemapper.js +81 -88
- package/out/src/sourcemapper/sourcemapper.js.map +1 -1
- package/out/src/time-profiler.d.ts +1 -1
- package/out/src/time-profiler.js +40 -34
- package/out/src/time-profiler.js.map +1 -1
- package/out/src/v8-types.d.ts +38 -0
- package/out/third_party/cloud-debug-nodejs/src/agent/io/scanner.js +6 -17
- package/out/third_party/cloud-debug-nodejs/src/agent/io/scanner.js.map +1 -1
- package/package-lock.json +5627 -0
- package/package.json +12 -14
- package/prebuilds/darwin-arm64/node-102.node +0 -0
- package/prebuilds/darwin-arm64/node-108.node +0 -0
- package/prebuilds/darwin-arm64/node-72.node +0 -0
- package/prebuilds/darwin-arm64/node-79.node +0 -0
- package/prebuilds/darwin-arm64/node-83.node +0 -0
- package/prebuilds/darwin-arm64/node-88.node +0 -0
- package/prebuilds/darwin-arm64/node-93.node +0 -0
- package/prebuilds/darwin-ia32/node-102.node +0 -0
- package/prebuilds/darwin-ia32/node-108.node +0 -0
- package/prebuilds/darwin-ia32/node-72.node +0 -0
- package/prebuilds/darwin-ia32/node-79.node +0 -0
- package/prebuilds/darwin-ia32/node-83.node +0 -0
- package/prebuilds/darwin-ia32/node-88.node +0 -0
- package/prebuilds/darwin-ia32/node-93.node +0 -0
- package/prebuilds/darwin-x64/node-102.node +0 -0
- package/prebuilds/darwin-x64/node-108.node +0 -0
- package/prebuilds/darwin-x64/node-72.node +0 -0
- package/prebuilds/darwin-x64/node-79.node +0 -0
- package/prebuilds/darwin-x64/node-83.node +0 -0
- package/prebuilds/darwin-x64/node-88.node +0 -0
- package/prebuilds/darwin-x64/node-93.node +0 -0
- package/prebuilds/linux-ia32/node-72.node +0 -0
- package/prebuilds/linux-ia32/node-79.node +0 -0
- package/prebuilds/linux-x64/node-102.node +0 -0
- package/prebuilds/linux-x64/node-108.node +0 -0
- package/prebuilds/linux-x64/node-72.node +0 -0
- package/prebuilds/linux-x64/node-79.node +0 -0
- package/prebuilds/linux-x64/node-83.node +0 -0
- package/prebuilds/linux-x64/node-88.node +0 -0
- package/prebuilds/linux-x64/node-93.node +0 -0
- package/prebuilds/win32-ia32/node-102.node +0 -0
- package/prebuilds/win32-ia32/node-72.node +0 -0
- package/prebuilds/win32-ia32/node-79.node +0 -0
- package/prebuilds/win32-ia32/node-83.node +0 -0
- package/prebuilds/win32-ia32/node-88.node +0 -0
- package/prebuilds/win32-ia32/node-93.node +0 -0
- package/prebuilds/win32-x64/node-102.node +0 -0
- package/prebuilds/win32-x64/node-108.node +0 -0
- package/prebuilds/win32-x64/node-72.node +0 -0
- package/prebuilds/win32-x64/node-79.node +0 -0
- package/prebuilds/win32-x64/node-83.node +0 -0
- package/prebuilds/win32-x64/node-88.node +0 -0
- package/prebuilds/win32-x64/node-93.node +0 -0
- package/scripts/require-package-json.js +11 -11
- package/scripts/should_rebuild.js +3 -3
- package/bindings/profiler.cc +0 -384
- package/scripts/preinstall.js +0 -36
package/package.json
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/pprof",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "pprof support for Node.js",
|
|
5
5
|
"repository": "datadog/pprof-nodejs",
|
|
6
6
|
"main": "out/src/index.js",
|
|
7
7
|
"types": "out/src/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"preinstall": "node scripts/preinstall.js",
|
|
10
9
|
"install": "(node scripts/should_rebuild && node-gyp-build) || exit 0",
|
|
11
10
|
"rebuild": "node-gyp rebuild --jobs=max",
|
|
12
|
-
"test": "nyc mocha out/test/test-*.js",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"test:js": "nyc mocha out/test/test-*.js",
|
|
12
|
+
"test:cpp": "node scripts/cctest.js",
|
|
13
|
+
"test": "npm run test:js && npm run test:cpp",
|
|
15
14
|
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
|
|
16
15
|
"compile": "tsc -p .",
|
|
17
16
|
"fix": "gts fix",
|
|
18
|
-
"lint": "gts check",
|
|
19
|
-
"docs": "echo 'no docs yet'",
|
|
17
|
+
"lint": "jsgl --local . && gts check",
|
|
20
18
|
"prebuild": "node scripts/prebuild.js",
|
|
21
19
|
"prebuilds": "node scripts/prebuilds.js",
|
|
22
20
|
"prepare": "npm run compile",
|
|
23
21
|
"prepublishOnly": "node scripts/prepublish.js",
|
|
24
22
|
"pretest": "npm run compile && npm run rebuild",
|
|
25
|
-
"posttest": "npm run check && npm run license-check",
|
|
26
23
|
"proto": "npm run proto:profile",
|
|
27
|
-
"proto:profile": "mkdir -p proto && pbjs -t static-module -w commonjs -o proto/profile.js third_party/proto/profile.proto && pbts -o proto/profile.d.ts proto/profile.js"
|
|
28
|
-
"license-check": "jsgl --local .",
|
|
29
|
-
"docs-test": "linkinator docs -r --skip www.googleapis.com",
|
|
30
|
-
"predocs-test": "npm run docs"
|
|
24
|
+
"proto:profile": "mkdir -p proto && pbjs -t static-module -w commonjs -o proto/profile.js third_party/proto/profile.proto && pbts -o proto/profile.d.ts proto/profile.js"
|
|
31
25
|
},
|
|
32
26
|
"author": {
|
|
33
27
|
"name": "Google Inc."
|
|
@@ -40,7 +34,7 @@
|
|
|
40
34
|
"node-gyp-build": "^3.9.0",
|
|
41
35
|
"p-limit": "^3.0.0",
|
|
42
36
|
"pify": "^5.0.0",
|
|
43
|
-
"protobufjs": "~6.11.
|
|
37
|
+
"protobufjs": "~6.11.3",
|
|
44
38
|
"rimraf": "^3.0.2",
|
|
45
39
|
"semver": "^7.3.5",
|
|
46
40
|
"source-map": "^0.7.3",
|
|
@@ -59,6 +53,10 @@
|
|
|
59
53
|
"checksum": "^0.1.1",
|
|
60
54
|
"codecov": "^3.0.0",
|
|
61
55
|
"deep-copy": "^1.4.2",
|
|
56
|
+
"eslint-config-standard": "^17.0.0",
|
|
57
|
+
"eslint-plugin-import": "^2.26.0",
|
|
58
|
+
"eslint-plugin-n": "^15.2.0",
|
|
59
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
62
60
|
"glob": "^7.1.7",
|
|
63
61
|
"gts": "^3.0.0",
|
|
64
62
|
"js-green-licenses": "^3.0.0",
|
|
@@ -97,6 +95,6 @@
|
|
|
97
95
|
]
|
|
98
96
|
},
|
|
99
97
|
"engines": {
|
|
100
|
-
"node": ">=12
|
|
98
|
+
"node": ">=12"
|
|
101
99
|
}
|
|
102
100
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const fs = require('fs')
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Given a package name and a module to start from, find a package's
|
|
@@ -14,20 +14,20 @@ const fs = require('fs');
|
|
|
14
14
|
* @param {Module} module
|
|
15
15
|
* @return {Object} The parsed package.json
|
|
16
16
|
*/
|
|
17
|
-
function requirePackageJson(name, module) {
|
|
17
|
+
function requirePackageJson (name, module) {
|
|
18
18
|
if (path.isAbsolute(name)) {
|
|
19
|
-
const candidate = path.join(name, 'package.json')
|
|
20
|
-
return JSON.parse(fs.readFileSync(candidate, 'utf8'))
|
|
19
|
+
const candidate = path.join(name, 'package.json')
|
|
20
|
+
return JSON.parse(fs.readFileSync(candidate, 'utf8'))
|
|
21
21
|
}
|
|
22
22
|
for (const modulePath of module.paths) {
|
|
23
|
-
const candidate = path.join(modulePath, name, 'package.json')
|
|
23
|
+
const candidate = path.join(modulePath, name, 'package.json')
|
|
24
24
|
try {
|
|
25
|
-
return JSON.parse(fs.readFileSync(candidate, 'utf8'))
|
|
25
|
+
return JSON.parse(fs.readFileSync(candidate, 'utf8'))
|
|
26
26
|
} catch (e) {
|
|
27
|
-
continue
|
|
27
|
+
continue
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
throw new Error(`could not find ${name}/package.json`)
|
|
30
|
+
throw new Error(`could not find ${name}/package.json`)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
module.exports = requirePackageJson
|
|
33
|
+
module.exports = requirePackageJson
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
const {CI, INIT_CWD, PWD} = process.env
|
|
3
|
+
const { CI, INIT_CWD, PWD } = process.env
|
|
4
4
|
|
|
5
5
|
// skip for local development, CI, or very old package managers without INIT_CWD
|
|
6
6
|
if (CI === 'true' || !INIT_CWD || INIT_CWD.includes(PWD)) {
|
|
7
|
-
process.exitCode = 1
|
|
7
|
+
process.exitCode = 1
|
|
8
8
|
}
|
package/bindings/profiler.cc
DELETED
|
@@ -1,384 +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
|
-
static inline Nan::Persistent<v8::Function> & constructor() {
|
|
246
|
-
static Nan::Persistent<v8::Function> my_constructor;
|
|
247
|
-
return my_constructor;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
explicit TimeProfiler(int interval) {
|
|
251
|
-
Isolate* isolate = Isolate::GetCurrent();
|
|
252
|
-
|
|
253
|
-
// A new CPU profiler object will be created each time profiling is started
|
|
254
|
-
// to work around https://bugs.chromium.org/p/v8/issues/detail?id=11051.
|
|
255
|
-
cpuProfiler = CpuProfiler::New(isolate);
|
|
256
|
-
cpuProfiler->SetSamplingInterval(interval);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
static NAN_METHOD(New) {
|
|
260
|
-
if (info.Length() != 1) {
|
|
261
|
-
return Nan::ThrowTypeError("TimeProfiler must have one argument.");
|
|
262
|
-
}
|
|
263
|
-
if (!info[0]->IsNumber()) {
|
|
264
|
-
return Nan::ThrowTypeError("Sample rate must be a number.");
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (info.IsConstructCall()) {
|
|
268
|
-
int interval =
|
|
269
|
-
Nan::MaybeLocal<Integer>(info[0].As<Integer>()).ToLocalChecked()->Value();
|
|
270
|
-
|
|
271
|
-
TimeProfiler* obj = new TimeProfiler(interval);
|
|
272
|
-
obj->Wrap(info.This());
|
|
273
|
-
info.GetReturnValue().Set(info.This());
|
|
274
|
-
} else {
|
|
275
|
-
const int argc = 1;
|
|
276
|
-
v8::Local<v8::Value> argv[argc] = {info[0]};
|
|
277
|
-
v8::Local<v8::Function> cons = Nan::New(constructor());
|
|
278
|
-
info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
void StartProfiling(Local<String> name, bool includeLines) {
|
|
283
|
-
// Sample counts and timestamps are not used, so we do not need to record
|
|
284
|
-
// samples.
|
|
285
|
-
const bool recordSamples = false;
|
|
286
|
-
|
|
287
|
-
if (includeLines) {
|
|
288
|
-
cpuProfiler->StartProfiling(name, CpuProfilingMode::kCallerLineNumbers,
|
|
289
|
-
recordSamples);
|
|
290
|
-
} else {
|
|
291
|
-
cpuProfiler->StartProfiling(name, recordSamples);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
static NAN_METHOD(Start) {
|
|
296
|
-
TimeProfiler* timeProfiler =
|
|
297
|
-
Nan::ObjectWrap::Unwrap<TimeProfiler>(info.Holder());
|
|
298
|
-
|
|
299
|
-
if (info.Length() != 2) {
|
|
300
|
-
return Nan::ThrowTypeError("Start must have two arguments.");
|
|
301
|
-
}
|
|
302
|
-
if (!info[0]->IsString()) {
|
|
303
|
-
return Nan::ThrowTypeError("Profile name must be a string.");
|
|
304
|
-
}
|
|
305
|
-
if (!info[1]->IsBoolean()) {
|
|
306
|
-
return Nan::ThrowTypeError("Include lines must be a boolean.");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
Local<String> name =
|
|
310
|
-
Nan::MaybeLocal<String>(info[0].As<String>()).ToLocalChecked();
|
|
311
|
-
|
|
312
|
-
bool includeLines =
|
|
313
|
-
Nan::MaybeLocal<Boolean>(info[1].As<Boolean>()).ToLocalChecked()->Value();
|
|
314
|
-
|
|
315
|
-
timeProfiler->StartProfiling(name, includeLines);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
Local<Value> StopProfiling(Local<String> name, bool includeLines) {
|
|
319
|
-
CpuProfile* profile = cpuProfiler->StopProfiling(name);
|
|
320
|
-
Local<Value> translated_profile =
|
|
321
|
-
TranslateTimeProfile(profile, includeLines);
|
|
322
|
-
profile->Delete();
|
|
323
|
-
// Dispose of CPU profiler to work around memory leak.
|
|
324
|
-
cpuProfiler->Dispose();
|
|
325
|
-
cpuProfiler = NULL;
|
|
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, "stop", Stop);
|
|
361
|
-
|
|
362
|
-
constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked());
|
|
363
|
-
Nan::Set(target, className, Nan::GetFunction(tpl).ToLocalChecked());
|
|
364
|
-
}
|
|
365
|
-
private:
|
|
366
|
-
CpuProfiler* cpuProfiler;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
extern "C" NODE_MODULE_EXPORT void
|
|
370
|
-
NODE_MODULE_INITIALIZER(Local<Object> target,
|
|
371
|
-
Local<Value> module,
|
|
372
|
-
Local<Context> context) {
|
|
373
|
-
TimeProfiler::Init(target);
|
|
374
|
-
|
|
375
|
-
Local<Object> heapProfiler = Nan::New<Object>();
|
|
376
|
-
Nan::SetMethod(heapProfiler, "startSamplingHeapProfiler",
|
|
377
|
-
StartSamplingHeapProfiler);
|
|
378
|
-
Nan::SetMethod(heapProfiler, "stopSamplingHeapProfiler",
|
|
379
|
-
StopSamplingHeapProfiler);
|
|
380
|
-
Nan::SetMethod(heapProfiler, "getAllocationProfile",
|
|
381
|
-
GetAllocationProfile);
|
|
382
|
-
Nan::Set(target, Nan::New<String>("heapProfiler").ToLocalChecked(),
|
|
383
|
-
heapProfiler);
|
|
384
|
-
}
|
package/scripts/preinstall.js
DELETED
|
@@ -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
|
-
}
|