GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_perf.h Lines: 29 36 80.6 %
Date: 2019-02-13 22:28:58 Branches: 24 35 68.6 %

Line Branch Exec Source
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-inl.h"
10
#include "histogram-inl.h"
11
12
#include "v8.h"
13
#include "uv.h"
14
15
#include <string>
16
17
namespace node {
18
namespace performance {
19
20
using v8::FunctionCallbackInfo;
21
using v8::GCType;
22
using v8::Local;
23
using v8::Object;
24
using v8::Value;
25
26
extern const uint64_t timeOrigin;
27
28
double GetCurrentTimeInMicroseconds();
29
30
46
static inline const char* GetPerformanceMilestoneName(
31
    enum PerformanceMilestone milestone) {
32

46
  switch (milestone) {
33
#define V(name, label) case NODE_PERFORMANCE_MILESTONE_##name: return label;
34
8
  NODE_PERFORMANCE_MILESTONES(V)
35
#undef V
36
    default:
37
      UNREACHABLE();
38
  }
39
}
40
41
5
static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) {
42
#define V(name, label)                                                        \
43
  if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name;
44



5
  NODE_PERFORMANCE_MILESTONES(V)
45
#undef V
46
5
  return NODE_PERFORMANCE_MILESTONE_INVALID;
47
}
48
49
33
static inline PerformanceEntryType ToPerformanceEntryTypeEnum(
50
    const char* type) {
51
#define V(name, label)                                                        \
52
  if (strcmp(type, label) == 0) return NODE_PERFORMANCE_ENTRY_TYPE_##name;
53



33
  NODE_PERFORMANCE_ENTRY_TYPES(V)
54
#undef V
55
  return NODE_PERFORMANCE_ENTRY_TYPE_INVALID;
56
}
57
58
class PerformanceEntry {
59
 public:
60
  static void Notify(Environment* env,
61
                     PerformanceEntryType type,
62
                     Local<Value> object);
63
64
  static void New(const FunctionCallbackInfo<Value>& args);
65
66
33
  PerformanceEntry(Environment* env,
67
                   const char* name,
68
                   const char* type,
69
                   uint64_t startTime,
70
                   uint64_t endTime) : env_(env),
71
                                       name_(name),
72
                                       type_(type),
73
                                       startTime_(startTime),
74
33
                                       endTime_(endTime) { }
75
76
33
  virtual ~PerformanceEntry() { }
77
78
  virtual v8::MaybeLocal<Object> ToObject() const;
79
80
37
  Environment* env() const { return env_; }
81
82
33
  const std::string& name() const { return name_; }
83
84
66
  const std::string& type() const { return type_; }
85
86
33
  PerformanceEntryType kind() {
87
33
    return ToPerformanceEntryTypeEnum(type().c_str());
88
  }
89
90
33
  double startTime() const { return startTimeNano() / 1e6; }
91
92
33
  double duration() const { return durationNano() / 1e6; }
93
94
36
  uint64_t startTimeNano() const { return startTime_ - timeOrigin; }
95
96
33
  uint64_t durationNano() const { return endTime_ - startTime_; }
97
98
 private:
99
  Environment* env_;
100
  const std::string name_;
101
  const std::string type_;
102
  const uint64_t startTime_;
103
  const uint64_t endTime_;
104
};
105
106
enum PerformanceGCKind {
107
  NODE_PERFORMANCE_GC_MAJOR = GCType::kGCTypeMarkSweepCompact,
108
  NODE_PERFORMANCE_GC_MINOR = GCType::kGCTypeScavenge,
109
  NODE_PERFORMANCE_GC_INCREMENTAL = GCType::kGCTypeIncrementalMarking,
110
  NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks
111
};
112
113
2
class GCPerformanceEntry : public PerformanceEntry {
114
 public:
115
1
  GCPerformanceEntry(Environment* env,
116
                     PerformanceGCKind gckind,
117
                     uint64_t startTime,
118
                     uint64_t endTime) :
119
                         PerformanceEntry(env, "gc", "gc", startTime, endTime),
120
1
                         gckind_(gckind) { }
121
122
1
  PerformanceGCKind gckind() const { return gckind_; }
123
124
 private:
125
  PerformanceGCKind gckind_;
126
};
127
128
class ELDHistogram : public BaseObject, public Histogram {
129
 public:
130
  ELDHistogram(Environment* env,
131
               Local<Object> wrap,
132
               int32_t resolution);
133
134
  ~ELDHistogram() override;
135
136
  bool RecordDelta();
137
  bool Enable();
138
  bool Disable();
139
2
  void ResetState() {
140
2
    Reset();
141
2
    exceeds_ = 0;
142
2
    prev_ = 0;
143
2
  }
144
  int64_t Exceeds() { return exceeds_; }
145
146
  void MemoryInfo(MemoryTracker* tracker) const override {
147
    tracker->TrackFieldWithSize("histogram", GetMemorySize());
148
  }
149
150
  SET_MEMORY_INFO_NAME(ELDHistogram)
151
  SET_SELF_SIZE(ELDHistogram)
152
153
 private:
154
  void CloseTimer();
155
156
  bool enabled_ = false;
157
  int32_t resolution_ = 0;
158
  int64_t exceeds_ = 0;
159
  uint64_t prev_ = 0;
160
  uv_timer_t* timer_;
161
};
162
163
}  // namespace performance
164
}  // namespace node
165
166
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
167
168
#endif  // SRC_NODE_PERF_H_