Skip to content

Commit c7d61be

Browse files
IlyasShabiszegedi
authored andcommitted
use stop and collect on time profiler (#305)
1 parent 5d72277 commit c7d61be

File tree

6 files changed

+36
-374
lines changed

6 files changed

+36
-374
lines changed

bindings/profilers/wall.cc

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -920,28 +920,6 @@ v8::ProfilerId WallProfiler::StartInternal() {
920920
return result.id;
921921
}
922922

923-
NAN_METHOD(WallProfiler::Stop) {
924-
if (info.Length() != 1) {
925-
return Nan::ThrowTypeError("Stop must have one argument.");
926-
}
927-
if (!info[0]->IsBoolean()) {
928-
return Nan::ThrowTypeError("Restart must be a boolean.");
929-
}
930-
931-
bool restart = info[0].As<Boolean>()->Value();
932-
933-
WallProfiler* wallProfiler =
934-
Nan::ObjectWrap::Unwrap<WallProfiler>(info.This());
935-
936-
v8::Local<v8::Value> profile;
937-
auto err = wallProfiler->StopImpl(restart, profile);
938-
939-
if (!err.success) {
940-
return Nan::ThrowTypeError(err.msg.c_str());
941-
}
942-
info.GetReturnValue().Set(profile);
943-
}
944-
945923
// stopAndCollect(restart, callback): callback result
946924
NAN_METHOD(WallProfiler::StopAndCollect) {
947925
if (info.Length() != 2) {
@@ -1100,20 +1078,6 @@ Result WallProfiler::StopCore(bool restart, ProfileBuilder&& buildProfile) {
11001078
return {};
11011079
}
11021080

1103-
Result WallProfiler::StopImpl(bool restart, v8::Local<v8::Value>& profile) {
1104-
return StopCore(restart,
1105-
[&](const v8::CpuProfile* v8_profile,
1106-
bool hasCpuTime,
1107-
int64_t nonJSThreadsCpuTime,
1108-
ContextsByNode* contextsByNodePtr) {
1109-
profile = TranslateTimeProfile(v8_profile,
1110-
includeLines_,
1111-
contextsByNodePtr,
1112-
hasCpuTime,
1113-
nonJSThreadsCpuTime);
1114-
});
1115-
}
1116-
11171081
Result WallProfiler::StopAndCollectImpl(bool restart,
11181082
v8::Local<v8::Function> callback,
11191083
v8::Local<v8::Value>& result) {
@@ -1148,7 +1112,6 @@ NAN_MODULE_INIT(WallProfiler::Init) {
11481112
SetContext);
11491113

11501114
Nan::SetPrototypeMethod(tpl, "start", Start);
1151-
Nan::SetPrototypeMethod(tpl, "stop", Stop);
11521115
Nan::SetPrototypeMethod(tpl, "stopAndCollect", StopAndCollect);
11531116
Nan::SetPrototypeMethod(tpl, "dispose", Dispose);
11541117
Nan::SetPrototypeMethod(tpl,

bindings/profilers/wall.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class WallProfiler : public Nan::ObjectWrap {
157157
v8::ProfilerId StartInternal();
158158
template <typename ProfileBuilder>
159159
Result StopCore(bool restart, ProfileBuilder&& buildProfile);
160-
Result StopImpl(bool restart, v8::Local<v8::Value>& profile);
161160
Result StopAndCollectImpl(bool restart,
162161
v8::Local<v8::Function> callback,
163162
v8::Local<v8::Value>& result);
@@ -189,7 +188,6 @@ class WallProfiler : public Nan::ObjectWrap {
189188

190189
static NAN_METHOD(New);
191190
static NAN_METHOD(Start);
192-
static NAN_METHOD(Stop);
193191
static NAN_METHOD(StopAndCollect);
194192
static NAN_METHOD(V8ProfilerStuckEventLoopDetected);
195193
static NAN_METHOD(Dispose);

ts/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const time = {
3434
profile: timeProfiler.profile,
3535
start: timeProfiler.start,
3636
stop: timeProfiler.stop,
37-
profileV2: timeProfiler.profileV2,
3837
getContext: timeProfiler.getContext,
3938
setContext: timeProfiler.setContext,
4039
runWithContext: timeProfiler.runWithContext,

ts/src/time-profiler.ts

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Microseconds = number;
4343
type Milliseconds = number;
4444

4545
type NativeTimeProfiler = InstanceType<typeof TimeProfiler> & {
46-
stopAndCollect?: <T>(
46+
stopAndCollect: <T>(
4747
restart: boolean,
4848
callback: (profile: TimeProfile) => T,
4949
) => T;
@@ -65,7 +65,7 @@ function handleStopRestart() {
6565
// a loop eating 100% CPU, leading to empty profiles.
6666
// Fully stop and restart the profiler to reset the profile to a valid state.
6767
if (gV8ProfilerStuckEventLoopDetected > 0) {
68-
gProfiler.stop(false);
68+
gProfiler.stopAndCollect(false, () => undefined);
6969
gProfiler.start();
7070
}
7171
}
@@ -126,13 +126,6 @@ export async function profile(options: TimeProfilerOptions = {}) {
126126
return stop();
127127
}
128128

129-
export async function profileV2(options: TimeProfilerOptions = {}) {
130-
options = {...DEFAULT_OPTIONS, ...options};
131-
start(options);
132-
await setTimeout(options.durationMillis!);
133-
return stopV2();
134-
}
135-
136129
// Temporarily retained for backwards compatibility with older tracer
137130
export function start(options: TimeProfilerOptions = {}) {
138131
options = {...DEFAULT_OPTIONS, ...options};
@@ -155,39 +148,11 @@ export function start(options: TimeProfilerOptions = {}) {
155148
}
156149
}
157150

158-
export function stop(
159-
restart = false,
160-
generateLabels?: GenerateTimeLabelsFunction,
161-
lowCardinalityLabels?: string[],
162-
) {
163-
if (!gProfiler) {
164-
throw new Error('Wall profiler is not started');
165-
}
166-
167-
const profile = gProfiler.stop(restart);
168-
if (restart) {
169-
handleStopRestart();
170-
} else {
171-
handleStopNoRestart();
172-
}
173-
174-
const serializedProfile = serializeTimeProfile(
175-
profile,
176-
gIntervalMicros,
177-
gSourceMapper,
178-
true,
179-
generateLabels,
180-
lowCardinalityLabels,
181-
);
182-
return serializedProfile;
183-
}
184-
185151
/**
186-
* Same as stop() but uses the lazy callback path: serialization happens inside
187-
* a native callback while the V8 profile is still alive.
188-
* This reduces memory overhead.
152+
* Serializes the profile inside a native callback while the V8 profile is
153+
* still alive. This reduces memory overhead.
189154
*/
190-
export function stopV2(
155+
export function stop(
191156
restart = false,
192157
generateLabels?: GenerateTimeLabelsFunction,
193158
lowCardinalityLabels?: string[],

0 commit comments

Comments
 (0)