Skip to content

Commit d7f74a4

Browse files
committed
Hide new functionality behind a flag
1 parent fe39100 commit d7f74a4

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

bindings/profilers/wall.cc

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,17 @@ NAN_METHOD(WallProfiler::Start) {
449449
WallProfiler* wallProfiler =
450450
Nan::ObjectWrap::Unwrap<WallProfiler>(info.Holder());
451451

452-
if (info.Length() != 2) {
453-
return Nan::ThrowTypeError("Start must have two arguments.");
452+
if (info.Length() != 3) {
453+
return Nan::ThrowTypeError("Start must have three arguments.");
454454
}
455455
if (!info[0]->IsString()) {
456456
return Nan::ThrowTypeError("Profile name must be a string.");
457457
}
458458
if (!info[1]->IsBoolean()) {
459-
return Nan::ThrowTypeError("Include lines must be a boolean.");
459+
return Nan::ThrowTypeError("Include lines flag must be a boolean.");
460+
}
461+
if (!info[2]->IsBoolean()) {
462+
return Nan::ThrowTypeError("With labels flag must be a boolean.");
460463
}
461464

462465
Local<String> name =
@@ -465,29 +468,34 @@ NAN_METHOD(WallProfiler::Start) {
465468
bool includeLines =
466469
Nan::MaybeLocal<Boolean>(info[1].As<Boolean>()).ToLocalChecked()->Value();
467470

468-
wallProfiler->StartImpl(name, includeLines);
471+
bool withLabels =
472+
Nan::MaybeLocal<Boolean>(info[2].As<Boolean>()).ToLocalChecked()->Value();
469473

470-
#ifdef DD_WALL_USE_SIGPROF
471-
struct sigaction sa, old_sa;
472-
sa.sa_flags = SA_SIGINFO | SA_RESTART;
473-
sa.sa_sigaction = &sighandler;
474-
sigemptyset(&sa.sa_mask);
475-
sigaction(SIGPROF, &sa, &old_sa);
474+
wallProfiler->StartImpl(name, includeLines, withLabels);
476475

477-
// At the end of a cycle start is called before stop,
478-
// at this point old_sa.sa_sigaction is sighandler !
479-
if (!old_handler) {
480-
old_handler = old_sa.sa_sigaction;
476+
#ifdef DD_WALL_USE_SIGPROF
477+
if (withLabels) {
478+
struct sigaction sa, old_sa;
479+
sa.sa_flags = SA_SIGINFO | SA_RESTART;
480+
sa.sa_sigaction = &sighandler;
481+
sigemptyset(&sa.sa_mask);
482+
sigaction(SIGPROF, &sa, &old_sa);
483+
484+
// At the end of a cycle start is called before stop,
485+
// at this point old_sa.sa_sigaction is sighandler !
486+
if (!old_handler) {
487+
old_handler = old_sa.sa_sigaction;
488+
}
481489
}
482490
#endif
483491
}
484492

485-
void WallProfiler::StartImpl(Local<String> name, bool includeLines) {
493+
void WallProfiler::StartImpl(Local<String> name, bool includeLines, bool withLabels) {
486494
if (includeLines) {
487495
GetProfiler()->StartProfiling(
488-
name, CpuProfilingMode::kCallerLineNumbers, true);
496+
name, CpuProfilingMode::kCallerLineNumbers, withLabels);
489497
} else {
490-
GetProfiler()->StartProfiling(name, true);
498+
GetProfiler()->StartProfiling(name, withLabels);
491499
}
492500

493501
last_start = current_start;

bindings/profilers/wall.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class WallProfiler : public Nan::ObjectWrap {
6363
}
6464

6565
void PushContext();
66-
void StartImpl(v8::Local<v8::String> name, bool includeLines);
66+
void StartImpl(v8::Local<v8::String> name, bool includeLines, bool withLabels);
6767
v8::Local<v8::Value> StopImpl(v8::Local<v8::String> name, bool includeLines);
6868

6969
static NAN_METHOD(New);

ts/src/time-profiler.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,49 @@ function ensureRunName(name?: string) {
6262
return name || `pprof-${Date.now()}-${Math.random()}`;
6363
}
6464

65-
// Retained for backwards compatibility with older tracer
65+
// Temporarily retained for backwards compatibility with older tracer
6666
export function start(
6767
intervalMicros: Microseconds = DEFAULT_INTERVAL_MICROS,
6868
name?: string,
6969
sourceMapper?: SourceMapper,
7070
lineNumbers = true
7171
) {
72-
const {stop} = startWithLabels(
72+
const {stop} = startInternal(
7373
intervalMicros,
7474
DEFAULT_DURATION_MILLIS,
7575
name,
7676
sourceMapper,
77-
lineNumbers
77+
lineNumbers,
78+
false
7879
);
7980
return stop;
8081
}
8182

82-
// NOTE: refreshing doesn't work if giving a profile name.
8383
export function startWithLabels(
8484
intervalMicros: Microseconds = DEFAULT_INTERVAL_MICROS,
8585
durationMillis: Milliseconds = DEFAULT_DURATION_MILLIS,
8686
name?: string,
8787
sourceMapper?: SourceMapper,
8888
lineNumbers = true
89+
) {
90+
return startInternal(
91+
intervalMicros,
92+
durationMillis,
93+
name,
94+
sourceMapper,
95+
lineNumbers,
96+
true
97+
)
98+
}
99+
100+
// NOTE: refreshing doesn't work if giving a profile name.
101+
function startInternal(
102+
intervalMicros: Microseconds,
103+
durationMillis: Milliseconds,
104+
name?: string,
105+
sourceMapper?: SourceMapper,
106+
lineNumbers?: boolean,
107+
withLabels?: boolean
89108
) {
90109
const profiler = new TimeProfiler(intervalMicros, durationMillis * 1000);
91110
let runName = start();
@@ -97,7 +116,7 @@ export function startWithLabels(
97116

98117
function start() {
99118
const runName = ensureRunName(name);
100-
profiler.start(runName, lineNumbers);
119+
profiler.start(runName, lineNumbers, withLabels);
101120
return runName;
102121
}
103122

0 commit comments

Comments
 (0)