GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/node_perf.h Lines: 24 26 92.3 %
Date: 2019-01-07 12:15:22 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_internals.h"
8
#include "node_perf_common.h"
9
#include "env.h"
10
#include "base_object-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
      return 0;
39
  }
40
}
41
42
5
static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) {
43
#define V(name, label)                                                        \
44
  if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name;
45



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



33
  NODE_PERFORMANCE_ENTRY_TYPES(V)
55
#undef V
56
  return NODE_PERFORMANCE_ENTRY_TYPE_INVALID;
57
}
58
59
class PerformanceEntry {
60
 public:
61
  static void Notify(Environment* env,
62
                     PerformanceEntryType type,
63
                     Local<Value> object);
64
65
  static void New(const FunctionCallbackInfo<Value>& args);
66
67
33
  PerformanceEntry(Environment* env,
68
                   const char* name,
69
                   const char* type,
70
                   uint64_t startTime,
71
                   uint64_t endTime) : env_(env),
72
                                       name_(name),
73
                                       type_(type),
74
                                       startTime_(startTime),
75
33
                                       endTime_(endTime) { }
76
77
33
  virtual ~PerformanceEntry() { }
78
79
  virtual const Local<Object> ToObject() const;
80
81
37
  Environment* env() const { return env_; }
82
83
33
  const std::string& name() const { return name_; }
84
85
66
  const std::string& type() const { return type_; }
86
87
33
  PerformanceEntryType kind() {
88
33
    return ToPerformanceEntryTypeEnum(type().c_str());
89
  }
90
91
33
  double startTime() const { return startTimeNano() / 1e6; }
92
93
33
  double duration() const { return durationNano() / 1e6; }
94
95
36
  uint64_t startTimeNano() const { return startTime_ - timeOrigin; }
96
97
33
  uint64_t durationNano() const { return endTime_ - startTime_; }
98
99
 private:
100
  Environment* env_;
101
  const std::string name_;
102
  const std::string type_;
103
  const uint64_t startTime_;
104
  const uint64_t endTime_;
105
};
106
107
enum PerformanceGCKind {
108
  NODE_PERFORMANCE_GC_MAJOR = GCType::kGCTypeMarkSweepCompact,
109
  NODE_PERFORMANCE_GC_MINOR = GCType::kGCTypeScavenge,
110
  NODE_PERFORMANCE_GC_INCREMENTAL = GCType::kGCTypeIncrementalMarking,
111
  NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks
112
};
113
114
2
class GCPerformanceEntry : public PerformanceEntry {
115
 public:
116
1
  GCPerformanceEntry(Environment* env,
117
                     PerformanceGCKind gckind,
118
                     uint64_t startTime,
119
                     uint64_t endTime) :
120
                         PerformanceEntry(env, "gc", "gc", startTime, endTime),
121
1
                         gckind_(gckind) { }
122
123
1
  PerformanceGCKind gckind() const { return gckind_; }
124
125
 private:
126
  PerformanceGCKind gckind_;
127
};
128
129
}  // namespace performance
130
}  // namespace node
131
132
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
133
134
#endif  // SRC_NODE_PERF_H_