From e0e308448240260c207958dfc3dd9245d903af85 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 23 Mar 2019 07:39:52 +0800 Subject: 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 --- src/inspector_profiler.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/inspector_profiler.h') 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 message); + v8::MaybeLocal GetResult(v8::Local message); + + std::unique_ptr session_; + bool ending_ = false; +}; + } // namespace profiler } // namespace node -- cgit v1.2.3