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-19 15:38:23 +0800
commite0e308448240260c207958dfc3dd9245d903af85 (patch)
tree611f54d2aac113f735f7a3047f2857561192e969 /src/inspector_profiler.h
parent57ab3b56fcba725e1af4ed7f8a05bbdbd0b8a4d9 (diff)
downloadandroid-node-v8-e0e308448240260c207958dfc3dd9245d903af85.tar.gz
android-node-v8-e0e308448240260c207958dfc3dd9245d903af85.tar.bz2
android-node-v8-e0e308448240260c207958dfc3dd9245d903af85.zip
inspector: implement --cpu-prof[-path]
This patch introduces a CLI flag --cpu-prof that starts the V8 CPU profiler on start up, and ends the profiler then writes the CPU profile before the Node.js instance (on the main thread or the worker thread) exits. By default the profile is written to `${cwd}/CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile`. The patch also introduces a --cpu-prof-path flag for the user to specify the path the profile will be written to. Refs: https://github.com/nodejs/node/issues/26878 PR-URL: https://github.com/nodejs/node/pull/27147 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/inspector_profiler.h')
-rw-r--r--src/inspector_profiler.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/inspector_profiler.h b/src/inspector_profiler.h
index 43a8d54163..7120819c13 100644
--- a/src/inspector_profiler.h
+++ b/src/inspector_profiler.h
@@ -68,6 +68,24 @@ class V8CoverageConnection : public V8ProfilerConnection {
bool ending_ = false;
};
+class V8CpuProfilerConnection : public V8ProfilerConnection {
+ public:
+ explicit V8CpuProfilerConnection(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:
+ void WriteCpuProfile(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