@datadog/pprof 0.1.2 → 0.3.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/bindings/profiler.cc +144 -123
- package/out/src/profile-serializer.js +6 -3
- package/out/src/profile-serializer.js.map +1 -1
- package/out/src/time-profiler-bindings.d.ts +1 -4
- package/out/src/time-profiler-bindings.js +4 -16
- package/out/src/time-profiler-bindings.js.map +1 -1
- package/out/src/time-profiler.d.ts +1 -1
- package/out/src/time-profiler.js +40 -23
- package/out/src/time-profiler.js.map +1 -1
- package/package.json +7 -5
- package/prebuilds/darwin-ia32/node-102.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-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-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-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/prebuild.js +0 -57
- package/scripts/prebuilds.js +0 -93
- package/scripts/prepublish.js +0 -201
package/bindings/profiler.cc
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
#include <memory>
|
|
18
18
|
|
|
19
|
+
#include <node.h>
|
|
19
20
|
#include "nan.h"
|
|
20
21
|
#include "v8-profiler.h"
|
|
21
22
|
|
|
@@ -95,22 +96,6 @@ NAN_METHOD(GetAllocationProfile) {
|
|
|
95
96
|
info.GetReturnValue().Set(TranslateAllocationProfile(root));
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
// Time profiler
|
|
99
|
-
#if NODE_MODULE_VERSION >= NODE_12_0_MODULE_VERSION
|
|
100
|
-
// For Node 12 and Node 14, a new CPU profiler object will be created each
|
|
101
|
-
// time profiling is started to work around
|
|
102
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=11051.
|
|
103
|
-
CpuProfiler* cpuProfiler;
|
|
104
|
-
// Default sampling interval is 1000us.
|
|
105
|
-
int samplingIntervalUS = 1000;
|
|
106
|
-
#elif NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION
|
|
107
|
-
// This profiler exists for the lifetime of the program. Not calling
|
|
108
|
-
// CpuProfiler::Dispose() is intentional.
|
|
109
|
-
CpuProfiler* cpuProfiler = CpuProfiler::New(v8::Isolate::GetCurrent());
|
|
110
|
-
#else
|
|
111
|
-
CpuProfiler* cpuProfiler = v8::Isolate::GetCurrent()->GetCpuProfiler();
|
|
112
|
-
#endif
|
|
113
|
-
|
|
114
99
|
Local<Object> CreateTimeNode(Local<String> name, Local<String> scriptName,
|
|
115
100
|
Local<Integer> scriptId, Local<Integer> lineNumber,
|
|
116
101
|
Local<Integer> columnNumber,
|
|
@@ -130,7 +115,6 @@ Local<Object> CreateTimeNode(Local<String> name, Local<String> scriptName,
|
|
|
130
115
|
return js_node;
|
|
131
116
|
}
|
|
132
117
|
|
|
133
|
-
#if NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION
|
|
134
118
|
Local<Object> TranslateLineNumbersTimeProfileNode(const CpuProfileNode* parent,
|
|
135
119
|
const CpuProfileNode* node);
|
|
136
120
|
|
|
@@ -216,7 +200,6 @@ Local<Value> TranslateLineNumbersTimeProfileRoot(const CpuProfileNode* node) {
|
|
|
216
200
|
Nan::New<Integer>(node->GetColumnNumber()),
|
|
217
201
|
Nan::New<Integer>(0), children);
|
|
218
202
|
}
|
|
219
|
-
#endif
|
|
220
203
|
|
|
221
204
|
Local<Value> TranslateTimeProfileNode(const CpuProfileNode* node) {
|
|
222
205
|
int32_t count = node->GetChildrenCount();
|
|
@@ -257,129 +240,167 @@ Local<Value> TranslateTimeProfile(const CpuProfile* profile,
|
|
|
257
240
|
return js_profile;
|
|
258
241
|
}
|
|
259
242
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
+
}
|
|
265
253
|
}
|
|
266
|
-
|
|
267
|
-
|
|
254
|
+
|
|
255
|
+
static NAN_METHOD(Dispose) {
|
|
256
|
+
TimeProfiler* timeProfiler =
|
|
257
|
+
Nan::ObjectWrap::Unwrap<TimeProfiler>(info.Holder());
|
|
258
|
+
|
|
259
|
+
timeProfiler->Dispose();
|
|
268
260
|
}
|
|
269
|
-
|
|
270
|
-
|
|
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
|
+
}
|
|
271
283
|
}
|
|
272
284
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
}
|
|
279
296
|
}
|
|
280
|
-
cpuProfiler = CpuProfiler::New(v8::Isolate::GetCurrent());
|
|
281
|
-
cpuProfiler->SetSamplingInterval(samplingIntervalUS);
|
|
282
|
-
#endif
|
|
283
297
|
|
|
284
|
-
|
|
285
|
-
|
|
298
|
+
static NAN_METHOD(Start) {
|
|
299
|
+
TimeProfiler* timeProfiler =
|
|
300
|
+
Nan::ObjectWrap::Unwrap<TimeProfiler>(info.Holder());
|
|
286
301
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
+
}
|
|
290
311
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
} else {
|
|
299
|
-
cpuProfiler->StartProfiling(name, recordSamples);
|
|
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);
|
|
300
319
|
}
|
|
301
|
-
#else
|
|
302
|
-
cpuProfiler->StartProfiling(name, recordSamples);
|
|
303
|
-
#endif
|
|
304
|
-
}
|
|
305
320
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return
|
|
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;
|
|
312
327
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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());
|
|
316
365
|
}
|
|
317
|
-
|
|
318
|
-
|
|
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;
|
|
319
373
|
}
|
|
320
|
-
|
|
321
|
-
|
|
374
|
+
|
|
375
|
+
~TimeProfiler() {
|
|
376
|
+
Dispose();
|
|
322
377
|
}
|
|
323
|
-
Local<String> name =
|
|
324
|
-
Nan::MaybeLocal<String>(info[0].As<String>()).ToLocalChecked();
|
|
325
|
-
bool includeLineInfo =
|
|
326
|
-
Nan::MaybeLocal<Boolean>(info[1].As<Boolean>()).ToLocalChecked()->Value();
|
|
327
|
-
|
|
328
|
-
CpuProfile* profile = cpuProfiler->StopProfiling(name);
|
|
329
|
-
Local<Value> translated_profile =
|
|
330
|
-
TranslateTimeProfile(profile, includeLineInfo);
|
|
331
|
-
profile->Delete();
|
|
332
|
-
#if NODE_MODULE_VERSION >= NODE_12_0_MODULE_VERSION
|
|
333
|
-
// Dispose of CPU profiler to work around memory leak.
|
|
334
|
-
cpuProfiler->Dispose();
|
|
335
|
-
cpuProfiler = NULL;
|
|
336
|
-
#endif
|
|
337
|
-
info.GetReturnValue().Set(translated_profile);
|
|
338
|
-
}
|
|
339
378
|
|
|
340
|
-
//
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
cpuProfiler->SetSamplingInterval(us);
|
|
352
|
-
#endif
|
|
353
|
-
}
|
|
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
|
+
};
|
|
354
390
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Nan::Set(timeProfiler, Nan::New("stopProfiling").ToLocalChecked(),
|
|
361
|
-
Nan::GetFunction(Nan::New<FunctionTemplate>(StopProfiling))
|
|
362
|
-
.ToLocalChecked());
|
|
363
|
-
Nan::Set(timeProfiler, Nan::New("setSamplingInterval").ToLocalChecked(),
|
|
364
|
-
Nan::GetFunction(Nan::New<FunctionTemplate>(SetSamplingInterval))
|
|
365
|
-
.ToLocalChecked());
|
|
366
|
-
Nan::Set(target, Nan::New<String>("timeProfiler").ToLocalChecked(),
|
|
367
|
-
timeProfiler);
|
|
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);
|
|
368
396
|
|
|
369
397
|
Local<Object> heapProfiler = Nan::New<Object>();
|
|
370
|
-
Nan::
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
Nan::
|
|
375
|
-
|
|
376
|
-
Nan::GetFunction(Nan::New<FunctionTemplate>(StopSamplingHeapProfiler))
|
|
377
|
-
.ToLocalChecked());
|
|
378
|
-
Nan::Set(heapProfiler, Nan::New("getAllocationProfile").ToLocalChecked(),
|
|
379
|
-
Nan::GetFunction(Nan::New<FunctionTemplate>(GetAllocationProfile))
|
|
380
|
-
.ToLocalChecked());
|
|
398
|
+
Nan::SetMethod(heapProfiler, "startSamplingHeapProfiler",
|
|
399
|
+
StartSamplingHeapProfiler);
|
|
400
|
+
Nan::SetMethod(heapProfiler, "stopSamplingHeapProfiler",
|
|
401
|
+
StopSamplingHeapProfiler);
|
|
402
|
+
Nan::SetMethod(heapProfiler, "getAllocationProfile",
|
|
403
|
+
GetAllocationProfile);
|
|
381
404
|
Nan::Set(target, Nan::New<String>("heapProfiler").ToLocalChecked(),
|
|
382
405
|
heapProfiler);
|
|
383
406
|
}
|
|
384
|
-
|
|
385
|
-
NODE_MODULE(google_cloud_profiler, InitAll);
|
|
@@ -74,6 +74,8 @@ function serialize(profile, root, appendToSamples, stringTable, ignoreSamplesPat
|
|
|
74
74
|
if (ignoreSamplesPath && node.scriptName.indexOf(ignoreSamplesPath) > -1) {
|
|
75
75
|
continue;
|
|
76
76
|
}
|
|
77
|
+
if (node.name === '(idle)' || node.name === '(program)')
|
|
78
|
+
continue;
|
|
77
79
|
const stack = entry.stack;
|
|
78
80
|
const location = getLocation(node, sourceMapper);
|
|
79
81
|
stack.unshift(location.id);
|
|
@@ -148,13 +150,13 @@ function createSampleCountValueType(table) {
|
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
152
|
/**
|
|
151
|
-
* @return value type for time samples (type:wall, units:
|
|
153
|
+
* @return value type for time samples (type:wall, units:nanoseconds), and
|
|
152
154
|
* adds strings used in this value type to the table.
|
|
153
155
|
*/
|
|
154
156
|
function createTimeValueType(table) {
|
|
155
157
|
return new profile_1.perftools.profiles.ValueType({
|
|
156
158
|
type: table.getIndexOrAdd('wall'),
|
|
157
|
-
unit: table.getIndexOrAdd('
|
|
159
|
+
unit: table.getIndexOrAdd('nanoseconds'),
|
|
158
160
|
});
|
|
159
161
|
}
|
|
160
162
|
/**
|
|
@@ -185,11 +187,12 @@ function createAllocationValueType(table) {
|
|
|
185
187
|
* @param intervalMicros - average time (microseconds) between samples.
|
|
186
188
|
*/
|
|
187
189
|
function serializeTimeProfile(prof, intervalMicros, sourceMapper) {
|
|
190
|
+
const intervalNanos = intervalMicros * 1000;
|
|
188
191
|
const appendTimeEntryToSamples = (entry, samples) => {
|
|
189
192
|
if (entry.node.hitCount > 0) {
|
|
190
193
|
const sample = new profile_1.perftools.profiles.Sample({
|
|
191
194
|
locationId: entry.stack,
|
|
192
|
-
value: [entry.node.hitCount, entry.node.hitCount *
|
|
195
|
+
value: [entry.node.hitCount, entry.node.hitCount * intervalNanos],
|
|
193
196
|
});
|
|
194
197
|
samples.push(sample);
|
|
195
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-serializer.js","sourceRoot":"","sources":["../../ts/src/profile-serializer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iDAA8C;AAmC9C,SAAS,mBAAmB,CAC1B,QAAwB;IAExB,OAAO,CACL,QAAQ,CAAC,MAAM,KAAK,SAAS;QAC7B,QAAQ,CAAC,IAAI,KAAK,SAAS;QAC3B,QAAQ,CAAC,IAAI,GAAG,CAAC,CAClB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,WAAW;IAIf;QACE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC5C,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,GAAW;QACvB,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,GAAG,CAAC;SACZ;QACD,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,SAAS,SAAS,CAChB,OAAoC,EACpC,IAAO,EACP,eAAwC,EACxC,WAAwB,EAC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CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;oBACnD,oCAAoC;iBACrC,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACtB;SACF;IACH,CAAC,CAAC;IAEJ,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,MAAM,eAAe,GAAG,0BAA0B,CAAC,WAAW,CAAC,CAAC;IAChE,MAAM,mBAAmB,GAAG,yBAAyB,CAAC,WAAW,CAAC,CAAC;IAEnE,MAAM,OAAO,GAAG;QACd,UAAU,EAAE,CAAC,eAAe,EAAE,mBAAmB,CAAC;QAClD,SAAS,EAAE,cAAc;QACzB,UAAU,EAAE,mBAAmB;QAC/B,MAAM,EAAE,aAAa;KACtB,CAAC;IAEF,SAAS,CACP,OAAO,EACP,IAAI,EACJ,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,CACb,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AA5CD,oDA4CC"}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function startProfiling(runName: string, includeLineInfo?: boolean): void;
|
|
3
|
-
export declare function stopProfiling(runName: string, includeLineInfo?: boolean): TimeProfile;
|
|
4
|
-
export declare function setSamplingInterval(intervalMicros: number): void;
|
|
1
|
+
export declare const TimeProfiler: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TimeProfiler = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright 2018 Google Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -16,20 +16,8 @@ exports.setSamplingInterval = exports.stopProfiling = exports.startProfiling = v
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
const
|
|
19
|
+
const path_1 = require("path");
|
|
20
20
|
const findBinding = require('node-gyp-build');
|
|
21
|
-
const profiler = findBinding(
|
|
22
|
-
|
|
23
|
-
function startProfiling(runName, includeLineInfo) {
|
|
24
|
-
profiler.timeProfiler.startProfiling(runName, includeLineInfo || false);
|
|
25
|
-
}
|
|
26
|
-
exports.startProfiling = startProfiling;
|
|
27
|
-
function stopProfiling(runName, includeLineInfo) {
|
|
28
|
-
return profiler.timeProfiler.stopProfiling(runName, includeLineInfo || false);
|
|
29
|
-
}
|
|
30
|
-
exports.stopProfiling = stopProfiling;
|
|
31
|
-
function setSamplingInterval(intervalMicros) {
|
|
32
|
-
profiler.timeProfiler.setSamplingInterval(intervalMicros);
|
|
33
|
-
}
|
|
34
|
-
exports.setSamplingInterval = setSamplingInterval;
|
|
21
|
+
const profiler = findBinding(path_1.join(__dirname, '..', '..'));
|
|
22
|
+
exports.TimeProfiler = profiler.TimeProfiler;
|
|
35
23
|
//# sourceMappingURL=time-profiler-bindings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-profiler-bindings.js","sourceRoot":"","sources":["../../ts/src/time-profiler-bindings.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH
|
|
1
|
+
{"version":3,"file":"time-profiler-bindings.js","sourceRoot":"","sources":["../../ts/src/time-profiler-bindings.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,+BAA0B;AAE1B,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE7C,QAAA,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC"}
|
|
@@ -32,5 +32,5 @@ export interface TimeProfilerOptions {
|
|
|
32
32
|
lineNumbers?: boolean;
|
|
33
33
|
}
|
|
34
34
|
export declare function profile(options: TimeProfilerOptions): Promise<import("../../proto/profile").perftools.profiles.IProfile>;
|
|
35
|
-
export declare function start(intervalMicros?: Microseconds, name?: string, sourceMapper?: SourceMapper, lineNumbers?: boolean): () => import("../../proto/profile").perftools.profiles.IProfile;
|
|
35
|
+
export declare function start(intervalMicros?: Microseconds, name?: string, sourceMapper?: SourceMapper, lineNumbers?: boolean): (restart?: boolean) => import("../../proto/profile").perftools.profiles.IProfile;
|
|
36
36
|
export {};
|
package/out/src/time-profiler.js
CHANGED
|
@@ -28,8 +28,8 @@ exports.start = exports.profile = void 0;
|
|
|
28
28
|
const delay_1 = require("delay");
|
|
29
29
|
const profile_serializer_1 = require("./profile-serializer");
|
|
30
30
|
const time_profiler_bindings_1 = require("./time-profiler-bindings");
|
|
31
|
-
let profiling = false;
|
|
32
31
|
const DEFAULT_INTERVAL_MICROS = 1000;
|
|
32
|
+
const majorVersion = process.version.slice(1).split('.').map(Number)[0];
|
|
33
33
|
function profile(options) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
const stop = start(options.intervalMicros || DEFAULT_INTERVAL_MICROS, options.name, options.sourceMapper, options.lineNumbers);
|
|
@@ -38,29 +38,46 @@ function profile(options) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
exports.profile = profile;
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
function ensureRunName(name) {
|
|
42
|
+
return name || `pprof-${Date.now()}-${Math.random()}`;
|
|
43
|
+
}
|
|
44
|
+
// NOTE: refreshing doesn't work if giving a profile name.
|
|
45
|
+
function start(intervalMicros = DEFAULT_INTERVAL_MICROS, name, sourceMapper, lineNumbers = true) {
|
|
46
|
+
const profiler = new time_profiler_bindings_1.TimeProfiler(intervalMicros);
|
|
47
|
+
let runName = start();
|
|
48
|
+
return majorVersion < 16 ? stopOld : stop;
|
|
49
|
+
function start() {
|
|
50
|
+
const runName = ensureRunName(name);
|
|
51
|
+
profiler.start(runName, lineNumbers);
|
|
52
|
+
return runName;
|
|
53
|
+
}
|
|
54
|
+
// Node.js versions prior to v16 leak memory if not disposed and recreated
|
|
55
|
+
// between each profile. As disposing deletes current profile data too,
|
|
56
|
+
// we must stop then dispose then start.
|
|
57
|
+
function stopOld(restart = false) {
|
|
58
|
+
const result = profiler.stop(runName, lineNumbers);
|
|
59
|
+
profiler.dispose();
|
|
60
|
+
if (restart) {
|
|
61
|
+
runName = start();
|
|
62
|
+
}
|
|
63
|
+
return profile_serializer_1.serializeTimeProfile(result, intervalMicros, sourceMapper);
|
|
64
|
+
}
|
|
65
|
+
// For Node.js v16+, we want to start the next profile before we stop the
|
|
66
|
+
// current one as otherwise the active profile count could reach zero which
|
|
67
|
+
// means V8 might tear down the symbolizer thread and need to start it again.
|
|
68
|
+
function stop(restart = false) {
|
|
69
|
+
let nextRunName;
|
|
70
|
+
if (restart) {
|
|
71
|
+
nextRunName = start();
|
|
72
|
+
}
|
|
73
|
+
const result = profiler.stop(runName, lineNumbers);
|
|
74
|
+
if (nextRunName) {
|
|
75
|
+
runName = nextRunName;
|
|
76
|
+
}
|
|
77
|
+
if (!restart)
|
|
78
|
+
profiler.dispose();
|
|
79
|
+
return profile_serializer_1.serializeTimeProfile(result, intervalMicros, sourceMapper);
|
|
44
80
|
}
|
|
45
|
-
profiling = true;
|
|
46
|
-
const runName = name || `pprof-${Date.now()}-${Math.random()}`;
|
|
47
|
-
time_profiler_bindings_1.setSamplingInterval(intervalMicros);
|
|
48
|
-
// Node.js contains an undocumented API for reporting idle status to V8.
|
|
49
|
-
// This lets the profiler distinguish idle time from time spent in native
|
|
50
|
-
// code. Ideally this should be default behavior. Until then, use the
|
|
51
|
-
// undocumented API.
|
|
52
|
-
// See https://github.com/nodejs/node/issues/19009#issuecomment-403161559.
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
-
process._startProfilerIdleNotifier();
|
|
55
|
-
time_profiler_bindings_1.startProfiling(runName, lineNumbers);
|
|
56
|
-
return function stop() {
|
|
57
|
-
profiling = false;
|
|
58
|
-
const result = time_profiler_bindings_1.stopProfiling(runName, lineNumbers);
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
process._stopProfilerIdleNotifier();
|
|
61
|
-
const profile = profile_serializer_1.serializeTimeProfile(result, intervalMicros, sourceMapper);
|
|
62
|
-
return profile;
|
|
63
|
-
};
|
|
64
81
|
}
|
|
65
82
|
exports.start = start;
|
|
66
83
|
//# sourceMappingURL=time-profiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-profiler.js","sourceRoot":"","sources":["../../ts/src/time-profiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,iCAA0B;AAE1B,6DAA0D;AAE1D,
|
|
1
|
+
{"version":3,"file":"time-profiler.js","sourceRoot":"","sources":["../../ts/src/time-profiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,iCAA0B;AAE1B,6DAA0D;AAE1D,qEAAsD;AAEtD,MAAM,uBAAuB,GAAiB,IAAI,CAAC;AAEnD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAsBxE,SAAsB,OAAO,CAAC,OAA4B;;QACxD,MAAM,IAAI,GAAG,KAAK,CAChB,OAAO,CAAC,cAAc,IAAI,uBAAuB,EACjD,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,WAAW,CACpB,CAAC;QACF,MAAM,eAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACpC,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;CAAA;AATD,0BASC;AAED,SAAS,aAAa,CAAC,IAAa;IAClC,OAAO,IAAI,IAAI,SAAS,I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,QAAQ,CAAC,OAAO,EAAE,CAAC;QACjC,OAAO,yCAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AA3CD,sBA2CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/pprof",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "pprof support for Node.js",
|
|
5
5
|
"repository": "datadog/pprof-nodejs",
|
|
6
6
|
"main": "out/src/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"preinstall": "node scripts/preinstall.js",
|
|
10
10
|
"install": "(node scripts/should_rebuild && node-gyp-build) || exit 0",
|
|
11
11
|
"rebuild": "node-gyp rebuild --jobs=max",
|
|
12
|
-
"test": "nyc mocha
|
|
12
|
+
"test": "nyc mocha out/test/test-*.js",
|
|
13
13
|
"check": "gts check",
|
|
14
14
|
"clean": "gts clean && node-gyp clean",
|
|
15
15
|
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"delay": "^5.0.0",
|
|
38
38
|
"findit2": "^2.2.3",
|
|
39
39
|
"nan": "^2.14.0",
|
|
40
|
-
"node-gyp-build": "^
|
|
40
|
+
"node-gyp-build": "^3.9.0",
|
|
41
41
|
"p-limit": "^3.0.0",
|
|
42
42
|
"pify": "^5.0.0",
|
|
43
43
|
"protobufjs": "~6.11.0",
|
|
@@ -84,7 +84,9 @@
|
|
|
84
84
|
"package-lock.json",
|
|
85
85
|
"package.json",
|
|
86
86
|
"README.md",
|
|
87
|
-
"scripts",
|
|
87
|
+
"scripts/preinstall.js",
|
|
88
|
+
"scripts/require-package-json.js",
|
|
89
|
+
"scripts/should_rebuild.js",
|
|
88
90
|
"prebuilds"
|
|
89
91
|
],
|
|
90
92
|
"nyc": {
|
|
@@ -95,6 +97,6 @@
|
|
|
95
97
|
]
|
|
96
98
|
},
|
|
97
99
|
"engines": {
|
|
98
|
-
"node": ">=
|
|
100
|
+
"node": ">=12.0.0"
|
|
99
101
|
}
|
|
100
102
|
}
|
|
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
|
package/scripts/prebuild.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const mkdirp = require('mkdirp');
|
|
7
|
-
const {execSync} = require('child_process');
|
|
8
|
-
const semver = require('semver');
|
|
9
|
-
const checksum = require('checksum');
|
|
10
|
-
|
|
11
|
-
const platform = os.platform();
|
|
12
|
-
const arch = process.env.ARCH || os.arch();
|
|
13
|
-
|
|
14
|
-
const {NODE_VERSIONS = '>=12'} = process.env;
|
|
15
|
-
|
|
16
|
-
// https://nodejs.org/en/download/releases/
|
|
17
|
-
const targets = [
|
|
18
|
-
{version: '12.0.0', abi: '72'},
|
|
19
|
-
{version: '13.0.0', abi: '79'},
|
|
20
|
-
{version: '14.0.0', abi: '83'},
|
|
21
|
-
{version: '15.0.0', abi: '88'},
|
|
22
|
-
{version: '16.0.0', abi: '93'},
|
|
23
|
-
].filter(target => semver.satisfies(target.version, NODE_VERSIONS));
|
|
24
|
-
|
|
25
|
-
prebuildify();
|
|
26
|
-
|
|
27
|
-
function prebuildify() {
|
|
28
|
-
const cache = path.join(os.tmpdir(), 'prebuilds');
|
|
29
|
-
|
|
30
|
-
mkdirp.sync(cache);
|
|
31
|
-
mkdirp.sync(`prebuilds/${platform}-${arch}`);
|
|
32
|
-
|
|
33
|
-
targets.forEach(target => {
|
|
34
|
-
const output = `prebuilds/${platform}-${arch}/node-${target.abi}.node`;
|
|
35
|
-
const cmd = [
|
|
36
|
-
'node-gyp rebuild',
|
|
37
|
-
`--target=${target.version}`,
|
|
38
|
-
`--target_arch=${arch}`,
|
|
39
|
-
`--devdir=${cache}`,
|
|
40
|
-
'--release',
|
|
41
|
-
'--jobs=max',
|
|
42
|
-
'--build_v8_with_gn=false',
|
|
43
|
-
'--v8_enable_pointer_compression=""',
|
|
44
|
-
'--v8_enable_31bit_smis_on_64bit_arch=""',
|
|
45
|
-
'--enable_lto=false',
|
|
46
|
-
].join(' ');
|
|
47
|
-
|
|
48
|
-
execSync(cmd, {stdio: [0, 1, 2]});
|
|
49
|
-
|
|
50
|
-
const sum = checksum(fs.readFileSync('build/Release/dd-pprof.node'), {
|
|
51
|
-
algorithm: 'sha256',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
fs.writeFileSync(`${output}.sha1`, sum);
|
|
55
|
-
fs.copyFileSync('build/Release/dd-pprof.node', output);
|
|
56
|
-
});
|
|
57
|
-
}
|
package/scripts/prebuilds.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const checksum = require('checksum');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const glob = require('glob');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const tar = require('tar');
|
|
9
|
-
|
|
10
|
-
const platforms = [
|
|
11
|
-
'darwin-ia32',
|
|
12
|
-
'darwin-x64',
|
|
13
|
-
'linux-ia32',
|
|
14
|
-
'linux-x64',
|
|
15
|
-
'win32-ia32',
|
|
16
|
-
'win32-x64',
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
zipPrebuilds();
|
|
20
|
-
extractPrebuilds();
|
|
21
|
-
validatePrebuilds();
|
|
22
|
-
createChecksum();
|
|
23
|
-
copyPrebuilds();
|
|
24
|
-
|
|
25
|
-
function zipPrebuilds() {
|
|
26
|
-
tar.create(
|
|
27
|
-
{
|
|
28
|
-
gzip: true,
|
|
29
|
-
sync: true,
|
|
30
|
-
portable: true,
|
|
31
|
-
strict: true,
|
|
32
|
-
file: path.join(os.tmpdir(), 'prebuilds.tgz'),
|
|
33
|
-
},
|
|
34
|
-
glob.sync('prebuilds/**/*.node')
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function extractPrebuilds() {
|
|
39
|
-
tar.extract({
|
|
40
|
-
sync: true,
|
|
41
|
-
strict: true,
|
|
42
|
-
file: path.join(os.tmpdir(), 'prebuilds.tgz'),
|
|
43
|
-
cwd: os.tmpdir(),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function validatePrebuilds() {
|
|
48
|
-
platforms.forEach(platform => {
|
|
49
|
-
try {
|
|
50
|
-
fs.readdirSync(path.join(os.tmpdir(), 'prebuilds', platform))
|
|
51
|
-
.filter(file => /^node-\d+\.node$/.test(file))
|
|
52
|
-
.forEach(file => {
|
|
53
|
-
const content = fs.readFileSync(
|
|
54
|
-
path.join('prebuilds', platform, file)
|
|
55
|
-
);
|
|
56
|
-
const sum = fs.readFileSync(
|
|
57
|
-
path.join('prebuilds', platform, `${file}.sha1`),
|
|
58
|
-
'ascii'
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
if (sum !== checksum(content, {algorithm: 'sha256'})) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Invalid checksum for "prebuilds/${platform}/${file}".`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
} catch (e) {
|
|
68
|
-
// skip missing platforms
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function createChecksum() {
|
|
74
|
-
const file = path.join(os.tmpdir(), 'prebuilds.tgz');
|
|
75
|
-
const sum = checksum(fs.readFileSync(file), {algorithm: 'sha256'});
|
|
76
|
-
|
|
77
|
-
fs.writeFileSync(`${file}.sha1`, sum);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function copyPrebuilds() {
|
|
81
|
-
const basename = path.normalize(path.join(__dirname, '..'));
|
|
82
|
-
const filename = 'prebuilds.tgz';
|
|
83
|
-
|
|
84
|
-
fs.copyFileSync(
|
|
85
|
-
path.join(os.tmpdir(), filename),
|
|
86
|
-
path.join(basename, filename)
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
fs.copyFileSync(
|
|
90
|
-
path.join(os.tmpdir(), `${filename}.sha1`),
|
|
91
|
-
path.join(basename, `${filename}.sha1`)
|
|
92
|
-
);
|
|
93
|
-
}
|
package/scripts/prepublish.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-console */
|
|
4
|
-
|
|
5
|
-
const axios = require('axios');
|
|
6
|
-
const checksum = require('checksum');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const os = require('os');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
const rimraf = require('rimraf');
|
|
11
|
-
const tar = require('tar');
|
|
12
|
-
const {execSync} = require('child_process');
|
|
13
|
-
|
|
14
|
-
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
|
15
|
-
const color = {
|
|
16
|
-
GRAY: '\\033[1;90m',
|
|
17
|
-
CYAN: '\\033[1;36m',
|
|
18
|
-
NONE: '\\033[0m',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const {CIRCLE_TOKEN} = process.env;
|
|
22
|
-
|
|
23
|
-
title('Downloading and compiling files for release.');
|
|
24
|
-
|
|
25
|
-
const revision = execPipe('git rev-parse HEAD');
|
|
26
|
-
|
|
27
|
-
console.log(revision);
|
|
28
|
-
|
|
29
|
-
const branch = execPipe('git symbolic-ref --short HEAD');
|
|
30
|
-
|
|
31
|
-
console.log(branch);
|
|
32
|
-
|
|
33
|
-
const headers = CIRCLE_TOKEN
|
|
34
|
-
? {
|
|
35
|
-
'circle-token': CIRCLE_TOKEN,
|
|
36
|
-
}
|
|
37
|
-
: {};
|
|
38
|
-
const client = axios.create({
|
|
39
|
-
baseURL: 'https://circleci.com/api/v2/',
|
|
40
|
-
timeout: 5000,
|
|
41
|
-
headers,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const fetch = (url, options) => {
|
|
45
|
-
console.log(`GET ${url}`);
|
|
46
|
-
|
|
47
|
-
return client
|
|
48
|
-
.get(url, options)
|
|
49
|
-
.catch(() => client.get(url, options))
|
|
50
|
-
.catch(() => client.get(url, options));
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
getPipeline()
|
|
54
|
-
.then(getWorkflow)
|
|
55
|
-
.then(getPrebuildsJob)
|
|
56
|
-
.then(getPrebuildArtifacts)
|
|
57
|
-
.then(downloadArtifacts)
|
|
58
|
-
.then(validatePrebuilds)
|
|
59
|
-
.then(extractPrebuilds)
|
|
60
|
-
.catch(e => {
|
|
61
|
-
process.exitCode = 1;
|
|
62
|
-
console.error(e);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
function getPipeline() {
|
|
66
|
-
return fetch(
|
|
67
|
-
`project/github/DataDog/pprof-nodejs/pipeline?branch=${branch}`
|
|
68
|
-
).then(response => {
|
|
69
|
-
const pipeline = response.data.items
|
|
70
|
-
.filter(item => item.trigger.type !== 'schedule')
|
|
71
|
-
.find(item => item.vcs.revision === revision);
|
|
72
|
-
|
|
73
|
-
if (!pipeline) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`Unable to find CircleCI pipeline for ${branch}@${revision}.`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return pipeline;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getWorkflow(pipeline) {
|
|
84
|
-
return fetch(`pipeline/${pipeline.id}/workflow`).then(response => {
|
|
85
|
-
const workflows = response.data.items.sort((a, b) =>
|
|
86
|
-
a.stopped_at < b.stopped_at ? 1 : -1
|
|
87
|
-
);
|
|
88
|
-
const workflow = workflows.find(workflow => workflow.name === 'prebuild');
|
|
89
|
-
|
|
90
|
-
if (!workflow) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`Unable to find CircleCI workflow for pipeline ${pipeline.id}.`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!workflow.stopped_at) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Workflow ${workflow.id} is still running for pipeline ${pipeline.id}.`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (workflow.status !== 'success') {
|
|
103
|
-
throw new Error(
|
|
104
|
-
`Aborting because CircleCI workflow ${workflow.id} did not succeed.`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return workflow;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function getPrebuildsJob(workflow) {
|
|
113
|
-
return fetch(`workflow/${workflow.id}/job`).then(response => {
|
|
114
|
-
const job = response.data.items.find(item => item.name === 'prebuilds');
|
|
115
|
-
|
|
116
|
-
if (!job) {
|
|
117
|
-
throw new Error(`Missing prebuild jobs in workflow ${workflow.id}.`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return job;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getPrebuildArtifacts(job) {
|
|
125
|
-
return fetch(
|
|
126
|
-
`project/github/DataDog/pprof-nodejs/${job.job_number}/artifacts`
|
|
127
|
-
).then(response => {
|
|
128
|
-
const artifacts = response.data.items.filter(artifact =>
|
|
129
|
-
/\/prebuilds\.tgz/.test(artifact.url)
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
if (artifacts.length === 0) {
|
|
133
|
-
throw new Error(`Missing artifacts in job ${job.job_number}.`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return artifacts;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function downloadArtifacts(artifacts) {
|
|
141
|
-
const files = artifacts.map(artifact => artifact.url);
|
|
142
|
-
|
|
143
|
-
return Promise.all(files.map(downloadArtifact));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function downloadArtifact(file) {
|
|
147
|
-
return fetch(file, {responseType: 'stream'}).then(response => {
|
|
148
|
-
const parts = file.split('/');
|
|
149
|
-
const basename = os.tmpdir();
|
|
150
|
-
const filename = parts.slice(-1)[0];
|
|
151
|
-
|
|
152
|
-
return new Promise((resolve, reject) => {
|
|
153
|
-
response.data
|
|
154
|
-
.pipe(fs.createWriteStream(path.join(basename, filename)))
|
|
155
|
-
.on('finish', () => resolve())
|
|
156
|
-
.on('error', reject);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function validatePrebuilds() {
|
|
162
|
-
const file = path.join(os.tmpdir(), 'prebuilds.tgz');
|
|
163
|
-
const content = fs.readFileSync(file);
|
|
164
|
-
const sum = fs.readFileSync(path.join(`${file}.sha1`), 'ascii');
|
|
165
|
-
|
|
166
|
-
if (sum !== checksum(content, {algorithm: 'sha256'})) {
|
|
167
|
-
throw new Error('Invalid checksum for "prebuilds.tgz".');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function extractPrebuilds() {
|
|
172
|
-
rimraf.sync('prebuilds');
|
|
173
|
-
|
|
174
|
-
return tar.extract({
|
|
175
|
-
file: path.join(os.tmpdir(), 'prebuilds.tgz'),
|
|
176
|
-
cwd: path.join(__dirname, '..'),
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function exec(command, options) {
|
|
181
|
-
options = Object.assign({stdio: [0, 1, 2]}, options);
|
|
182
|
-
|
|
183
|
-
execSync(`echo "${color.GRAY}$ ${command}${color.NONE}"`, {stdio: [0, 1, 2]});
|
|
184
|
-
|
|
185
|
-
return execSync(command, options);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function execPipe(command, options) {
|
|
189
|
-
return exec(command, Object.assign({stdio: 'pipe'}, options))
|
|
190
|
-
.toString()
|
|
191
|
-
.replace(/\n$/, '');
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function title(str) {
|
|
195
|
-
const options = {stdio: [0, 1, 2]};
|
|
196
|
-
const line = ''.padStart(str.length, '=');
|
|
197
|
-
|
|
198
|
-
execSync(`echo "${color.CYAN}${line}${color.NONE}"`, options);
|
|
199
|
-
execSync(`echo "${color.CYAN}${str}${color.NONE}"`, options);
|
|
200
|
-
execSync(`echo "${color.CYAN}${line}${color.NONE}"`, options);
|
|
201
|
-
}
|