GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 |
extern const uint64_t timeOrigin; |
||
23 |
|||
24 |
46 |
static inline const char* GetPerformanceMilestoneName( |
|
25 |
enum PerformanceMilestone milestone) { |
||
26 |
✓✓✓✓ ✓✓✗ |
46 |
switch (milestone) { |
27 |
#define V(name, label) case NODE_PERFORMANCE_MILESTONE_##name: return label; |
||
28 |
8 |
NODE_PERFORMANCE_MILESTONES(V) |
|
29 |
#undef V |
||
30 |
default: |
||
31 |
UNREACHABLE(); |
||
32 |
} |
||
33 |
} |
||
34 |
|||
35 |
6 |
static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) { |
|
36 |
#define V(name, label) \ |
||
37 |
if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name; |
||
38 |
✗✓✗✓ ✗✓✗✓ ✗✓✗✓ |
6 |
NODE_PERFORMANCE_MILESTONES(V) |
39 |
#undef V |
||
40 |
6 |
return NODE_PERFORMANCE_MILESTONE_INVALID; |
|
41 |
} |
||
42 |
|||
43 |
56 |
static inline PerformanceEntryType ToPerformanceEntryTypeEnum( |
|
44 |
const char* type) { |
||
45 |
#define V(name, label) \ |
||
46 |
if (strcmp(type, label) == 0) return NODE_PERFORMANCE_ENTRY_TYPE_##name; |
||
47 |
✗✓✓✓ ✓✓✓✓ ✓✓✓✓ ✓✗ |
56 |
NODE_PERFORMANCE_ENTRY_TYPES(V) |
48 |
#undef V |
||
49 |
return NODE_PERFORMANCE_ENTRY_TYPE_INVALID; |
||
50 |
} |
||
51 |
|||
52 |
class PerformanceEntry { |
||
53 |
public: |
||
54 |
static void Notify(Environment* env, |
||
55 |
PerformanceEntryType type, |
||
56 |
v8::Local<v8::Value> object); |
||
57 |
|||
58 |
static void New(const v8::FunctionCallbackInfo<v8::Value>& args); |
||
59 |
|||
60 |
54 |
PerformanceEntry(Environment* env, |
|
61 |
const char* name, |
||
62 |
const char* type, |
||
63 |
uint64_t startTime, |
||
64 |
54 |
uint64_t endTime) : env_(env), |
|
65 |
name_(name), |
||
66 |
type_(type), |
||
67 |
startTime_(startTime), |
||
68 |
54 |
endTime_(endTime) { } |
|
69 |
|||
70 |
54 |
virtual ~PerformanceEntry() = default; |
|
71 |
|||
72 |
virtual v8::MaybeLocal<v8::Object> ToObject() const; |
||
73 |
|||
74 |
69 |
Environment* env() const { return env_; } |
|
75 |
|||
76 |
54 |
const std::string& name() const { return name_; } |
|
77 |
|||
78 |
108 |
const std::string& type() const { return type_; } |
|
79 |
|||
80 |
54 |
PerformanceEntryType kind() { |
|
81 |
54 |
return ToPerformanceEntryTypeEnum(type().c_str()); |
|
82 |
} |
||
83 |
|||
84 |
54 |
double startTime() const { return startTimeNano() / 1e6; } |
|
85 |
|||
86 |
54 |
double duration() const { return durationNano() / 1e6; } |
|
87 |
|||
88 |
66 |
uint64_t startTimeNano() const { return startTime_ - timeOrigin; } |
|
89 |
|||
90 |
54 |
uint64_t durationNano() const { return endTime_ - startTime_; } |
|
91 |
|||
92 |
private: |
||
93 |
Environment* env_; |
||
94 |
const std::string name_; |
||
95 |
const std::string type_; |
||
96 |
const uint64_t startTime_; |
||
97 |
const uint64_t endTime_; |
||
98 |
}; |
||
99 |
|||
100 |
enum PerformanceGCKind { |
||
101 |
NODE_PERFORMANCE_GC_MAJOR = v8::GCType::kGCTypeMarkSweepCompact, |
||
102 |
NODE_PERFORMANCE_GC_MINOR = v8::GCType::kGCTypeScavenge, |
||
103 |
NODE_PERFORMANCE_GC_INCREMENTAL = v8::GCType::kGCTypeIncrementalMarking, |
||
104 |
NODE_PERFORMANCE_GC_WEAKCB = v8::GCType::kGCTypeProcessWeakCallbacks |
||
105 |
}; |
||
106 |
|||
107 |
enum PerformanceGCFlags { |
||
108 |
NODE_PERFORMANCE_GC_FLAGS_NO = |
||
109 |
v8::GCCallbackFlags::kNoGCCallbackFlags, |
||
110 |
NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED = |
||
111 |
v8::GCCallbackFlags::kGCCallbackFlagConstructRetainedObjectInfos, |
||
112 |
NODE_PERFORMANCE_GC_FLAGS_FORCED = |
||
113 |
v8::GCCallbackFlags::kGCCallbackFlagForced, |
||
114 |
NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING = |
||
115 |
v8::GCCallbackFlags::kGCCallbackFlagSynchronousPhantomCallbackProcessing, |
||
116 |
NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE = |
||
117 |
v8::GCCallbackFlags::kGCCallbackFlagCollectAllAvailableGarbage, |
||
118 |
NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY = |
||
119 |
v8::GCCallbackFlags::kGCCallbackFlagCollectAllExternalMemory, |
||
120 |
NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE = |
||
121 |
v8::GCCallbackFlags::kGCCallbackScheduleIdleGarbageCollection |
||
122 |
}; |
||
123 |
|||
124 |
2 |
class GCPerformanceEntry : public PerformanceEntry { |
|
125 |
public: |
||
126 |
1 |
GCPerformanceEntry(Environment* env, |
|
127 |
PerformanceGCKind gckind, |
||
128 |
PerformanceGCFlags gcflags, |
||
129 |
uint64_t startTime, |
||
130 |
1 |
uint64_t endTime) : |
|
131 |
PerformanceEntry(env, "gc", "gc", startTime, endTime), |
||
132 |
gckind_(gckind), |
||
133 |
1 |
gcflags_(gcflags) { } |
|
134 |
|||
135 |
1 |
PerformanceGCKind gckind() const { return gckind_; } |
|
136 |
1 |
PerformanceGCFlags gcflags() const { return gcflags_; } |
|
137 |
|||
138 |
private: |
||
139 |
PerformanceGCKind gckind_; |
||
140 |
PerformanceGCFlags gcflags_; |
||
141 |
}; |
||
142 |
|||
143 |
4 |
class ELDHistogram : public HandleWrap, public Histogram { |
|
144 |
public: |
||
145 |
ELDHistogram(Environment* env, |
||
146 |
v8::Local<v8::Object> wrap, |
||
147 |
int32_t resolution); |
||
148 |
|||
149 |
bool RecordDelta(); |
||
150 |
bool Enable(); |
||
151 |
bool Disable(); |
||
152 |
2 |
void ResetState() { |
|
153 |
2 |
Reset(); |
|
154 |
2 |
exceeds_ = 0; |
|
155 |
2 |
prev_ = 0; |
|
156 |
2 |
} |
|
157 |
int64_t Exceeds() const { return exceeds_; } |
||
158 |
|||
159 |
void MemoryInfo(MemoryTracker* tracker) const override { |
||
160 |
tracker->TrackFieldWithSize("histogram", GetMemorySize()); |
||
161 |
} |
||
162 |
|||
163 |
SET_MEMORY_INFO_NAME(ELDHistogram) |
||
164 |
SET_SELF_SIZE(ELDHistogram) |
||
165 |
|||
166 |
private: |
||
167 |
static void DelayIntervalCallback(uv_timer_t* req); |
||
168 |
|||
169 |
bool enabled_ = false; |
||
170 |
int32_t resolution_ = 0; |
||
171 |
int64_t exceeds_ = 0; |
||
172 |
uint64_t prev_ = 0; |
||
173 |
uv_timer_t timer_; |
||
174 |
}; |
||
175 |
|||
176 |
} // namespace performance |
||
177 |
} // namespace node |
||
178 |
|||
179 |
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
||
180 |
|||
181 |
#endif // SRC_NODE_PERF_H_ |
Generated by: GCOVR (Version 3.4) |