@@ -915,9 +915,6 @@ void Worker::StartCpuProfile(const FunctionCallbackInfo<Value>& args) {
915
915
ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
916
916
Environment* env = w->env ();
917
917
918
- CHECK (args[0 ]->IsString ());
919
- node::Utf8Value name (env->isolate (), args[0 ]);
920
-
921
918
AsyncHooks::DefaultTriggerAsyncIdScope trigger_id_scope (w);
922
919
Local<Object> wrap;
923
920
if (!env->worker_cpu_profile_taker_template ()
@@ -930,25 +927,23 @@ void Worker::StartCpuProfile(const FunctionCallbackInfo<Value>& args) {
930
927
MakeDetachedBaseObject<WorkerCpuProfileTaker>(env, wrap);
931
928
932
929
bool scheduled = w->RequestInterrupt ([taker = std::move (taker),
933
- name = name.ToString (),
934
930
env](Environment* worker_env) mutable {
935
- CpuProfilingResult result = worker_env->StartCpuProfile (name );
931
+ CpuProfilingResult result = worker_env->StartCpuProfile ();
936
932
env->SetImmediateThreadsafe (
937
- [taker = std::move (taker),
938
- status = result.status ](Environment* env) mutable {
933
+ [taker = std::move (taker), result = result](Environment* env) mutable {
939
934
Isolate* isolate = env->isolate ();
940
935
HandleScope handle_scope (isolate);
941
936
Context::Scope context_scope (env->context ());
942
937
AsyncHooks::DefaultTriggerAsyncIdScope trigger_id_scope (taker.get ());
943
938
Local<Value> argv[] = {
944
- Null (isolate), // error
939
+ Null (isolate), // error
940
+ Undefined (isolate), // profile id
945
941
};
946
- if (status == CpuProfilingStatus::kAlreadyStarted ) {
947
- argv[0 ] = ERR_CPU_PROFILE_ALREADY_STARTED (
948
- isolate, " CPU profile already started" );
949
- } else if (status == CpuProfilingStatus::kErrorTooManyProfilers ) {
942
+ if (result.status == CpuProfilingStatus::kErrorTooManyProfilers ) {
950
943
argv[0 ] = ERR_CPU_PROFILE_TOO_MANY (
951
944
isolate, " There are too many CPU profiles" );
945
+ } else if (result.status == CpuProfilingStatus::kStarted ) {
946
+ argv[1 ] = Number::New (isolate, result.id );
952
947
}
953
948
taker->MakeCallback (env->ondone_string (), arraysize (argv), argv);
954
949
},
@@ -965,8 +960,8 @@ void Worker::StopCpuProfile(const FunctionCallbackInfo<Value>& args) {
965
960
ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
966
961
967
962
Environment* env = w->env ();
968
- CHECK (args[0 ]->IsString ());
969
- node::Utf8Value name (env->isolate (), args[ 0 ] );
963
+ CHECK (args[0 ]->IsUint32 ());
964
+ uint32_t profile_id = args[ 0 ]-> Uint32Value (env->context ()). FromJust ( );
970
965
971
966
AsyncHooks::DefaultTriggerAsyncIdScope trigger_id_scope (w);
972
967
Local<Object> wrap;
@@ -980,11 +975,11 @@ void Worker::StopCpuProfile(const FunctionCallbackInfo<Value>& args) {
980
975
MakeDetachedBaseObject<WorkerCpuProfileTaker>(env, wrap);
981
976
982
977
bool scheduled = w->RequestInterrupt ([taker = std::move (taker),
983
- name = name. ToString () ,
978
+ profile_id = profile_id ,
984
979
env](Environment* worker_env) mutable {
985
980
bool found = false ;
986
981
auto json_out_stream = std::make_unique<node::JSONOutputStream>();
987
- CpuProfile* profile = worker_env->StopCpuProfile (name );
982
+ CpuProfile* profile = worker_env->StopCpuProfile (profile_id );
988
983
if (profile) {
989
984
profile->Serialize (json_out_stream.get (),
990
985
CpuProfile::SerializationFormat::kJSON );
0 commit comments