aboutsummaryrefslogtreecommitdiff
path: root/src/inspector_profiler.h
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-05-02 20:41:54 +0800
committerMichaƫl Zasso <targos@protonmail.com>2019-05-06 13:02:05 +0200
commit294d2ea71d5955247b96db6d814d5080cd91d36f (patch)
tree98387894fc7e3bf3afd1ef65d754fea19d001b8b /src/inspector_profiler.h
parentbdabf699eb68c1ee01c1f66298d3682cc5d41dee (diff)
downloadandroid-node-v8-294d2ea71d5955247b96db6d814d5080cd91d36f.tar.gz
android-node-v8-294d2ea71d5955247b96db6d814d5080cd91d36f.tar.bz2
android-node-v8-294d2ea71d5955247b96db6d814d5080cd91d36f.zip
src: refactor V8ProfilerConnection::DispatchMessage()
- Auto-generate the message id and return it for future use (we can always parse the response to find the message containing the profile instead of relying on the inspector connection being synchornous). - Generate the message from method and parameter strings and create a `StringView` directly to avoid the unnecessary copy in `ToProtocolString()`. PR-URL: https://github.com/nodejs/node/pull/27535 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/inspector_profiler.h')
-rw-r--r--src/inspector_profiler.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/inspector_profiler.h b/src/inspector_profiler.h
index cbe053e578..219405b8c7 100644
--- a/src/inspector_profiler.h
+++ b/src/inspector_profiler.h
@@ -34,7 +34,13 @@ class V8ProfilerConnection {
virtual ~V8ProfilerConnection() = default;
Environment* env() const { return env_; }
- void DispatchMessage(v8::Local<v8::String> message);
+
+ // Dispatch a protocol message, and returns the id of the message.
+ // `method` does not need to be surrounded by quotes.
+ // The optional `params` should be formatted in JSON.
+ // The strings should be in one byte characters - which is enough for
+ // the commands we use here.
+ size_t DispatchMessage(const char* method, const char* params = nullptr);
// Use DispatchMessage() to dispatch necessary inspector messages
// to start and end the profiling.
@@ -55,9 +61,11 @@ class V8ProfilerConnection {
v8::Local<v8::Object> result) = 0;
private:
+ size_t next_id() { return id_++; }
void WriteProfile(v8::Local<v8::String> message);
std::unique_ptr<inspector::InspectorSession> session_;
Environment* env_ = nullptr;
+ size_t id_ = 1;
};
class V8CoverageConnection : public V8ProfilerConnection {