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