Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2020-06-09 15:46:52 +0300
committergengjiawen <technicalcute@gmail.com>2020-10-22 13:53:32 +0300
commitfc5636e1eb45949e764f3b1ffbd63e39b2ca30a9 (patch)
treeaeb5ddeeb20fb191a5ae9dd854a72cc5543604b9 /src/inspector_profiler.h
parent7657f62b1810b94acbe7db68089b608213b34749 (diff)
v8: implement v8.takeCoverage()
Add an v8.takeCoverage() API that allows the user to write the coverage started by NODE_V8_COVERAGE to disk on demand. The coverage can be written multiple times during the lifetime of the process, each time the execution counter will be reset. When the process is about to exit, one last coverage will still be written to disk. Also refactors the internal profiler connection code so that we use the inspector response id to identify the profile response instead of using an ad-hoc flag in C++. PR-URL: https://github.com/nodejs/node/pull/33807 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com>
Diffstat (limited to 'src/inspector_profiler.h')
-rw-r--r--src/inspector_profiler.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/inspector_profiler.h b/src/inspector_profiler.h
index 187bc0d1c49..5e861dd0ea0 100644
--- a/src/inspector_profiler.h
+++ b/src/inspector_profiler.h
@@ -7,6 +7,7 @@
#error("This header can only be used when inspector is enabled")
#endif
+#include <unordered_set>
#include "inspector_agent.h"
namespace node {
@@ -39,7 +40,9 @@ class V8ProfilerConnection {
// 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);
+ uint32_t DispatchMessage(const char* method,
+ const char* params = nullptr,
+ bool is_profile_request = false);
// Use DispatchMessage() to dispatch necessary inspector messages
// to start and end the profiling.
@@ -58,12 +61,19 @@ class V8ProfilerConnection {
// which will be then written as a JSON.
virtual v8::MaybeLocal<v8::Object> GetProfile(
v8::Local<v8::Object> result) = 0;
- virtual void WriteProfile(v8::Local<v8::String> message);
+ virtual void WriteProfile(v8::Local<v8::Object> result);
+
+ bool HasProfileId(uint32_t id) const {
+ return profile_ids_.find(id) != profile_ids_.end();
+ }
+
+ void RemoveProfileId(uint32_t id) { profile_ids_.erase(id); }
private:
- size_t next_id() { return id_++; }
+ uint32_t next_id() { return id_++; }
std::unique_ptr<inspector::InspectorSession> session_;
- size_t id_ = 1;
+ uint32_t id_ = 1;
+ std::unordered_set<uint32_t> profile_ids_;
protected:
Environment* env_ = nullptr;
@@ -82,8 +92,9 @@ class V8CoverageConnection : public V8ProfilerConnection {
std::string GetDirectory() const override;
std::string GetFilename() const override;
v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
- void WriteProfile(v8::Local<v8::String> message) override;
+ void WriteProfile(v8::Local<v8::Object> result) override;
void WriteSourceMapCache();
+ void TakeCoverage();
private:
std::unique_ptr<inspector::InspectorSession> session_;