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(GC, "gc") \ 36 V(HTTP, "http") \ 37 V(HTTP2, "http2") \ 38 V(NET, "net") \ 39 V(DNS, "dns") 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 class PerformanceState { 56 public: 57 struct SerializeInfo { 58 AliasedBufferIndex root; 59 AliasedBufferIndex milestones; 60 AliasedBufferIndex observers; 61 }; 62 63 explicit PerformanceState(v8::Isolate* isolate, const SerializeInfo* info); 64 SerializeInfo Serialize(v8::Local<v8::Context> context, 65 v8::SnapshotCreator* creator); 66 void Deserialize(v8::Local<v8::Context> context); 67 friend std::ostream& operator<<(std::ostream& o, const SerializeInfo& i); 68 69 AliasedUint8Array root; 70 AliasedFloat64Array milestones; 71 AliasedUint32Array observers; 72 73 uint64_t performance_last_gc_start_mark = 0; 74 uint16_t current_gc_type = 0; 75 76 void Mark(enum PerformanceMilestone milestone, 77 uint64_t ts = PERFORMANCE_NOW()); 78 79 private: 80 struct performance_state_internal { 81 // doubles first so that they are always sizeof(double)-aligned 82 double milestones[NODE_PERFORMANCE_MILESTONE_INVALID]; 83 uint32_t observers[NODE_PERFORMANCE_ENTRY_TYPE_INVALID]; 84 }; 85 }; 86 87 } // namespace performance 88 } // namespace node 89 90 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 91 92 #endif // SRC_NODE_PERF_COMMON_H_ 93