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-02-26 22:23:30 Branches: 59 86 68.6 %

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


















2298
    if (state_ == kAfterValue) out_ << ',';
142
2298
    out_ << '\n';
143
2298
    advance();
144
2298
    write_string(key);
145
2298
    out_ << ": ";
146
2298
    write_value(value);
147
2298
    state_ = kAfterValue;
148
2298
  }
149
150
  template <typename U>
151
187
  inline void json_element(const U& value) {
152
187
    if (state_ == kAfterValue) out_ << ',';
153
187
    out_ << '\n';
154
187
    advance();
155
187
    write_value(value);
156
187
    state_ = kAfterValue;
157
187
  }
158
159
  struct Null {};  // Usable as a JSON value.
160
161
 private:
162
  template <typename T,
163
            typename test_for_number = typename std::
164
                enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
165
868
  inline void write_value(T number) {
166
    if (std::is_same<T, bool>::value)
167
196
      out_ << (number ? "true" : "false");
168
    else
169
672
      out_ << number;
170
868
  }
171
172
8
  inline void write_value(Null null) { out_ << "null"; }
173
325
  inline void write_value(const char* str) { write_string(str); }
174
1284
  inline void write_value(const std::string& str) { write_string(str); }
175
176
4263
  inline void write_string(const std::string& str) {
177
4263
    out_ << '"' << EscapeJsonChars(str) << '"';
178
4263
  }
179
2349
  inline void write_string(const char* str) { write_string(std::string(str)); }
180
181
  enum JSONState { kObjectStart, kAfterValue };
182
  std::ostream& out_;
183
  int indent_ = 0;
184
  int state_ = kObjectStart;
185
};
186
187
}  // namespace report
188
189
#endif  // SRC_NODE_REPORT_H_