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: 15 15 100.0 %
Date: 2019-05-05 22:32:45 Branches: 4 8 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
8550
  class V8ProfilerSessionDelegate : public inspector::InspectorSessionDelegate {
22
   public:
23
4656
    explicit V8ProfilerSessionDelegate(V8ProfilerConnection* connection)
24
4656
        : 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
4275
  virtual ~V8ProfilerConnection() = default;
35
36
36578
  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
13807
  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
8532
class V8CoverageConnection : public V8ProfilerConnection {
72
 public:
73
4646
  explicit V8CoverageConnection(Environment* env) : V8ProfilerConnection(env) {}
74
75
  void Start() override;
76
  void End() override;
77
78
22699
  const char* type() const override { return type_.c_str(); }
79
32078
  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
  std::string type_ = "coverage";
89
};
90
91
18
class V8CpuProfilerConnection : public V8ProfilerConnection {
92
 public:
93
10
  explicit V8CpuProfilerConnection(Environment* env)
94
10
      : V8ProfilerConnection(env) {}
95
96
  void Start() override;
97
  void End() override;
98
99
60
  const char* type() const override { return type_.c_str(); }
100
90
  bool ending() const override { return ending_; }
101
102
  std::string GetDirectory() const override;
103
  std::string GetFilename() const override;
104
  v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
105
106
 private:
107
  std::unique_ptr<inspector::InspectorSession> session_;
108
  bool ending_ = false;
109
  std::string type_ = "CPU";
110
};
111
112
}  // namespace profiler
113
}  // namespace node
114
115
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
116
#endif  // SRC_INSPECTOR_PROFILER_H_