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: 33 40 82.5 %
Date: 2020-02-19 22:14:06 Branches: 24 33 72.7 %

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 "base_object-inl.h"
9
#include "histogram-inl.h"
10
11
#include "v8.h"
12
#include "uv.h"
13
14
#include <string>
15
16
namespace node {
17
18
class Environment;
19
20
namespace performance {
21
22
using v8::FunctionCallbackInfo;
23
using v8::GCType;
24
using v8::GCCallbackFlags;
25
using v8::Local;
26
using v8::Object;
27
using v8::Value;
28
29
extern const uint64_t timeOrigin;
30
31
46
static inline const char* GetPerformanceMilestoneName(
32
    enum PerformanceMilestone milestone) {
33

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



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



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