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