Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-01-16 20:19:10 +0300
committerShelley Vohr <shelley.vohr@gmail.com>2020-02-17 21:54:33 +0300
commit1bcf2f942383e14181bf3118123ca7af57384c87 (patch)
tree355af5fd2459c8d47c70cee96edc9e14bb91eb0c /src/node_report.cc
parentf56de5a3b43a224bac6de2fee8d2d6c3a1e4a079 (diff)
report: add support for Workers
Include a report for each sub-Worker of the current Node.js instance. This adds a feature that is necessary for eventually making the report feature stable, as was discussed during the last collaborator summit. Refs: https://github.com/openjs-foundation/summit/pull/240 PR-URL: https://github.com/nodejs/node/pull/31386 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_report.cc')
-rw-r--r--src/node_report.cc43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/node_report.cc b/src/node_report.cc
index ddeb216c82d..9b32352326b 100644
--- a/src/node_report.cc
+++ b/src/node_report.cc
@@ -4,6 +4,8 @@
#include "diagnosticfilename-inl.h"
#include "node_internals.h"
#include "node_metadata.h"
+#include "node_mutex.h"
+#include "node_worker.h"
#include "util.h"
#ifdef _WIN32
@@ -19,18 +21,20 @@
#include <cwctype>
#include <fstream>
-constexpr int NODE_REPORT_VERSION = 1;
+constexpr int NODE_REPORT_VERSION = 2;
constexpr int NANOS_PER_SEC = 1000 * 1000 * 1000;
constexpr double SEC_PER_MICROS = 1e-6;
namespace report {
using node::arraysize;
+using node::ConditionVariable;
using node::DiagnosticFilename;
using node::Environment;
using node::Mutex;
using node::NativeSymbolDebuggingContext;
using node::PerIsolateOptions;
using node::TIME_TYPE;
+using node::worker::Worker;
using v8::HeapSpaceStatistics;
using v8::HeapStatistics;
using v8::Isolate;
@@ -210,6 +214,10 @@ static void WriteNodeReport(Isolate* isolate,
// Report native process ID
writer.json_keyvalue("processId", pid);
+ if (env != nullptr)
+ writer.json_keyvalue("threadId", env->thread_id());
+ else
+ writer.json_keyvalue("threadId", JSONWriter::Null{});
{
// Report the process cwd.
@@ -259,6 +267,39 @@ static void WriteNodeReport(Isolate* isolate,
writer.json_arrayend();
+ writer.json_arraystart("workers");
+ if (env != nullptr) {
+ Mutex workers_mutex;
+ ConditionVariable notify;
+ std::vector<std::string> worker_infos;
+ size_t expected_results = 0;
+
+ env->ForEachWorker([&](Worker* w) {
+ expected_results += w->RequestInterrupt([&](Environment* env) {
+ std::ostringstream os;
+
+ GetNodeReport(env->isolate(),
+ env,
+ "Worker thread subreport",
+ trigger,
+ Local<String>(),
+ os);
+
+ Mutex::ScopedLock lock(workers_mutex);
+ worker_infos.emplace_back(os.str());
+ notify.Signal(lock);
+ });
+ });
+
+ Mutex::ScopedLock lock(workers_mutex);
+ worker_infos.reserve(expected_results);
+ while (worker_infos.size() < expected_results)
+ notify.Wait(lock);
+ for (const std::string& worker_info : worker_infos)
+ writer.json_element(JSONWriter::ForeignJSON { worker_info });
+ }
+ writer.json_arrayend();
+
// Report operating system information
PrintSystemInformation(&writer);