Skip to content

Commit 8e2f906

Browse files
committed
Suggestions from Nicolas' review, minus the atomic update of profilers map
1 parent d82f6ff commit 8e2f906

4 files changed

Lines changed: 13 additions & 18 deletions

File tree

bindings/profilers/wall.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ LabelSetsByNode WallProfiler::GetLabelSetsByNode(CpuProfile* profile,
363363
return labelSetsByNode;
364364
}
365365
sampleContext = contexts.pop_front();
366-
break; // don't match more than one context to one sample
366+
break; // don't match more than one context to one sample
367367
}
368368
}
369369
}
@@ -373,8 +373,6 @@ LabelSetsByNode WallProfiler::GetLabelSetsByNode(CpuProfile* profile,
373373
return labelSetsByNode;
374374
}
375375

376-
static Nan::Persistent<v8::Function> constructor;
377-
378376
WallProfiler::WallProfiler(int intervalMicros, int durationMicros)
379377
: samplingInterval(intervalMicros),
380378
contexts(durationMicros * 2 / intervalMicros) {}
@@ -438,7 +436,7 @@ NAN_METHOD(WallProfiler::New) {
438436
return Nan::ThrowTypeError("Sample rate must be a number.");
439437
}
440438

441-
if (!info[0]->IsNumber()) {
439+
if (!info[1]->IsNumber()) {
442440
return Nan::ThrowTypeError("Duration must be a number.");
443441
}
444442

@@ -464,8 +462,8 @@ NAN_METHOD(WallProfiler::New) {
464462
obj->Wrap(info.This());
465463
info.GetReturnValue().Set(info.This());
466464
} else {
467-
const int argc = 1;
468-
v8::Local<v8::Value> argv[argc] = {info[0]};
465+
const int argc = 2;
466+
v8::Local<v8::Value> argv[argc] = {info[0], info[1]};
469467
v8::Local<v8::Function> cons = Nan::New(
470468
PerIsolateData::For(info.GetIsolate())->WallProfilerConstructor());
471469
info.GetReturnValue().Set(

bindings/profilers/wall.hh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include <nan.h>
44
#include <v8-profiler.h>
5+
#include <memory>
56
#include <unordered_map>
7+
#include <utility>
68

79
#include "../buffer.hh"
810

@@ -28,10 +30,9 @@ class WallProfiler : public Nan::ObjectWrap {
2830
uint64_t timestamp;
2931

3032
// Needed to initialize ring buffer elements
31-
SampleContext() {}
33+
SampleContext() = default;
3234

33-
SampleContext(std::shared_ptr<v8::Global<v8::Value>> l, uint64_t t)
34-
: labels(l), timestamp(t) {}
35+
SampleContext(const ValuePtr& l, uint64_t t) : labels(l), timestamp(t) {}
3536
};
3637

3738
RingBuffer<SampleContext> contexts;
@@ -58,11 +59,7 @@ class WallProfiler : public Nan::ObjectWrap {
5859

5960
v8::Local<v8::Value> GetLabels(v8::Isolate*);
6061
void SetLabels(v8::Isolate*, v8::Local<v8::Value>);
61-
bool GetLabelsCaptured() {
62-
bool captured = labelsCaptured;
63-
labelsCaptured = false;
64-
return captured;
65-
}
62+
bool GetLabelsCaptured() { return std::exchange(labelsCaptured, false); }
6663

6764
uint64_t PushContext();
6865
void StartImpl(v8::Local<v8::String> name,

ts/src/time-profiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {TimeProfiler} from './time-profiler-bindings';
2222
import {LabelSet} from './v8-types';
2323

2424
const DEFAULT_INTERVAL_MICROS: Microseconds = 1000;
25-
const DEFAULT_DURATION_MILLIS: Milliseconds = 60000;
25+
const DEFAULT_DURATION_MICROS: Microseconds = 60000000;
2626

2727
const majorVersion = process.version.slice(1).split('.').map(Number)[0];
2828

@@ -83,14 +83,14 @@ export function start(
8383

8484
export function startWithLabels(
8585
intervalMicros: Microseconds = DEFAULT_INTERVAL_MICROS,
86-
durationMillis: Milliseconds = DEFAULT_DURATION_MILLIS,
86+
durationMicros: Microseconds = DEFAULT_DURATION_MICROS,
8787
name?: string,
8888
sourceMapper?: SourceMapper,
8989
lineNumbers = true
9090
) {
9191
return startInternal(
9292
intervalMicros,
93-
durationMillis * 1000,
93+
durationMicros,
9494
name,
9595
sourceMapper,
9696
lineNumbers,

ts/test/test-time-profiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('Time Profiler', () => {
5050
const intervalNanos = PROFILE_OPTIONS.intervalMicros * 1_000;
5151
const {stop, setLabels} = time.startWithLabels(
5252
PROFILE_OPTIONS.intervalMicros,
53-
PROFILE_OPTIONS.durationMillis
53+
PROFILE_OPTIONS.durationMillis * 1000
5454
);
5555
const repeats = 3;
5656
// By repeating the test few times, we can also test the overlap behavior.

0 commit comments

Comments
 (0)