GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_perf.h Lines: 29 36 80.6 %
Date: 2019-09-07 22:28:56 Branches: 26 37 70.3 %

Line Branch Exec Source
1
#ifndef SRC_NODE_PERF_H_
2
#define SRC_NODE_PERF_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "node.h"
7
#include "node_perf_common.h"
8
#include "env.h"
9
#include "base_object-inl.h"
10
#include "histogram-inl.h"
11
12
#include "v8.h"
13
#include "uv.h"
14
15
#include <string>
16
17
namespace node {
18
namespace performance {
19
20
using v8::FunctionCallbackInfo;
21
using v8::GCType;
22
using v8::Local;
23
using v8::Object;
24
using v8::Value;
25
26
extern const uint64_t timeOrigin;
27
28
46
static inline const char* GetPerformanceMilestoneName(
29
    enum PerformanceMilestone milestone) {
30

46
  switch (milestone) {
31
#define V(name, label) case NODE_PERFORMANCE_MILESTONE_##name: return label;
32
8
  NODE_PERFORMANCE_MILESTONES(V)
33
#undef V
34
    default:
35
      UNREACHABLE();
36
  }
37
}
38
39
5
static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) {
40
#define V(name, label)                                                        \
41
  if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name;
42



5
  NODE_PERFORMANCE_MILESTONES(V)
43
#undef V
44
5
  return NODE_PERFORMANCE_MILESTONE_INVALID;
45
}
46
47
39
static inline PerformanceEntryType ToPerformanceEntryTypeEnum(
48
    const char* type) {
49
#define V(name, label)                                                        \
50
  if (strcmp(type, label) == 0) return NODE_PERFORMANCE_ENTRY_TYPE_##name;
51



39
  NODE_PERFORMANCE_ENTRY_TYPES(V)
52
#undef V
53
  return NODE_PERFORMANCE_ENTRY_TYPE_INVALID;
54
}
55
56
class PerformanceEntry {
57
 public:
58
  static void Notify(Environment* env,
59
                     PerformanceEntryType type,
60
                     Local<Value> object);
61
62
  static void New(const FunctionCallbackInfo<Value>& args);
63
64
37
  PerformanceEntry(Environment* env,
65
                   const char* name,
66
                   const char* type,
67
                   uint64_t startTime,
68
                   uint64_t endTime) : env_(env),
69
                                       name_(name),
70
                                       type_(type),
71
                                       startTime_(startTime),
72
37
                                       endTime_(endTime) { }
73
74
37
  virtual ~PerformanceEntry() = default;
75
76
  virtual v8::MaybeLocal<Object> ToObject() const;
77
78
41
  Environment* env() const { return env_; }
79
80
37
  const std::string& name() const { return name_; }
81
82
74
  const std::string& type() const { return type_; }
83
84
37
  PerformanceEntryType kind() {
85
37
    return ToPerformanceEntryTypeEnum(type().c_str());
86
  }
87
88
37
  double startTime() const { return startTimeNano() / 1e6; }
89
90
37
  double duration() const { return durationNano() / 1e6; }
91
92
40
  uint64_t startTimeNano() const { return startTime_ - timeOrigin; }
93
94
37
  uint64_t durationNano() const { return endTime_ - startTime_; }
95
96
 private:
97
  Environment* env_;
98
  const std::string name_;
99
  const std::string type_;
100
  const uint64_t startTime_;
101
  const uint64_t endTime_;
102
};
103
104
enum PerformanceGCKind {
105
  NODE_PERFORMANCE_GC_MAJOR = GCType::kGCTypeMarkSweepCompact,
106
  NODE_PERFORMANCE_GC_MINOR = GCType::kGCTypeScavenge,
107
  NODE_PERFORMANCE_GC_INCREMENTAL = GCType::kGCTypeIncrementalMarking,
108
  NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks
109
};
110
111
2
class GCPerformanceEntry : public PerformanceEntry {
112
 public:
113
1
  GCPerformanceEntry(Environment* env,
114
                     PerformanceGCKind gckind,
115
                     uint64_t startTime,
116
                     uint64_t endTime) :
117
                         PerformanceEntry(env, "gc", "gc", startTime, endTime),
118
1
                         gckind_(gckind) { }
119
120
1
  PerformanceGCKind gckind() const { return gckind_; }
121
122
 private:
123
  PerformanceGCKind gckind_;
124
};
125
126
class ELDHistogram : public BaseObject, public Histogram {
127
 public:
128
  ELDHistogram(Environment* env,
129
               Local<Object> wrap,
130
               int32_t resolution);
131
132
  ~ELDHistogram() override;
133
134
  bool RecordDelta();
135
  bool Enable();
136
  bool Disable();
137
2
  void ResetState() {
138
2
    Reset();
139
2
    exceeds_ = 0;
140
2
    prev_ = 0;
141
2
  }
142
  int64_t Exceeds() { return exceeds_; }
143
144
  void MemoryInfo(MemoryTracker* tracker) const override {
145
    tracker->TrackFieldWithSize("histogram", GetMemorySize());
146
  }
147
148
  SET_MEMORY_INFO_NAME(ELDHistogram)
149
  SET_SELF_SIZE(ELDHistogram)
150
151
 private:
152
  void CloseTimer();
153
154
  bool enabled_ = false;
155
  int32_t resolution_ = 0;
156
  int64_t exceeds_ = 0;
157
  uint64_t prev_ = 0;
158
  uv_timer_t* timer_;
159
};
160
161
}  // namespace performance
162
}  // namespace node
163
164
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
165
166
#endif  // SRC_NODE_PERF_H_