Node.js  v8.x
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine
node_perf.h
Go to the documentation of this file.
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.h"
10 #include "base-object-inl.h"
11 
12 #include "v8.h"
13 #include "uv.h"
14 
15 #include <limits>
16 #include <string>
17 
18 namespace node {
19 namespace performance {
20 
21 using v8::FunctionCallbackInfo;
22 using v8::GCType;
23 using v8::Local;
24 using v8::Object;
25 using v8::Value;
26 
27 static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) {
28 #define V(name, label) \
29  if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name;
31 #undef V
33 }
34 
35 static inline PerformanceEntryType ToPerformanceEntryTypeEnum(
36  const char* type) {
37 #define V(name, label) \
38  if (strcmp(type, label) == 0) return NODE_PERFORMANCE_ENTRY_TYPE_##name;
40 #undef V
42 }
43 
44 const double MAX_DOUBLE = std::numeric_limits<double>::max();
45 
46 NODE_EXTERN inline void MarkPerformanceMilestone(
47  Environment* env,
48  PerformanceMilestone milestone) {
49  env->performance_state()->milestones[milestone] = PERFORMANCE_NOW();
50  }
51 
52 class PerformanceEntry : public BaseObject {
53  public:
54  // Used for temporary storage of performance entry details when the
55  // object cannot be created immediately.
56  class Data {
57  public:
58  Data(
59  const char* name,
60  const char* type,
61  uint64_t startTime,
62  uint64_t endTime,
63  int data = 0) :
64  name_(name),
65  type_(type),
66  startTime_(startTime),
67  endTime_(endTime),
68  data_(data) {}
69 
70  std::string name() const {
71  return name_;
72  }
73 
74  std::string type() const {
75  return type_;
76  }
77 
78  uint64_t startTime() const {
79  return startTime_;
80  }
81 
82  uint64_t endTime() const {
83  return endTime_;
84  }
85 
86  int data() const {
87  return data_;
88  }
89 
90  private:
91  std::string name_;
92  std::string type_;
93  uint64_t startTime_;
94  uint64_t endTime_;
95  int data_;
96  };
97 
98  static void NotifyObservers(Environment* env, PerformanceEntry* entry);
99 
100  static void New(const FunctionCallbackInfo<Value>& args);
101 
102  PerformanceEntry(Environment* env,
103  Local<Object> wrap,
104  const char* name,
105  const char* type,
106  uint64_t startTime,
107  uint64_t endTime) :
108  BaseObject(env, wrap),
109  name_(name),
110  type_(type),
111  startTime_(startTime),
112  endTime_(endTime) {
113  MakeWeak<PerformanceEntry>(this);
114  NotifyObservers(env, this);
115  }
116 
117  PerformanceEntry(Environment* env,
118  Local<Object> wrap,
119  Data* data) :
120  BaseObject(env, wrap),
121  name_(data->name()),
122  type_(data->type()),
123  startTime_(data->startTime()),
124  endTime_(data->endTime()) {
125  MakeWeak<PerformanceEntry>(this);
126  NotifyObservers(env, this);
127  }
128 
129  ~PerformanceEntry() {}
130 
131  std::string name() const {
132  return name_;
133  }
134 
135  std::string type() const {
136  return type_;
137  }
138 
139  double startTime() const {
140  return startTime_ / 1e6;
141  }
142 
143  double duration() const {
144  return durationNano() / 1e6;
145  }
146 
147  uint64_t startTimeNano() const {
148  return startTime_;
149  }
150 
151  uint64_t durationNano() const {
152  return endTime_ - startTime_;
153  }
154 
155  private:
156  std::string name_;
157  std::string type_;
158  uint64_t startTime_;
159  uint64_t endTime_;
160 };
161 
162 enum PerformanceGCKind {
163  NODE_PERFORMANCE_GC_MAJOR = GCType::kGCTypeMarkSweepCompact,
164  NODE_PERFORMANCE_GC_MINOR = GCType::kGCTypeScavenge,
165  NODE_PERFORMANCE_GC_INCREMENTAL = GCType::kGCTypeIncrementalMarking,
166  NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks
167 };
168 
169 } // namespace performance
170 } // namespace node
171 
172 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
173 
174 #endif // SRC_NODE_PERF_H_
QueryWrap * wrap
Definition: cares_wrap.cc:478
#define PERFORMANCE_NOW()
union node::cares_wrap::@8::CaresAsyncData::@0 data
#define NODE_EXTERN
Definition: node.h:32
char * Data(Local< Value > val)
Definition: node_buffer.cc:211
#define V(PROVIDER)
#define NODE_PERFORMANCE_ENTRY_TYPES(V)
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)
Definition: node_buffer.cc:241
#define NODE_PERFORMANCE_MILESTONES(V)