Skip to content

Commit

Permalink
deps: backport 3d8e87a from upstream V8
Browse files Browse the repository at this point in the history
Original commit message:

  Switch tracing to use v8::TracingController

  BUG=v8:6511
  [email protected]

  Cq-Include-Trybots:
  master.tryserver.chromium.linux:linux_chromium_rel_ng
  Change-Id: I4961e4b61a9ddc98385ed97c3ffcbcaef2d9cba7
  Reviewed-on: https://chromium-review.googlesource.com/543144
  Commit-Queue: Jochen Eisinger <[email protected]>
  Reviewed-by: Fadi Meawad <[email protected]>
  Cr-Commit-Position: refs/heads/master@{#46307}

PR-URL: #14001
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
Matt Loring authored and MylesBorins committed Sep 12, 2017
1 parent 6cb718b commit 6e2f622
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 181 deletions.
2 changes: 2 additions & 0 deletions deps/v8/include/libplatform/libplatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
* Attempts to set the tracing controller for the given platform.
*
* The |platform| has to be created using |CreateDefaultPlatform|.
*
* DEPRECATED: Will be removed soon.
*/
V8_PLATFORM_EXPORT void SetTracingController(
v8::Platform* platform,
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/include/v8-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class Platform {
/**
* Returns an instance of a v8::TracingController. This must be non-nullptr.
*/
virtual TracingController* GetTracingController() { return nullptr; }
virtual TracingController* GetTracingController() = 0;

// DEPRECATED methods, use TracingController interface instead.

Expand Down
32 changes: 17 additions & 15 deletions deps/v8/src/d8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class PredictablePlatform : public Platform {
return synthetic_time_in_sec_ += 0.00001;
}

v8::TracingController* GetTracingController() override {
return platform_->GetTracingController();
}

using Platform::AddTraceEvent;
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, const char* scope, uint64_t id,
Expand Down Expand Up @@ -3063,18 +3067,7 @@ int Shell::Main(int argc, char* argv[]) {
if (!SetOptions(argc, argv)) return 1;
v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file);

v8::platform::InProcessStackDumping in_process_stack_dumping =
options.disable_in_process_stack_traces
? v8::platform::InProcessStackDumping::kDisabled
: v8::platform::InProcessStackDumping::kEnabled;

g_platform = i::FLAG_verify_predictable
? new PredictablePlatform()
: v8::platform::CreateDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled,
in_process_stack_dumping);

platform::tracing::TracingController* tracing_controller;
platform::tracing::TracingController* tracing_controller = nullptr;
if (options.trace_enabled) {
trace_file.open("v8_trace.json");
tracing_controller = new platform::tracing::TracingController();
Expand All @@ -3083,11 +3076,20 @@ int Shell::Main(int argc, char* argv[]) {
platform::tracing::TraceBuffer::kRingBufferChunks,
platform::tracing::TraceWriter::CreateJSONTraceWriter(trace_file));
tracing_controller->Initialize(trace_buffer);
if (!i::FLAG_verify_predictable) {
platform::SetTracingController(g_platform, tracing_controller);
}
}

v8::platform::InProcessStackDumping in_process_stack_dumping =
options.disable_in_process_stack_traces
? v8::platform::InProcessStackDumping::kDisabled
: v8::platform::InProcessStackDumping::kEnabled;

g_platform = i::FLAG_verify_predictable
? new PredictablePlatform()
: v8::platform::CreateDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled,
in_process_stack_dumping,
tracing_controller);

v8::V8::InitializePlatform(g_platform);
v8::V8::Initialize();
if (options.natives_blob || options.snapshot_blob) {
Expand Down
75 changes: 20 additions & 55 deletions deps/v8/src/libplatform/default-platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/base/sys-info.h"
#include "src/libplatform/tracing/trace-buffer.h"
#include "src/libplatform/tracing/trace-writer.h"
#include "src/libplatform/worker-thread.h"

namespace v8 {
Expand All @@ -36,11 +38,10 @@ v8::Platform* CreateDefaultPlatform(int thread_pool_size,
if (in_process_stack_dumping == InProcessStackDumping::kEnabled) {
v8::base::debug::EnableInProcessStackDumping();
}
DefaultPlatform* platform = new DefaultPlatform(idle_task_support);
DefaultPlatform* platform =
new DefaultPlatform(idle_task_support, tracing_controller);
platform->SetThreadPoolSize(thread_pool_size);
platform->EnsureInitialized();
if (tracing_controller != nullptr)
platform->SetTracingController(tracing_controller);
return platform;
}

Expand Down Expand Up @@ -70,10 +71,22 @@ void SetTracingController(

const int DefaultPlatform::kMaxThreadPoolSize = 8;

DefaultPlatform::DefaultPlatform(IdleTaskSupport idle_task_support)
DefaultPlatform::DefaultPlatform(IdleTaskSupport idle_task_support,
v8::TracingController* tracing_controller)
: initialized_(false),
thread_pool_size_(0),
idle_task_support_(idle_task_support) {}
idle_task_support_(idle_task_support) {
if (tracing_controller) {
tracing_controller_.reset(tracing_controller);
} else {
tracing::TraceWriter* writer = new tracing::NullTraceWriter();
tracing::TraceBuffer* ring_buffer =
new tracing::TraceBufferRingBuffer(1, writer);
tracing::TracingController* controller = new tracing::TracingController();
controller->Initialize(ring_buffer);
tracing_controller_.reset(controller);
}
}

DefaultPlatform::~DefaultPlatform() {
base::LockGuard<base::Mutex> guard(&lock_);
Expand Down Expand Up @@ -274,64 +287,16 @@ TracingController* DefaultPlatform::GetTracingController() {
return tracing_controller_.get();
}

uint64_t DefaultPlatform::AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) {
if (tracing_controller_) {
return tracing_controller_->AddTraceEvent(
phase, category_enabled_flag, name, scope, id, bind_id, num_args,
arg_names, arg_types, arg_values, arg_convertables, flags);
}

return 0;
}

void DefaultPlatform::UpdateTraceEventDuration(
const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {
if (tracing_controller_) {
tracing_controller_->UpdateTraceEventDuration(category_enabled_flag, name,
handle);
}
}

const uint8_t* DefaultPlatform::GetCategoryGroupEnabled(const char* name) {
if (tracing_controller_) {
return tracing_controller_->GetCategoryGroupEnabled(name);
}
static uint8_t no = 0;
return &no;
}


const char* DefaultPlatform::GetCategoryGroupName(
const uint8_t* category_enabled_flag) {
static const char dummy[] = "dummy";
return dummy;
}

void DefaultPlatform::SetTracingController(
TracingController* tracing_controller) {
v8::TracingController* tracing_controller) {
DCHECK_NOT_NULL(tracing_controller);
tracing_controller_.reset(tracing_controller);
}

size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() {
return static_cast<size_t>(thread_pool_size_);
}

void DefaultPlatform::AddTraceStateObserver(TraceStateObserver* observer) {
if (!tracing_controller_) return;
tracing_controller_->AddTraceStateObserver(observer);
}

void DefaultPlatform::RemoveTraceStateObserver(TraceStateObserver* observer) {
if (!tracing_controller_) return;
tracing_controller_->RemoveTraceStateObserver(observer);
}

Platform::StackTracePrinter DefaultPlatform::GetStackTracePrinter() {
return PrintStackTrace;
}
Expand Down
24 changes: 5 additions & 19 deletions deps/v8/src/libplatform/default-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class WorkerThread;
class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
public:
explicit DefaultPlatform(
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled);
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
v8::TracingController* tracing_controller = nullptr);
virtual ~DefaultPlatform();

void SetThreadPoolSize(int thread_pool_size);
Expand All @@ -44,6 +45,8 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {

void RunIdleTasks(v8::Isolate* isolate, double idle_time_in_seconds);

void SetTracingController(v8::TracingController* tracing_controller);

// v8::Platform implementation.
size_t NumberOfAvailableBackgroundThreads() override;
void CallOnBackgroundThread(Task* task,
Expand All @@ -54,24 +57,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override;
bool IdleTasksEnabled(Isolate* isolate) override;
double MonotonicallyIncreasingTime() override;
TracingController* GetTracingController() override;
const uint8_t* GetCategoryGroupEnabled(const char* name) override;
const char* GetCategoryGroupName(
const uint8_t* category_enabled_flag) override;
using Platform::AddTraceEvent;
uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) override;
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) override;
void SetTracingController(TracingController* tracing_controller);

void AddTraceStateObserver(TraceStateObserver* observer) override;
void RemoveTraceStateObserver(TraceStateObserver* observer) override;
v8::TracingController* GetTracingController() override;
StackTracePrinter GetStackTracePrinter() override;

private:
Expand Down
8 changes: 8 additions & 0 deletions deps/v8/src/libplatform/tracing/trace-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class JSONTraceWriter : public TraceWriter {
bool append_comma_ = false;
};

class NullTraceWriter : public TraceWriter {
public:
NullTraceWriter() = default;
~NullTraceWriter() = default;
void AppendTraceEvent(TraceObject*) override {}
void Flush() override {}
};

} // namespace tracing
} // namespace platform
} // namespace v8
Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/libplatform/tracing/tracing-controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ v8::base::AtomicWord g_category_index = g_num_builtin_categories;

TracingController::TracingController() {}

TracingController::~TracingController() {}
TracingController::~TracingController() { StopTracing(); }

void TracingController::Initialize(TraceBuffer* trace_buffer) {
trace_buffer_.reset(trace_buffer);
Expand Down Expand Up @@ -111,6 +111,10 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
}

void TracingController::StopTracing() {
if (mode_ == DISABLED) {
return;
}
DCHECK(trace_buffer_);
mode_ = DISABLED;
UpdateCategoryGroupEnabledFlags();
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
Expand Down
5 changes: 3 additions & 2 deletions deps/v8/src/profiler/tracing-cpu-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ TracingCpuProfilerImpl::TracingCpuProfilerImpl(Isolate* isolate)
TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"));
TRACE_EVENT_WARMUP_CATEGORY(
TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler.hires"));
V8::GetCurrentPlatform()->AddTraceStateObserver(this);
V8::GetCurrentPlatform()->GetTracingController()->AddTraceStateObserver(this);
}

TracingCpuProfilerImpl::~TracingCpuProfilerImpl() {
StopProfiling();
V8::GetCurrentPlatform()->RemoveTraceStateObserver(this);
V8::GetCurrentPlatform()->GetTracingController()->RemoveTraceStateObserver(
this);
}

void TracingCpuProfilerImpl::OnTraceEnabled() {
Expand Down
7 changes: 4 additions & 3 deletions deps/v8/src/profiler/tracing-cpu-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ namespace internal {
class CpuProfiler;
class Isolate;

class TracingCpuProfilerImpl final : public TracingCpuProfiler,
private v8::Platform::TraceStateObserver {
class TracingCpuProfilerImpl final
: public TracingCpuProfiler,
private v8::TracingController::TraceStateObserver {
public:
explicit TracingCpuProfilerImpl(Isolate*);
~TracingCpuProfilerImpl();

// v8::Platform::TraceStateObserver
// v8::TracingController::TraceStateObserver
void OnTraceEnabled() final;
void OnTraceDisabled() final;

Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/tracing/trace-event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace v8 {
namespace internal {
namespace tracing {

v8::Platform* TraceEventHelper::GetCurrentPlatform() {
return v8::internal::V8::GetCurrentPlatform();
v8::TracingController* TraceEventHelper::GetTracingController() {
return v8::internal::V8::GetCurrentPlatform()->GetTracingController();
}

void CallStatsScopedTracer::AddEndTraceEvent() {
Expand Down
20 changes: 10 additions & 10 deletions deps/v8/src/tracing/trace-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ enum CategoryGroupEnabledFlags {
// for best performance when tracing is disabled.
// const uint8_t*
// TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
v8::internal::tracing::TraceEventHelper::GetTracingController() \
->GetCategoryGroupEnabled

// Get the number of times traces have been recorded. This is used to implement
Expand Down Expand Up @@ -101,8 +101,8 @@ enum CategoryGroupEnabledFlags {
// const uint8_t* category_group_enabled,
// const char* name,
// uint64_t id)
#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
v8::internal::tracing::TraceEventHelper::GetTracingController() \
->UpdateTraceEventDuration

// Defines atomic operations used internally by the tracing system.
Expand Down Expand Up @@ -277,7 +277,7 @@ const uint64_t kNoId = 0;

class TraceEventHelper {
public:
static v8::Platform* GetCurrentPlatform();
static v8::TracingController* GetTracingController();
};

// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
Expand Down Expand Up @@ -424,11 +424,11 @@ static V8_INLINE uint64_t AddTraceEventImpl(
static_cast<intptr_t>(arg_values[1])));
}
DCHECK(num_args <= 2);
v8::Platform* platform =
v8::internal::tracing::TraceEventHelper::GetCurrentPlatform();
return platform->AddTraceEvent(phase, category_group_enabled, name, scope, id,
bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertables, flags);
v8::TracingController* controller =
v8::internal::tracing::TraceEventHelper::GetTracingController();
return controller->AddTraceEvent(phase, category_group_enabled, name, scope,
id, bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertables, flags);
}

// Define SetTraceValue for each allowed type. It stores the type and
Expand Down
10 changes: 6 additions & 4 deletions deps/v8/src/tracing/tracing-category-observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ TracingCategoryObserver* TracingCategoryObserver::instance_ = nullptr;

void TracingCategoryObserver::SetUp() {
TracingCategoryObserver::instance_ = new TracingCategoryObserver();
v8::internal::V8::GetCurrentPlatform()->AddTraceStateObserver(
TracingCategoryObserver::instance_);
v8::internal::V8::GetCurrentPlatform()
->GetTracingController()
->AddTraceStateObserver(TracingCategoryObserver::instance_);
TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"));
TRACE_EVENT_WARMUP_CATEGORY(
TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling"));
Expand All @@ -25,8 +26,9 @@ void TracingCategoryObserver::SetUp() {
}

void TracingCategoryObserver::TearDown() {
v8::internal::V8::GetCurrentPlatform()->RemoveTraceStateObserver(
TracingCategoryObserver::instance_);
v8::internal::V8::GetCurrentPlatform()
->GetTracingController()
->RemoveTraceStateObserver(TracingCategoryObserver::instance_);
delete TracingCategoryObserver::instance_;
}

Expand Down
Loading

0 comments on commit 6e2f622

Please sign in to comment.