GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/inspector_profiler.h Lines: 20 20 100.0 %
Date: 2019-09-15 22:29:17 Branches: 5 10 50.0 %

Line Branch Exec Source
1
#ifndef SRC_INSPECTOR_PROFILER_H_
2
#define SRC_INSPECTOR_PROFILER_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#if !HAVE_INSPECTOR
7
#error("This header can only be used when inspector is enabled")
8
#endif
9
10
#include "env.h"
11
#include "inspector_agent.h"
12
13
namespace node {
14
// Forward declaration to break recursive dependency chain with src/env.h.
15
class Environment;
16
17
namespace profiler {
18
19
class V8ProfilerConnection {
20
 public:
21
9570
  class V8ProfilerSessionDelegate : public inspector::InspectorSessionDelegate {
22
   public:
23
5193
    explicit V8ProfilerSessionDelegate(V8ProfilerConnection* connection)
24
5193
        : connection_(connection) {}
25
26
    void SendMessageToFrontend(
27
        const v8_inspector::StringView& message) override;
28
29
   private:
30
    V8ProfilerConnection* connection_;
31
  };
32
33
  explicit V8ProfilerConnection(Environment* env);
34
4785
  virtual ~V8ProfilerConnection() = default;
35
36
40823
  Environment* env() const { return env_; }
37
38
  // Dispatch a protocol message, and returns the id of the message.
39
  // `method` does not need to be surrounded by quotes.
40
  // The optional `params` should be formatted in JSON.
41
  // The strings should be in one byte characters - which is enough for
42
  // the commands we use here.
43
  size_t DispatchMessage(const char* method, const char* params = nullptr);
44
45
  // Use DispatchMessage() to dispatch necessary inspector messages
46
  // to start and end the profiling.
47
  virtual void Start() = 0;
48
  virtual void End() = 0;
49
50
  // Return a descriptive name of the profile for debugging.
51
  virtual const char* type() const = 0;
52
  // Return if the profile is ending and the response can be parsed.
53
  virtual bool ending() const = 0;
54
  // Return the directory where the profile should be placed.
55
  virtual std::string GetDirectory() const = 0;
56
  // Return the filename the profile should be written as.
57
  virtual std::string GetFilename() const = 0;
58
  // Return the profile object parsed from `message.result`,
59
  // which will be then written as a JSON.
60
  virtual v8::MaybeLocal<v8::Object> GetProfile(
61
      v8::Local<v8::Object> result) = 0;
62
63
 private:
64
15397
  size_t next_id() { return id_++; }
65
  void WriteProfile(v8::Local<v8::String> message);
66
  std::unique_ptr<inspector::InspectorSession> session_;
67
  Environment* env_ = nullptr;
68
  size_t id_ = 1;
69
};
70
71
9533
class V8CoverageConnection : public V8ProfilerConnection {
72
 public:
73
5172
  explicit V8CoverageConnection(Environment* env) : V8ProfilerConnection(env) {}
74
75
  void Start() override;
76
  void End() override;
77
78
25294
  const char* type() const override { return "coverage"; }
79
35726
  bool ending() const override { return ending_; }
80
81
  std::string GetDirectory() const override;
82
  std::string GetFilename() const override;
83
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
84
85
 private:
86
  std::unique_ptr<inspector::InspectorSession> session_;
87
  bool ending_ = false;
88
};
89
90
18
class V8CpuProfilerConnection : public V8ProfilerConnection {
91
 public:
92
10
  explicit V8CpuProfilerConnection(Environment* env)
93
10
      : V8ProfilerConnection(env) {}
94
95
  void Start() override;
96
  void End() override;
97
98
60
  const char* type() const override { return "CPU"; }
99
90
  bool ending() const override { return ending_; }
100
101
  std::string GetDirectory() const override;
102
  std::string GetFilename() const override;
103
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
104
105
 private:
106
  std::unique_ptr<inspector::InspectorSession> session_;
107
  bool ending_ = false;
108
};
109
110
18
class V8HeapProfilerConnection : public V8ProfilerConnection {
111
 public:
112
10
  explicit V8HeapProfilerConnection(Environment* env)
113
10
      : V8ProfilerConnection(env) {}
114
115
  void Start() override;
116
  void End() override;
117
118
50
  const char* type() const override { return "heap"; }
119
70
  bool ending() const override { return ending_; }
120
121
  std::string GetDirectory() const override;
122
  std::string GetFilename() const override;
123
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
124
125
 private:
126
  std::unique_ptr<inspector::InspectorSession> session_;
127
  bool ending_ = false;
128
};
129
130
}  // namespace profiler
131
}  // namespace node
132
133
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
134
#endif  // SRC_INSPECTOR_PROFILER_H_