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-13 22:28:58 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
107
std::string ValueToHexString(T value) {
62
107
  std::stringstream hex;
63
64
107
  hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex <<
65
    value;
66
107
  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
6
  explicit JSONWriter(std::ostream& out) : out_(out) {}
80
81
329
  inline void indent() { indent_ += 2; }
82
329
  inline void deindent() { indent_ -= 2; }
83
2224
  inline void advance() {
84
2224
    for (int i = 0; i < indent_; i++) out_ << ' ';
85
2224
  }
86
87
113
  inline void json_start() {
88
113
    if (state_ == kAfterValue) out_ << ',';
89
113
    out_ << '\n';
90
113
    advance();
91
113
    out_ << '{';
92
113
    indent();
93
113
    state_ = kObjectStart;
94
113
  }
95
96
107
  inline void json_end() {
97
107
    out_ << '\n';
98
107
    deindent();
99
107
    advance();
100
107
    out_ << '}';
101
107
    state_ = kAfterValue;
102
107
  }
103
  template <typename T>
104
186
  inline void json_objectstart(T key) {
105
186
    if (state_ == kAfterValue) out_ << ',';
106
186
    out_ << '\n';
107
186
    advance();
108
186
    write_string(key);
109
186
    out_ << ": {";
110
186
    indent();
111
186
    state_ = kObjectStart;
112
186
  }
113
114
  template <typename T>
115
30
  inline void json_arraystart(T key) {
116
30
    if (state_ == kAfterValue) out_ << ',';
117
30
    out_ << '\n';
118
30
    advance();
119
30
    write_string(key);
120
30
    out_ << ": [";
121
30
    indent();
122
30
    state_ = kObjectStart;
123
30
  }
124
192
  inline void json_objectend() {
125
192
    out_ << '\n';
126
192
    deindent();
127
192
    advance();
128
192
    out_ << '}';
129
192
    state_ = kAfterValue;
130
192
  }
131
132
30
  inline void json_arrayend() {
133
30
    out_ << '\n';
134
30
    deindent();
135
30
    advance();
136
30
    out_ << ']';
137
30
    state_ = kAfterValue;
138
30
  }
139
  template <typename T, typename U>
140
1446
  inline void json_keyvalue(const T& key, const U& value) {
141


















1446
    if (state_ == kAfterValue) out_ << ',';
142
1446
    out_ << '\n';
143
1446
    advance();
144
1446
    write_string(key);
145
1446
    out_ << ": ";
146
1446
    write_value(value);
147
1446
    state_ = kAfterValue;
148
1446
  }
149
150
  template <typename U>
151
120
  inline void json_element(const U& value) {
152
120
    if (state_ == kAfterValue) out_ << ',';
153
120
    out_ << '\n';
154
120
    advance();
155
120
    write_value(value);
156
120
    state_ = kAfterValue;
157
120
  }
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
560
  inline void write_value(T number) {
166
    if (std::is_same<T, bool>::value)
167
144
      out_ << (number ? "true" : "false");
168
    else
169
416
      out_ << number;
170
560
  }
171
172
6
  inline void write_value(Null null) { out_ << "null"; }
173
211
  inline void write_value(const char* str) { write_string(str); }
174
789
  inline void write_value(const std::string& str) { write_string(str); }
175
176
2662
  inline void write_string(const std::string& str) {
177
2662
    out_ << '"' << EscapeJsonChars(str) << '"';
178
2662
  }
179
1495
  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_