Commit 1def6cd4 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[cpu-profiler] Automatically create TracingCpuProfiler

Previously embedder had to create an instance of TracingCpuProfiler explicitly.
The patch makes the profiler created automatically for every isolate.
The profiler has no overhead unless tracing with v8.cpu_profiler category is enabled.

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I9369c2c56bcddc72093eda33dc2bc185c9253b4a
Reviewed-on: https://chromium-review.googlesource.com/1006049
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52552}
parent c7393ac8
......@@ -54,7 +54,11 @@ namespace v8 {
*/
class V8_EXPORT TracingCpuProfiler {
public:
static std::unique_ptr<TracingCpuProfiler> Create(Isolate*);
V8_DEPRECATE_SOON(
"The profiler is created automatically with the isolate.\n"
"No need to create it explicitly.",
static std::unique_ptr<TracingCpuProfiler> Create(Isolate*));
virtual ~TracingCpuProfiler() = default;
protected:
......
......@@ -42,6 +42,7 @@
#include "src/objects/frame-array-inl.h"
#include "src/objects/promise-inl.h"
#include "src/profiler/cpu-profiler.h"
#include "src/profiler/tracing-cpu-profiler.h"
#include "src/prototype.h"
#include "src/regexp/regexp-stack.h"
#include "src/runtime-profiler.h"
......@@ -2591,6 +2592,8 @@ Isolate::Isolate(bool enable_serializer)
InitializeLoggingAndCounters();
debug_ = new Debug(this);
tracing_cpu_profiler_.reset(new TracingCpuProfilerImpl(this));
init_memcopy_functions(this);
}
......@@ -2598,6 +2601,7 @@ Isolate::Isolate(bool enable_serializer)
void Isolate::TearDown() {
TRACE_ISOLATE(tear_down);
tracing_cpu_profiler_.reset();
if (FLAG_stress_sampling_allocation_profiler > 0) {
heap_profiler()->StopSamplingHeapProfiler();
}
......
......@@ -100,6 +100,7 @@ class SweeperThread;
class ThreadManager;
class ThreadState;
class ThreadVisitor; // Defined in v8threads.h
class TracingCpuProfilerImpl;
class UnicodeCache;
template <StateTag Tag> class VMState;
......@@ -1678,6 +1679,8 @@ class Isolate {
std::unique_ptr<wasm::WasmEngine> wasm_engine_;
std::unique_ptr<TracingCpuProfilerImpl> tracing_cpu_profiler_;
// The top entry of the v8::Context::BackupIncumbentScope stack.
const v8::Context::BackupIncumbentScope* top_backup_incumbent_scope_ =
nullptr;
......
......@@ -12,9 +12,10 @@ namespace v8 {
std::unique_ptr<TracingCpuProfiler> TracingCpuProfiler::Create(
v8::Isolate* isolate) {
return std::unique_ptr<TracingCpuProfiler>(
new internal::TracingCpuProfilerImpl(
reinterpret_cast<internal::Isolate*>(isolate)));
// Dummy profiler that does nothing.
// Remove it along with the deprecated code.
// The actual profiler is created by the isolate itself.
return std::unique_ptr<TracingCpuProfiler>(new TracingCpuProfiler());
}
namespace internal {
......
......@@ -2244,7 +2244,6 @@ TEST(TracingCpuProfiler) {
v8::HandleScope scope(env->GetIsolate());
{
tracing_controller->StartTracing(trace_config);
auto profiler = v8::TracingCpuProfiler::Create(env->GetIsolate());
CompileRun("function foo() { } foo();");
tracing_controller->StopTracing();
CompileRun("function bar() { } bar();");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment