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: 0 26 0.0 %
Date: 2019-02-01 22:03:38 Branches: 0 35 0.0 %

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
11
#include "v8.h"
12
#include "uv.h"
13
14
#include <string>
15
16
namespace node {
17
namespace performance {
18
19
using v8::FunctionCallbackInfo;
20
using v8::GCType;
21
using v8::Local;
22
using v8::Object;
23
using v8::Value;
24
25
extern const uint64_t timeOrigin;
26
27
double GetCurrentTimeInMicroseconds();
28
29
static inline const char* GetPerformanceMilestoneName(
30
    enum PerformanceMilestone milestone) {
31
  switch (milestone) {
32
#define V(name, label) case NODE_PERFORMANCE_MILESTONE_##name: return label;
33
  NODE_PERFORMANCE_MILESTONES(V)
34
#undef V
35
    default:
36
      UNREACHABLE();
37
      return 0;
38
  }
39
}
40
41
static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) {
42
#define V(name, label)                                                        \
43
  if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name;
44
  NODE_PERFORMANCE_MILESTONES(V)
45
#undef V
46
  return NODE_PERFORMANCE_MILESTONE_INVALID;
47
}
48
49
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
  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
  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
                                       endTime_(endTime) { }
75
76
  virtual ~PerformanceEntry() { }
77
78
  virtual v8::MaybeLocal<Object> ToObject() const;
79
80
  Environment* env() const { return env_; }
81
82
  const std::string& name() const { return name_; }
83
84
  const std::string& type() const { return type_; }
85
86
  PerformanceEntryType kind() {
87
    return ToPerformanceEntryTypeEnum(type().c_str());
88
  }
89
90
  double startTime() const { return startTimeNano() / 1e6; }
91
92
  double duration() const { return durationNano() / 1e6; }
93
94
  uint64_t startTimeNano() const { return startTime_ - timeOrigin; }
95
96
  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
class GCPerformanceEntry : public PerformanceEntry {
114
 public:
115
  GCPerformanceEntry(Environment* env,
116
                     PerformanceGCKind gckind,
117
                     uint64_t startTime,
118
                     uint64_t endTime) :
119
                         PerformanceEntry(env, "gc", "gc", startTime, endTime),
120
                         gckind_(gckind) { }
121
122
  PerformanceGCKind gckind() const { return gckind_; }
123
124
 private:
125
  PerformanceGCKind gckind_;
126
};
127
128
}  // namespace performance
129
}  // namespace node
130
131
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
132
133
#endif  // SRC_NODE_PERF_H_