summaryrefslogtreecommitdiff
path: root/src/node_worker.cc
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-06-10 15:12:11 -0700
committerAnna Henningsen <anna@addaleax.net>2018-06-20 16:02:36 +0200
commit99e6ecbb17fa9ffef8e77a043e44367810403dbd (patch)
treef6523ebec842cac86f94f1fc11050dea619da271 /src/node_worker.cc
parent3ff1cb955f0af629b9f020aaf1705cb571ecf84b (diff)
downloadandroid-node-v8-99e6ecbb17fa9ffef8e77a043e44367810403dbd.tar.gz
android-node-v8-99e6ecbb17fa9ffef8e77a043e44367810403dbd.tar.bz2
android-node-v8-99e6ecbb17fa9ffef8e77a043e44367810403dbd.zip
workers,trace_events: set thread name for workers
Set the thread name for workers in trace events. Also, use uint64_t for thread_id_ because there's really no reason for those to be doubles PR-URL: https://github.com/nodejs/node/pull/21246 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r--src/node_worker.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 320b6703d4..c628e6295c 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -9,6 +9,8 @@
#include "async_wrap.h"
#include "async_wrap-inl.h"
+#include <string>
+
using v8::ArrayBuffer;
using v8::Context;
using v8::Function;
@@ -30,7 +32,7 @@ namespace worker {
namespace {
-double next_thread_id = 1;
+uint64_t next_thread_id = 1;
Mutex next_thread_id_mutex;
} // anonymous namespace
@@ -44,7 +46,8 @@ Worker::Worker(Environment* env, Local<Object> wrap)
}
wrap->Set(env->context(),
env->thread_id_string(),
- Number::New(env->isolate(), thread_id_)).FromJust();
+ Number::New(env->isolate(),
+ static_cast<double>(thread_id_))).FromJust();
// Set up everything that needs to be set up in the parent environment.
parent_port_ = MessagePort::New(env, env->context());
@@ -112,6 +115,11 @@ bool Worker::is_stopped() const {
}
void Worker::Run() {
+ std::string name = "WorkerThread ";
+ name += std::to_string(thread_id_);
+ TRACE_EVENT_METADATA1(
+ "__metadata", "thread_name", "name",
+ TRACE_STR_COPY(name.c_str()));
MultiIsolatePlatform* platform = isolate_data_->platform();
CHECK_NE(platform, nullptr);
@@ -418,7 +426,8 @@ void InitWorker(Local<Object> target,
auto thread_id_string = FIXED_ONE_BYTE_STRING(env->isolate(), "threadId");
target->Set(env->context(),
thread_id_string,
- Number::New(env->isolate(), env->thread_id())).FromJust();
+ Number::New(env->isolate(),
+ static_cast<double>(env->thread_id()))).FromJust();
}
} // anonymous namespace