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 "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 |
✗✓ | 4 |
class ELDHistogram : public HandleWrap, public Histogram { |
127 |
public: |
||
128 |
ELDHistogram(Environment* env, |
||
129 |
Local<Object> wrap, |
||
130 |
int32_t resolution); |
||
131 |
|||
132 |
bool RecordDelta(); |
||
133 |
bool Enable(); |
||
134 |
bool Disable(); |
||
135 |
2 |
void ResetState() { |
|
136 |
2 |
Reset(); |
|
137 |
2 |
exceeds_ = 0; |
|
138 |
2 |
prev_ = 0; |
|
139 |
2 |
} |
|
140 |
int64_t Exceeds() { return exceeds_; } |
||
141 |
|||
142 |
void MemoryInfo(MemoryTracker* tracker) const override { |
||
143 |
tracker->TrackFieldWithSize("histogram", GetMemorySize()); |
||
144 |
} |
||
145 |
|||
146 |
SET_MEMORY_INFO_NAME(ELDHistogram) |
||
147 |
SET_SELF_SIZE(ELDHistogram) |
||
148 |
|||
149 |
private: |
||
150 |
static void DelayIntervalCallback(uv_timer_t* req); |
||
151 |
|||
152 |
bool enabled_ = false; |
||
153 |
int32_t resolution_ = 0; |
||
154 |
int64_t exceeds_ = 0; |
||
155 |
uint64_t prev_ = 0; |
||
156 |
uv_timer_t timer_; |
||
157 |
}; |
||
158 |
|||
159 |
} // namespace performance |
||
160 |
} // namespace node |
||
161 |
|||
162 |
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
||
163 |
|||
164 |
#endif // SRC_NODE_PERF_H_ |
Generated by: GCOVR (Version 3.4) |