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.h Lines: 84 84 100.0 %
Date: 2019-05-05 22:32:45 Branches: 62 90 68.9 %

Line Branch Exec Source
1
#pragma once
2
3
#include "node.h"
4
#include "node_buffer.h"
5
#include "uv.h"
6
#include "v8.h"
7
8
#ifndef _WIN32
9
#include <sys/types.h>
10
#include <unistd.h>
11
#endif
12
13
#include <climits>
14
#include <cstdio>
15
#include <cstdlib>
16
#include <cstring>
17
#include <iomanip>
18
#include <iostream>
19
#include <sstream>
20
#include <limits>
21
#include <algorithm>
22
#include <queue>
23
#include <string>
24
#include <utility>
25
#include <vector>
26
27
namespace report {
28
29
#ifdef _WIN32
30
#define PATHSEP "\\"
31
#else  // UNIX, OSX
32
#define PATHSEP "/"
33
#endif
34
35
// Function declarations - functions in src/node_report.cc
36
std::string TriggerNodeReport(v8::Isolate* isolate,
37
                              node::Environment* env,
38
                              const char* message,
39
                              const char* trigger,
40
                              const std::string& name,
41
                              v8::Local<v8::String> stackstr);
42
void GetNodeReport(v8::Isolate* isolate,
43
                   node::Environment* env,
44
                   const char* message,
45
                   const char* trigger,
46
                   v8::Local<v8::String> stackstr,
47
                   std::ostream& out);
48
49
// Function declarations - utility functions in src/node_report_utils.cc
50
void WalkHandle(uv_handle_t* h, void* arg);
51
std::string EscapeJsonChars(const std::string& str);
52
53
template <typename T>
54
236
std::string ValueToHexString(T value) {
55
236
  std::stringstream hex;
56
57
236
  hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex <<
58
    value;
59
236
  return hex.str();
60
}
61
62
// Function declarations - export functions in src/node_report_module.cc
63
void WriteReport(const v8::FunctionCallbackInfo<v8::Value>& info);
64
void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info);
65
66
// Node.js boot time - defined in src/node.cc
67
extern double prog_start_time;
68
69
// JSON compiler definitions.
70
class JSONWriter {
71
 public:
72
13
  explicit JSONWriter(std::ostream& out) : out_(out) {}
73
74
725
  inline void indent() { indent_ += 2; }
75
725
  inline void deindent() { indent_ -= 2; }
76
4819
  inline void advance() {
77
4819
    for (int i = 0; i < indent_; i++) out_ << ' ';
78
4819
  }
79
80
249
  inline void json_start() {
81
249
    if (state_ == kAfterValue) out_ << ',';
82
249
    out_ << '\n';
83
249
    advance();
84
249
    out_ << '{';
85
249
    indent();
86
249
    state_ = kObjectStart;
87
249
  }
88
89
236
  inline void json_end() {
90
236
    out_ << '\n';
91
236
    deindent();
92
236
    advance();
93
236
    out_ << '}';
94
236
    state_ = kAfterValue;
95
236
  }
96
  template <typename T>
97
411
  inline void json_objectstart(T key) {
98
411
    if (state_ == kAfterValue) out_ << ',';
99
411
    out_ << '\n';
100
411
    advance();
101
411
    write_string(key);
102
411
    out_ << ": {";
103
411
    indent();
104
411
    state_ = kObjectStart;
105
411
  }
106
107
  template <typename T>
108
65
  inline void json_arraystart(T key) {
109
65
    if (state_ == kAfterValue) out_ << ',';
110
65
    out_ << '\n';
111
65
    advance();
112
65
    write_string(key);
113
65
    out_ << ": [";
114
65
    indent();
115
65
    state_ = kObjectStart;
116
65
  }
117
424
  inline void json_objectend() {
118
424
    out_ << '\n';
119
424
    deindent();
120
424
    advance();
121
424
    out_ << '}';
122
424
    state_ = kAfterValue;
123
424
  }
124
125
65
  inline void json_arrayend() {
126
65
    out_ << '\n';
127
65
    deindent();
128
65
    advance();
129
65
    out_ << ']';
130
65
    state_ = kAfterValue;
131
65
  }
132
  template <typename T, typename U>
133
3140
  inline void json_keyvalue(const T& key, const U& value) {
134



















3140
    if (state_ == kAfterValue) out_ << ',';
135
3140
    out_ << '\n';
136
3140
    advance();
137
3140
    write_string(key);
138
3140
    out_ << ": ";
139
3140
    write_value(value);
140
3140
    state_ = kAfterValue;
141
3140
  }
142
143
  template <typename U>
144
229
  inline void json_element(const U& value) {
145
229
    if (state_ == kAfterValue) out_ << ',';
146
229
    out_ << '\n';
147
229
    advance();
148
229
    write_value(value);
149
229
    state_ = kAfterValue;
150
229
  }
151
152
  struct Null {};  // Usable as a JSON value.
153
154
 private:
155
  template <typename T,
156
            typename test_for_number = typename std::
157
                enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
158
1225
  inline void write_value(T number) {
159
    if (std::is_same<T, bool>::value)
160
280
      out_ << (number ? "true" : "false");
161
    else
162
945
      out_ << number;
163
1225
  }
164
165
6
  inline void write_value(Null null) { out_ << "null"; }
166
442
  inline void write_value(const char* str) { write_string(str); }
167
1696
  inline void write_value(const std::string& str) { write_string(str); }
168
169
5754
  inline void write_string(const std::string& str) {
170
5754
    out_ << '"' << EscapeJsonChars(str) << '"';
171
5754
  }
172
3239
  inline void write_string(const char* str) { write_string(std::string(str)); }
173
174
  enum JSONState { kObjectStart, kAfterValue };
175
  std::ostream& out_;
176
  int indent_ = 0;
177
  int state_ = kObjectStart;
178
};
179
180
}  // namespace report