1 |
|
|
#ifndef SRC_NODE_PERF_COMMON_H_ |
2 |
|
|
#define SRC_NODE_PERF_COMMON_H_ |
3 |
|
|
|
4 |
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
5 |
|
|
|
6 |
|
|
#include "node.h" |
7 |
|
|
#include "uv.h" |
8 |
|
|
#include "v8.h" |
9 |
|
|
|
10 |
|
|
#include <algorithm> |
11 |
|
|
#include <map> |
12 |
|
|
#include <string> |
13 |
|
|
|
14 |
|
|
namespace node { |
15 |
|
|
namespace performance { |
16 |
|
|
|
17 |
|
|
#define PERFORMANCE_NOW() uv_hrtime() |
18 |
|
|
|
19 |
|
|
// These occur before the environment is created. Cache them |
20 |
|
|
// here and add them to the milestones when the env is init'd. |
21 |
|
|
extern uint64_t performance_v8_start; |
22 |
|
|
|
23 |
|
|
#define NODE_PERFORMANCE_MILESTONES(V) \ |
24 |
|
|
V(ENVIRONMENT, "environment") \ |
25 |
|
|
V(NODE_START, "nodeStart") \ |
26 |
|
|
V(V8_START, "v8Start") \ |
27 |
|
|
V(LOOP_START, "loopStart") \ |
28 |
|
|
V(LOOP_EXIT, "loopExit") \ |
29 |
|
|
V(BOOTSTRAP_COMPLETE, "bootstrapComplete") |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
#define NODE_PERFORMANCE_ENTRY_TYPES(V) \ |
33 |
|
|
V(NODE, "node") \ |
34 |
|
|
V(MARK, "mark") \ |
35 |
|
|
V(MEASURE, "measure") \ |
36 |
|
|
V(GC, "gc") \ |
37 |
|
|
V(FUNCTION, "function") \ |
38 |
|
|
V(HTTP2, "http2") \ |
39 |
|
|
V(HTTP, "http") |
40 |
|
|
|
41 |
|
|
enum PerformanceMilestone { |
42 |
|
|
#define V(name, _) NODE_PERFORMANCE_MILESTONE_##name, |
43 |
|
|
NODE_PERFORMANCE_MILESTONES(V) |
44 |
|
|
#undef V |
45 |
|
|
NODE_PERFORMANCE_MILESTONE_INVALID |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
enum PerformanceEntryType { |
49 |
|
|
#define V(name, _) NODE_PERFORMANCE_ENTRY_TYPE_##name, |
50 |
|
|
NODE_PERFORMANCE_ENTRY_TYPES(V) |
51 |
|
|
#undef V |
52 |
|
|
NODE_PERFORMANCE_ENTRY_TYPE_INVALID |
53 |
|
|
}; |
54 |
|
|
|
55 |
|
4699 |
class performance_state { |
56 |
|
|
public: |
57 |
|
5105 |
explicit performance_state(v8::Isolate* isolate) : |
58 |
|
|
root( |
59 |
|
|
isolate, |
60 |
|
|
sizeof(performance_state_internal)), |
61 |
|
|
milestones( |
62 |
|
|
isolate, |
63 |
|
|
offsetof(performance_state_internal, milestones), |
64 |
|
|
NODE_PERFORMANCE_MILESTONE_INVALID, |
65 |
|
|
root), |
66 |
|
|
observers( |
67 |
|
|
isolate, |
68 |
|
|
offsetof(performance_state_internal, observers), |
69 |
|
|
NODE_PERFORMANCE_ENTRY_TYPE_INVALID, |
70 |
|
5105 |
root) { |
71 |
✓✓ |
35735 |
for (size_t i = 0; i < milestones.Length(); i++) |
72 |
|
30630 |
milestones[i] = -1.; |
73 |
|
5105 |
} |
74 |
|
|
|
75 |
|
|
AliasedUint8Array root; |
76 |
|
|
AliasedFloat64Array milestones; |
77 |
|
|
AliasedUint32Array observers; |
78 |
|
|
|
79 |
|
|
uint64_t performance_last_gc_start_mark = 0; |
80 |
|
|
|
81 |
|
|
void Mark(enum PerformanceMilestone milestone, |
82 |
|
|
uint64_t ts = PERFORMANCE_NOW()); |
83 |
|
|
|
84 |
|
|
private: |
85 |
|
|
struct performance_state_internal { |
86 |
|
|
// doubles first so that they are always sizeof(double)-aligned |
87 |
|
|
double milestones[NODE_PERFORMANCE_MILESTONE_INVALID]; |
88 |
|
|
uint32_t observers[NODE_PERFORMANCE_ENTRY_TYPE_INVALID]; |
89 |
|
|
}; |
90 |
|
|
}; |
91 |
|
|
|
92 |
|
|
} // namespace performance |
93 |
|
|
} // namespace node |
94 |
|
|
|
95 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
96 |
|
|
|
97 |
|
|
#endif // SRC_NODE_PERF_COMMON_H_ |