GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_report.cc Lines: 299 301 99.3 %
Date: 2019-10-06 22:30:00 Branches: 71 98 72.4 %

Line Branch Exec Source
1
#include "env-inl.h"
2
#include "node_report.h"
3
#include "debug_utils.h"
4
#include "diagnosticfilename-inl.h"
5
#include "node_internals.h"
6
#include "node_metadata.h"
7
#include "util.h"
8
9
#ifdef _WIN32
10
#include <Windows.h>
11
#else  // !_WIN32
12
#include <sys/resource.h>
13
#include <cxxabi.h>
14
#include <dlfcn.h>
15
#endif
16
17
#include <cstring>
18
#include <ctime>
19
#include <cwctype>
20
#include <fstream>
21
#include <iomanip>
22
23
constexpr int NODE_REPORT_VERSION = 1;
24
constexpr int NANOS_PER_SEC = 1000 * 1000 * 1000;
25
constexpr double SEC_PER_MICROS = 1e-6;
26
27
namespace report {
28
using node::arraysize;
29
using node::DiagnosticFilename;
30
using node::Environment;
31
using node::Mutex;
32
using node::NativeSymbolDebuggingContext;
33
using node::PerIsolateOptions;
34
using node::TIME_TYPE;
35
using v8::HeapSpaceStatistics;
36
using v8::HeapStatistics;
37
using v8::Isolate;
38
using v8::Local;
39
using v8::Number;
40
using v8::StackTrace;
41
using v8::String;
42
using v8::V8;
43
using v8::Value;
44
45
// Internal/static function declarations
46
static void WriteNodeReport(Isolate* isolate,
47
                            Environment* env,
48
                            const char* message,
49
                            const char* trigger,
50
                            const std::string& filename,
51
                            std::ostream& out,
52
                            Local<String> stackstr);
53
static void PrintVersionInformation(JSONWriter* writer);
54
static void PrintJavaScriptStack(JSONWriter* writer,
55
                                 Isolate* isolate,
56
                                 Local<String> stackstr,
57
                                 const char* trigger);
58
static void PrintNativeStack(JSONWriter* writer);
59
static void PrintResourceUsage(JSONWriter* writer);
60
static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate);
61
static void PrintSystemInformation(JSONWriter* writer);
62
static void PrintLoadedLibraries(JSONWriter* writer);
63
static void PrintComponentVersions(JSONWriter* writer);
64
static void PrintRelease(JSONWriter* writer);
65
static void PrintCpuInfo(JSONWriter* writer);
66
static void PrintNetworkInterfaceInfo(JSONWriter* writer);
67
68
// External function to trigger a report, writing to file.
69
// The 'name' parameter is in/out: an input filename is used
70
// if supplied, and the actual filename is returned.
71
11
std::string TriggerNodeReport(Isolate* isolate,
72
                              Environment* env,
73
                              const char* message,
74
                              const char* trigger,
75
                              const std::string& name,
76
                              Local<String> stackstr) {
77
11
  std::string filename;
78
22
  std::shared_ptr<PerIsolateOptions> options;
79
11
  if (env != nullptr) options = env->isolate_data()->options();
80
81
  // Determine the required report filename. In order of priority:
82
  //   1) supplied on API 2) configured on startup 3) default generated
83
11
  if (!name.empty()) {
84
    // Filename was specified as API parameter.
85
4
    filename = name;
86

7
  } else if (env != nullptr && options->report_filename.length() > 0) {
87
    // File name was supplied via start-up option.
88
1
    filename = options->report_filename;
89
  } else {
90
12
    filename = *DiagnosticFilename(env != nullptr ? env->thread_id() : 0,
91
6
                                   "report", "json");
92
  }
93
94
  // Open the report file stream for writing. Supports stdout/err,
95
  // user-specified or (default) generated name
96
22
  std::ofstream outfile;
97
  std::ostream* outstream;
98
11
  if (filename == "stdout") {
99
1
    outstream = &std::cout;
100
10
  } else if (filename == "stderr") {
101
1
    outstream = &std::cerr;
102
  } else {
103
    // Regular file. Append filename to directory path if one was specified
104

9
    if (env != nullptr && options->report_directory.length() > 0) {
105
9
      std::string pathname = options->report_directory;
106
9
      pathname += node::kPathSeparator;
107
9
      pathname += filename;
108
9
      outfile.open(pathname, std::ios::out | std::ios::binary);
109
    } else {
110
      outfile.open(filename, std::ios::out | std::ios::binary);
111
    }
112
    // Check for errors on the file open
113
9
    if (!outfile.is_open()) {
114
1
      std::cerr << std::endl
115
1
                << "Failed to open Node.js report file: " << filename;
116
117

1
      if (env != nullptr && options->report_directory.length() > 0)
118
1
        std::cerr << " directory: " << options->report_directory;
119
120
1
      std::cerr << " (errno: " << errno << ")" << std::endl;
121
1
      return "";
122
    }
123
8
    outstream = &outfile;
124
8
    std::cerr << std::endl << "Writing Node.js report to file: " << filename;
125
  }
126
127
  WriteNodeReport(isolate, env, message, trigger, filename, *outstream,
128
10
                  stackstr);
129
130
  // Do not close stdout/stderr, only close files we opened.
131
10
  if (outfile.is_open()) {
132
8
    outfile.close();
133
  }
134
135
10
  std::cerr << std::endl << "Node.js report completed" << std::endl;
136
21
  return filename;
137
}
138
139
// External function to trigger a report, writing to a supplied stream.
140
5
void GetNodeReport(Isolate* isolate,
141
                   Environment* env,
142
                   const char* message,
143
                   const char* trigger,
144
                   Local<String> stackstr,
145
                   std::ostream& out) {
146
5
  WriteNodeReport(isolate, env, message, trigger, "", out, stackstr);
147
5
}
148
149
// Internal function to coordinate and write the various
150
// sections of the report to the supplied stream
151
15
static void WriteNodeReport(Isolate* isolate,
152
                            Environment* env,
153
                            const char* message,
154
                            const char* trigger,
155
                            const std::string& filename,
156
                            std::ostream& out,
157
                            Local<String> stackstr) {
158
  // Obtain the current time and the pid.
159
  TIME_TYPE tm_struct;
160
15
  DiagnosticFilename::LocalTime(&tm_struct);
161
15
  uv_pid_t pid = uv_os_getpid();
162
163
  // Save formatting for output stream.
164
15
  std::ios old_state(nullptr);
165
15
  old_state.copyfmt(out);
166
167
  // File stream opened OK, now start printing the report content:
168
  // the title and header information (event, filename, timestamp and pid)
169
170
15
  JSONWriter writer(out);
171
15
  writer.json_start();
172
15
  writer.json_objectstart("header");
173
15
  writer.json_keyvalue("reportVersion", NODE_REPORT_VERSION);
174
15
  writer.json_keyvalue("event", message);
175
15
  writer.json_keyvalue("trigger", trigger);
176
15
  if (!filename.empty())
177
10
    writer.json_keyvalue("filename", filename);
178
  else
179
5
    writer.json_keyvalue("filename", JSONWriter::Null{});
180
181
  // Report dump event and module load date/time stamps
182
  char timebuf[64];
183
#ifdef _WIN32
184
  snprintf(timebuf,
185
           sizeof(timebuf),
186
           "%4d-%02d-%02dT%02d:%02d:%02dZ",
187
           tm_struct.wYear,
188
           tm_struct.wMonth,
189
           tm_struct.wDay,
190
           tm_struct.wHour,
191
           tm_struct.wMinute,
192
           tm_struct.wSecond);
193
  writer.json_keyvalue("dumpEventTime", timebuf);
194
#else  // UNIX, OSX
195
  snprintf(timebuf,
196
           sizeof(timebuf),
197
           "%4d-%02d-%02dT%02d:%02d:%02dZ",
198
           tm_struct.tm_year + 1900,
199
           tm_struct.tm_mon + 1,
200
           tm_struct.tm_mday,
201
           tm_struct.tm_hour,
202
           tm_struct.tm_min,
203
15
           tm_struct.tm_sec);
204
15
  writer.json_keyvalue("dumpEventTime", timebuf);
205
#endif
206
207
  uv_timeval64_t ts;
208
15
  if (uv_gettimeofday(&ts) == 0) {
209
    writer.json_keyvalue("dumpEventTimeStamp",
210
15
                         std::to_string(ts.tv_sec * 1000 + ts.tv_usec / 1000));
211
  }
212
213
  // Report native process ID
214
15
  writer.json_keyvalue("processId", pid);
215
216
  {
217
    // Report the process cwd.
218
    char buf[PATH_MAX_BYTES];
219
15
    size_t cwd_size = sizeof(buf);
220
15
    if (uv_cwd(buf, &cwd_size) == 0)
221
15
      writer.json_keyvalue("cwd", buf);
222
  }
223
224
  // Report out the command line.
225
15
  if (!node::per_process::cli_options->cmdline.empty()) {
226
15
    writer.json_arraystart("commandLine");
227
65
    for (const std::string& arg : node::per_process::cli_options->cmdline) {
228
50
      writer.json_element(arg);
229
    }
230
15
    writer.json_arrayend();
231
  }
232
233
  // Report Node.js and OS version information
234
15
  PrintVersionInformation(&writer);
235
15
  writer.json_objectend();
236
237
  // Report summary JavaScript stack backtrace
238
15
  PrintJavaScriptStack(&writer, isolate, stackstr, trigger);
239
240
  // Report native stack backtrace
241
15
  PrintNativeStack(&writer);
242
243
  // Report V8 Heap and Garbage Collector information
244
15
  PrintGCStatistics(&writer, isolate);
245
246
  // Report OS and current thread resource usage
247
15
  PrintResourceUsage(&writer);
248
249
15
  writer.json_arraystart("libuv");
250
15
  if (env != nullptr) {
251
15
    uv_walk(env->event_loop(), WalkHandle, static_cast<void*>(&writer));
252
253
15
    writer.json_start();
254
15
    writer.json_keyvalue("type", "loop");
255
    writer.json_keyvalue("is_active",
256
15
        static_cast<bool>(uv_loop_alive(env->event_loop())));
257
    writer.json_keyvalue("address",
258
15
        ValueToHexString(reinterpret_cast<int64_t>(env->event_loop())));
259
15
    writer.json_end();
260
  }
261
262
15
  writer.json_arrayend();
263
264
  // Report operating system information
265
15
  PrintSystemInformation(&writer);
266
267
15
  writer.json_objectend();
268
269
  // Restore output stream formatting.
270
15
  out.copyfmt(old_state);
271
15
}
272
273
// Report Node.js version, OS version and machine information.
274
15
static void PrintVersionInformation(JSONWriter* writer) {
275
15
  std::ostringstream buf;
276
  // Report Node version
277
15
  buf << "v" << NODE_VERSION_STRING;
278
15
  writer->json_keyvalue("nodejsVersion", buf.str());
279
15
  buf.str("");
280
281
#ifndef _WIN32
282
  // Report compiler and runtime glibc versions where possible.
283
  const char* (*libc_version)();
284
  *(reinterpret_cast<void**>(&libc_version)) =
285
15
      dlsym(RTLD_DEFAULT, "gnu_get_libc_version");
286
15
  if (libc_version != nullptr)
287
15
    writer->json_keyvalue("glibcVersionRuntime", (*libc_version)());
288
#endif /* _WIN32 */
289
290
#ifdef __GLIBC__
291
15
  buf << __GLIBC__ << "." << __GLIBC_MINOR__;
292
15
  writer->json_keyvalue("glibcVersionCompiler", buf.str());
293
15
  buf.str("");
294
#endif
295
296
  // Report Process word size
297
15
  writer->json_keyvalue("wordSize", sizeof(void*) * 8);
298
15
  writer->json_keyvalue("arch", node::per_process::metadata.arch);
299
15
  writer->json_keyvalue("platform", node::per_process::metadata.platform);
300
301
  // Report deps component versions
302
15
  PrintComponentVersions(writer);
303
304
  // Report release metadata.
305
15
  PrintRelease(writer);
306
307
  // Report operating system and machine information
308
  uv_utsname_t os_info;
309
310
15
  if (uv_os_uname(&os_info) == 0) {
311
15
    writer->json_keyvalue("osName", os_info.sysname);
312
15
    writer->json_keyvalue("osRelease", os_info.release);
313
15
    writer->json_keyvalue("osVersion", os_info.version);
314
15
    writer->json_keyvalue("osMachine", os_info.machine);
315
  }
316
317
15
  PrintCpuInfo(writer);
318
15
  PrintNetworkInterfaceInfo(writer);
319
320
  char host[UV_MAXHOSTNAMESIZE];
321
15
  size_t host_size = sizeof(host);
322
323
15
  if (uv_os_gethostname(host, &host_size) == 0)
324
15
    writer->json_keyvalue("host", host);
325
15
}
326
327
// Report CPU info
328
15
static void PrintCpuInfo(JSONWriter* writer) {
329
  uv_cpu_info_t* cpu_info;
330
  int count;
331
15
  if (uv_cpu_info(&cpu_info, &count) == 0) {
332
15
    writer->json_arraystart("cpus");
333
135
    for (int i = 0; i < count; i++) {
334
120
      writer->json_start();
335
120
      writer->json_keyvalue("model", cpu_info[i].model);
336
120
      writer->json_keyvalue("speed", cpu_info[i].speed);
337
120
      writer->json_keyvalue("user", cpu_info[i].cpu_times.user);
338
120
      writer->json_keyvalue("nice", cpu_info[i].cpu_times.nice);
339
120
      writer->json_keyvalue("sys", cpu_info[i].cpu_times.sys);
340
120
      writer->json_keyvalue("idle", cpu_info[i].cpu_times.idle);
341
120
      writer->json_keyvalue("irq", cpu_info[i].cpu_times.irq);
342
120
      writer->json_end();
343
    }
344
15
    writer->json_arrayend();
345
15
    uv_free_cpu_info(cpu_info, count);
346
  }
347
15
}
348
349
15
static void PrintNetworkInterfaceInfo(JSONWriter* writer) {
350
  uv_interface_address_t* interfaces;
351
  char ip[INET6_ADDRSTRLEN];
352
  char netmask[INET6_ADDRSTRLEN];
353
  char mac[18];
354
  int count;
355
356
15
  if (uv_interface_addresses(&interfaces, &count) == 0) {
357
15
    writer->json_arraystart("networkInterfaces");
358
359
105
    for (int i = 0; i < count; i++) {
360
90
      writer->json_start();
361
90
      writer->json_keyvalue("name", interfaces[i].name);
362
90
      writer->json_keyvalue("internal", !!interfaces[i].is_internal);
363
      snprintf(mac,
364
               sizeof(mac),
365
               "%02x:%02x:%02x:%02x:%02x:%02x",
366
90
               static_cast<unsigned char>(interfaces[i].phys_addr[0]),
367
90
               static_cast<unsigned char>(interfaces[i].phys_addr[1]),
368
90
               static_cast<unsigned char>(interfaces[i].phys_addr[2]),
369
90
               static_cast<unsigned char>(interfaces[i].phys_addr[3]),
370
90
               static_cast<unsigned char>(interfaces[i].phys_addr[4]),
371
540
               static_cast<unsigned char>(interfaces[i].phys_addr[5]));
372
90
      writer->json_keyvalue("mac", mac);
373
374
90
      if (interfaces[i].address.address4.sin_family == AF_INET) {
375
45
        uv_ip4_name(&interfaces[i].address.address4, ip, sizeof(ip));
376
45
        uv_ip4_name(&interfaces[i].netmask.netmask4, netmask, sizeof(netmask));
377
45
        writer->json_keyvalue("address", ip);
378
45
        writer->json_keyvalue("netmask", netmask);
379
45
        writer->json_keyvalue("family", "IPv4");
380
45
      } else if (interfaces[i].address.address4.sin_family == AF_INET6) {
381
45
        uv_ip6_name(&interfaces[i].address.address6, ip, sizeof(ip));
382
45
        uv_ip6_name(&interfaces[i].netmask.netmask6, netmask, sizeof(netmask));
383
45
        writer->json_keyvalue("address", ip);
384
45
        writer->json_keyvalue("netmask", netmask);
385
45
        writer->json_keyvalue("family", "IPv6");
386
        writer->json_keyvalue("scopeid",
387
45
                              interfaces[i].address.address6.sin6_scope_id);
388
      } else {
389
        writer->json_keyvalue("family", "unknown");
390
      }
391
392
90
      writer->json_end();
393
    }
394
395
15
    writer->json_arrayend();
396
15
    uv_free_interface_addresses(interfaces, count);
397
  }
398
15
}
399
400
// Report the JavaScript stack.
401
15
static void PrintJavaScriptStack(JSONWriter* writer,
402
                                 Isolate* isolate,
403
                                 Local<String> stackstr,
404
                                 const char* trigger) {
405
15
  writer->json_objectstart("javascriptStack");
406
407
15
  std::string ss;
408

30
  if ((!strcmp(trigger, "FatalError")) ||
409
15
      (!strcmp(trigger, "Signal"))) {
410
1
    ss = "No stack.\nUnavailable.\n";
411
  } else {
412
14
    String::Utf8Value sv(isolate, stackstr);
413
14
    ss = std::string(*sv, sv.length());
414
  }
415
15
  int line = ss.find('\n');
416
15
  if (line == -1) {
417
2
    writer->json_keyvalue("message", ss);
418
  } else {
419
13
    std::string l = ss.substr(0, line);
420
13
    writer->json_keyvalue("message", l);
421
13
    writer->json_arraystart("stack");
422
13
    ss = ss.substr(line + 1);
423
13
    line = ss.find('\n');
424
104
    while (line != -1) {
425
78
      l = ss.substr(0, line);
426
386
      l.erase(l.begin(), std::find_if(l.begin(), l.end(), [](int ch) {
427
386
                return !std::iswspace(ch);
428
464
              }));
429
78
      writer->json_element(l);
430
78
      ss = ss.substr(line + 1);
431
78
      line = ss.find('\n');
432
    }
433
13
    writer->json_arrayend();
434
  }
435
15
  writer->json_objectend();
436
15
}
437
438
// Report a native stack backtrace
439
15
static void PrintNativeStack(JSONWriter* writer) {
440
15
  auto sym_ctx = NativeSymbolDebuggingContext::New();
441
  void* frames[256];
442
15
  const int size = sym_ctx->GetStackTrace(frames, arraysize(frames));
443
15
  writer->json_arraystart("nativeStack");
444
  int i;
445
135
  for (i = 1; i < size; i++) {
446
120
    void* frame = frames[i];
447
120
    writer->json_start();
448
    writer->json_keyvalue("pc",
449
120
                          ValueToHexString(reinterpret_cast<uintptr_t>(frame)));
450
120
    writer->json_keyvalue("symbol", sym_ctx->LookupSymbol(frame).Display());
451
120
    writer->json_end();
452
  }
453
15
  writer->json_arrayend();
454
15
}
455
456
// Report V8 JavaScript heap information.
457
// This uses the existing V8 HeapStatistics and HeapSpaceStatistics APIs.
458
// The isolate->GetGCStatistics(&heap_stats) internal V8 API could potentially
459
// provide some more useful information - the GC history and the handle counts
460
15
static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate) {
461
15
  HeapStatistics v8_heap_stats;
462
15
  isolate->GetHeapStatistics(&v8_heap_stats);
463
15
  HeapSpaceStatistics v8_heap_space_stats;
464
465
15
  writer->json_objectstart("javascriptHeap");
466
15
  writer->json_keyvalue("totalMemory", v8_heap_stats.total_heap_size());
467
  writer->json_keyvalue("totalCommittedMemory",
468
15
                        v8_heap_stats.total_physical_size());
469
15
  writer->json_keyvalue("usedMemory", v8_heap_stats.used_heap_size());
470
  writer->json_keyvalue("availableMemory",
471
15
                        v8_heap_stats.total_available_size());
472
15
  writer->json_keyvalue("memoryLimit", v8_heap_stats.heap_size_limit());
473
474
15
  writer->json_objectstart("heapSpaces");
475
  // Loop through heap spaces
476
135
  for (size_t i = 0; i < isolate->NumberOfHeapSpaces(); i++) {
477
120
    isolate->GetHeapSpaceStatistics(&v8_heap_space_stats, i);
478
120
    writer->json_objectstart(v8_heap_space_stats.space_name());
479
120
    writer->json_keyvalue("memorySize", v8_heap_space_stats.space_size());
480
    writer->json_keyvalue(
481
        "committedMemory",
482
120
        v8_heap_space_stats.physical_space_size());
483
    writer->json_keyvalue(
484
        "capacity",
485
240
        v8_heap_space_stats.space_used_size() +
486
240
            v8_heap_space_stats.space_available_size());
487
120
    writer->json_keyvalue("used", v8_heap_space_stats.space_used_size());
488
    writer->json_keyvalue(
489
120
        "available", v8_heap_space_stats.space_available_size());
490
120
    writer->json_objectend();
491
  }
492
493
15
  writer->json_objectend();
494
15
  writer->json_objectend();
495
15
}
496
497
15
static void PrintResourceUsage(JSONWriter* writer) {
498
  // Get process uptime in seconds
499
  uint64_t uptime =
500
15
      (uv_hrtime() - node::per_process::node_start_time) / (NANOS_PER_SEC);
501
15
  if (uptime == 0) uptime = 1;  // avoid division by zero.
502
503
  // Process and current thread usage statistics
504
  uv_rusage_t rusage;
505
15
  writer->json_objectstart("resourceUsage");
506
15
  if (uv_getrusage(&rusage) == 0) {
507
    double user_cpu =
508
15
        rusage.ru_utime.tv_sec + SEC_PER_MICROS * rusage.ru_utime.tv_usec;
509
    double kernel_cpu =
510
15
        rusage.ru_stime.tv_sec + SEC_PER_MICROS * rusage.ru_stime.tv_usec;
511
15
    writer->json_keyvalue("userCpuSeconds", user_cpu);
512
15
    writer->json_keyvalue("kernelCpuSeconds", kernel_cpu);
513
15
    double cpu_abs = user_cpu + kernel_cpu;
514
15
    double cpu_percentage = (cpu_abs / uptime) * 100.0;
515
15
    writer->json_keyvalue("cpuConsumptionPercent", cpu_percentage);
516
15
    writer->json_keyvalue("maxRss", rusage.ru_maxrss * 1024);
517
15
    writer->json_objectstart("pageFaults");
518
15
    writer->json_keyvalue("IORequired", rusage.ru_majflt);
519
15
    writer->json_keyvalue("IONotRequired", rusage.ru_minflt);
520
15
    writer->json_objectend();
521
15
    writer->json_objectstart("fsActivity");
522
15
    writer->json_keyvalue("reads", rusage.ru_inblock);
523
15
    writer->json_keyvalue("writes", rusage.ru_oublock);
524
15
    writer->json_objectend();
525
  }
526
15
  writer->json_objectend();
527
#ifdef RUSAGE_THREAD
528
  struct rusage stats;
529
15
  if (getrusage(RUSAGE_THREAD, &stats) == 0) {
530
15
    writer->json_objectstart("uvthreadResourceUsage");
531
    double user_cpu =
532
15
        stats.ru_utime.tv_sec + SEC_PER_MICROS * stats.ru_utime.tv_usec;
533
    double kernel_cpu =
534
15
        stats.ru_stime.tv_sec + SEC_PER_MICROS * stats.ru_stime.tv_usec;
535
15
    writer->json_keyvalue("userCpuSeconds", user_cpu);
536
15
    writer->json_keyvalue("kernelCpuSeconds", kernel_cpu);
537
15
    double cpu_abs = user_cpu + kernel_cpu;
538
15
    double cpu_percentage = (cpu_abs / uptime) * 100.0;
539
15
    writer->json_keyvalue("cpuConsumptionPercent", cpu_percentage);
540
15
    writer->json_objectstart("fsActivity");
541
15
    writer->json_keyvalue("reads", stats.ru_inblock);
542
15
    writer->json_keyvalue("writes", stats.ru_oublock);
543
15
    writer->json_objectend();
544
15
    writer->json_objectend();
545
  }
546
#endif
547
15
}
548
549
// Report operating system information.
550
15
static void PrintSystemInformation(JSONWriter* writer) {
551
  uv_env_item_t* envitems;
552
  int envcount;
553
  int r;
554
555
15
  writer->json_objectstart("environmentVariables");
556
557
  {
558
15
    Mutex::ScopedLock lock(node::per_process::env_var_mutex);
559
15
    r = uv_os_environ(&envitems, &envcount);
560
  }
561
562
15
  if (r == 0) {
563
975
    for (int i = 0; i < envcount; i++)
564
960
      writer->json_keyvalue(envitems[i].name, envitems[i].value);
565
566
15
    uv_os_free_environ(envitems, envcount);
567
  }
568
569
15
  writer->json_objectend();
570
571
#ifndef _WIN32
572
  static struct {
573
    const char* description;
574
    int id;
575
  } rlimit_strings[] = {
576
    {"core_file_size_blocks", RLIMIT_CORE},
577
    {"data_seg_size_kbytes", RLIMIT_DATA},
578
    {"file_size_blocks", RLIMIT_FSIZE},
579
#if !(defined(_AIX) || defined(__sun))
580
    {"max_locked_memory_bytes", RLIMIT_MEMLOCK},
581
#endif
582
#ifndef __sun
583
    {"max_memory_size_kbytes", RLIMIT_RSS},
584
#endif
585
    {"open_files", RLIMIT_NOFILE},
586
    {"stack_size_bytes", RLIMIT_STACK},
587
    {"cpu_time_seconds", RLIMIT_CPU},
588
#ifndef __sun
589
    {"max_user_processes", RLIMIT_NPROC},
590
#endif
591
#ifndef __OpenBSD__
592
    {"virtual_memory_kbytes", RLIMIT_AS}
593
#endif
594
  };
595
596
15
  writer->json_objectstart("userLimits");
597
  struct rlimit limit;
598
30
  std::string soft, hard;
599
600
165
  for (size_t i = 0; i < arraysize(rlimit_strings); i++) {
601
150
    if (getrlimit(rlimit_strings[i].id, &limit) == 0) {
602
150
      writer->json_objectstart(rlimit_strings[i].description);
603
604
150
      if (limit.rlim_cur == RLIM_INFINITY)
605
90
        writer->json_keyvalue("soft", "unlimited");
606
      else
607
60
        writer->json_keyvalue("soft", limit.rlim_cur);
608
609
150
      if (limit.rlim_max == RLIM_INFINITY)
610
105
        writer->json_keyvalue("hard", "unlimited");
611
      else
612
45
        writer->json_keyvalue("hard", limit.rlim_max);
613
614
150
      writer->json_objectend();
615
    }
616
  }
617
15
  writer->json_objectend();
618
#endif  // _WIN32
619
620
30
  PrintLoadedLibraries(writer);
621
15
}
622
623
// Report a list of loaded native libraries.
624
15
static void PrintLoadedLibraries(JSONWriter* writer) {
625
15
  writer->json_arraystart("sharedObjects");
626
  std::vector<std::string> modules =
627
15
      NativeSymbolDebuggingContext::GetLoadedLibraries();
628
15
  for (auto const& module_name : modules) writer->json_element(module_name);
629
15
  writer->json_arrayend();
630
15
}
631
632
// Obtain and report the node and subcomponent version strings.
633
15
static void PrintComponentVersions(JSONWriter* writer) {
634
15
  std::stringstream buf;
635
636
15
  writer->json_objectstart("componentVersions");
637
638
#define V(key)                                                                 \
639
  writer->json_keyvalue(#key, node::per_process::metadata.versions.key);
640
15
  NODE_VERSIONS_KEYS(V)
641
#undef V
642
643
15
  writer->json_objectend();
644
15
}
645
646
// Report runtime release information.
647
15
static void PrintRelease(JSONWriter* writer) {
648
15
  writer->json_objectstart("release");
649
15
  writer->json_keyvalue("name", node::per_process::metadata.release.name);
650
#if NODE_VERSION_IS_LTS
651
  writer->json_keyvalue("lts", node::per_process::metadata.release.lts);
652
#endif
653
654
#ifdef NODE_HAS_RELEASE_URLS
655
  writer->json_keyvalue("headersUrl",
656
                        node::per_process::metadata.release.headers_url);
657
  writer->json_keyvalue("sourceUrl",
658
                        node::per_process::metadata.release.source_url);
659
#ifdef _WIN32
660
  writer->json_keyvalue("libUrl", node::per_process::metadata.release.lib_url);
661
#endif  // _WIN32
662
#endif  // NODE_HAS_RELEASE_URLS
663
664
15
  writer->json_objectend();
665
15
}
666
667

15177
}  // namespace report