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-10-06 22:30:00 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
9604
  class V8ProfilerSessionDelegate : public inspector::InspectorSessionDelegate {
22
   public:
23
5220
    explicit V8ProfilerSessionDelegate(V8ProfilerConnection* connection)
24
5220
        : 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
4802
  virtual ~V8ProfilerConnection() = default;
35
36
46932
  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
  virtual void WriteProfile(v8::Local<v8::String> message);
63
64
 private:
65
15659
  size_t next_id() { return id_++; }
66
  std::unique_ptr<inspector::InspectorSession> session_;
67
  size_t id_ = 1;
68
69
 protected:
70
  Environment* env_ = nullptr;
71
};
72
73
9566
class V8CoverageConnection : public V8ProfilerConnection {
74
 public:
75
5200
  explicit V8CoverageConnection(Environment* env) : V8ProfilerConnection(env) {}
76
77
  void Start() override;
78
  void End() override;
79
80
25942
  const char* type() const override { return "coverage"; }
81
36458
  bool ending() const override { return ending_; }
82
83
  std::string GetDirectory() const override;
84
  std::string GetFilename() const override;
85
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
86
  void WriteProfile(v8::Local<v8::String> message) override;
87
  void WriteSourceMapCache();
88
89
 private:
90
  std::unique_ptr<inspector::InspectorSession> session_;
91
  bool ending_ = false;
92
};
93
94
18
class V8CpuProfilerConnection : public V8ProfilerConnection {
95
 public:
96
10
  explicit V8CpuProfilerConnection(Environment* env)
97
10
      : V8ProfilerConnection(env) {}
98
99
  void Start() override;
100
  void End() override;
101
102
60
  const char* type() const override { return "CPU"; }
103
90
  bool ending() const override { return ending_; }
104
105
  std::string GetDirectory() const override;
106
  std::string GetFilename() const override;
107
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
108
109
 private:
110
  std::unique_ptr<inspector::InspectorSession> session_;
111
  bool ending_ = false;
112
};
113
114
18
class V8HeapProfilerConnection : public V8ProfilerConnection {
115
 public:
116
10
  explicit V8HeapProfilerConnection(Environment* env)
117
10
      : V8ProfilerConnection(env) {}
118
119
  void Start() override;
120
  void End() override;
121
122
50
  const char* type() const override { return "heap"; }
123
70
  bool ending() const override { return ending_; }
124
125
  std::string GetDirectory() const override;
126
  std::string GetFilename() const override;
127
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
128
129
 private:
130
  std::unique_ptr<inspector::InspectorSession> session_;
131
  bool ending_ = false;
132
};
133
134
}  // namespace profiler
135
}  // namespace node
136
137
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
138
#endif  // SRC_INSPECTOR_PROFILER_H_