summaryrefslogtreecommitdiff
path: root/src/inspector_profiler.h
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-03-23 07:39:52 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-06 12:01:45 +0800
commit864860e9f3d4eed0b0b81af55197d7e525ea6306 (patch)
treeed0c9cbc1cea99323cd4fa4c5385a11b262be8ee /src/inspector_profiler.h
parentbaa54a5ae78ff04a3e8d8ac97c052304a6f6c18c (diff)
downloadandroid-node-v8-864860e9f3d4eed0b0b81af55197d7e525ea6306.tar.gz
android-node-v8-864860e9f3d4eed0b0b81af55197d7e525ea6306.tar.bz2
android-node-v8-864860e9f3d4eed0b0b81af55197d7e525ea6306.zip
src: port coverage serialization to C++
This patch moves the serialization of coverage profiles into C++. With this we no longer need to patch `process.reallyExit` and hook into the exit events, but instead hook into relevant places in C++ which are safe from user manipulation. This also makes the code easier to reuse for other types of profiles. PR-URL: https://github.com/nodejs/node/pull/26874 Reviewed-By: Ben Coe <bencoe@gmail.com>
Diffstat (limited to 'src/inspector_profiler.h')
-rw-r--r--src/inspector_profiler.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/inspector_profiler.h b/src/inspector_profiler.h
new file mode 100644
index 0000000000..43a8d54163
--- /dev/null
+++ b/src/inspector_profiler.h
@@ -0,0 +1,75 @@
+#ifndef SRC_INSPECTOR_PROFILER_H_
+#define SRC_INSPECTOR_PROFILER_H_
+
+#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+
+#if !HAVE_INSPECTOR
+#error("This header can only be used when inspector is enabled")
+#endif
+
+#include "env.h"
+#include "inspector_agent.h"
+
+namespace node {
+// Forward declaration to break recursive dependency chain with src/env.h.
+class Environment;
+
+namespace profiler {
+
+class V8ProfilerConnection {
+ public:
+ class V8ProfilerSessionDelegate : public inspector::InspectorSessionDelegate {
+ public:
+ explicit V8ProfilerSessionDelegate(V8ProfilerConnection* connection)
+ : connection_(connection) {}
+
+ void SendMessageToFrontend(
+ const v8_inspector::StringView& message) override {
+ connection_->OnMessage(message);
+ }
+
+ private:
+ V8ProfilerConnection* connection_;
+ };
+
+ explicit V8ProfilerConnection(Environment* env);
+ virtual ~V8ProfilerConnection() = default;
+ Environment* env() { return env_; }
+
+ // Use DispatchMessage() to dispatch necessary inspector messages
+ virtual void Start() = 0;
+ virtual void End() = 0;
+ // Override this to respond to the messages sent from the session.
+ virtual void OnMessage(const v8_inspector::StringView& message) = 0;
+ virtual bool ending() const = 0;
+
+ void DispatchMessage(v8::Local<v8::String> message);
+ // Write the result to a path
+ bool WriteResult(const char* path, v8::Local<v8::String> result);
+
+ private:
+ std::unique_ptr<inspector::InspectorSession> session_;
+ Environment* env_ = nullptr;
+};
+
+class V8CoverageConnection : public V8ProfilerConnection {
+ public:
+ explicit V8CoverageConnection(Environment* env) : V8ProfilerConnection(env) {}
+
+ void Start() override;
+ void End() override;
+ void OnMessage(const v8_inspector::StringView& message) override;
+ bool ending() const override { return ending_; }
+
+ private:
+ bool WriteCoverage(v8::Local<v8::String> message);
+ v8::MaybeLocal<v8::String> GetResult(v8::Local<v8::String> message);
+ std::unique_ptr<inspector::InspectorSession> session_;
+ bool ending_ = false;
+};
+
+} // namespace profiler
+} // namespace node
+
+#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+#endif // SRC_INSPECTOR_PROFILER_H_