Skip to content

Commit

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

  Pull tracing related methods out of Platform
  This will allow for embedders to easily implement their own Platform
  without duplicating the tracing controller code.

  BUG=v8:6511
  [email protected]

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

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 ca3ec90 commit c6e2b8a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 50 deletions.
32 changes: 23 additions & 9 deletions deps/v8/include/libplatform/v8-tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ class V8_PLATFORM_EXPORT TraceConfig {
void operator=(const TraceConfig&) = delete;
};

class V8_PLATFORM_EXPORT TracingController {
#if defined(_MSC_VER)
#define V8_PLATFORM_NON_EXPORTED_BASE(code) \
__pragma(warning(suppress : 4275)) code
#else
#define V8_PLATFORM_NON_EXPORTED_BASE(code) code
#endif // defined(_MSC_VER)

class V8_PLATFORM_EXPORT TracingController
: public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
public:
enum Mode { DISABLED = 0, RECORDING_MODE };

Expand All @@ -227,25 +235,29 @@ class V8_PLATFORM_EXPORT TracingController {
};

TracingController();
~TracingController();
~TracingController() override;
void Initialize(TraceBuffer* trace_buffer);
const uint8_t* GetCategoryGroupEnabled(const char* category_group);
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);

// v8::TracingController implementation.
const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
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);
unsigned int flags) override;
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle);
const char* name, uint64_t handle) override;
void AddTraceStateObserver(
v8::TracingController::TraceStateObserver* observer) override;
void RemoveTraceStateObserver(
v8::TracingController::TraceStateObserver* observer) override;

void StartTracing(TraceConfig* trace_config);
void StopTracing();

void AddTraceStateObserver(Platform::TraceStateObserver* observer);
void RemoveTraceStateObserver(Platform::TraceStateObserver* observer);
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);

private:
const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group);
Expand All @@ -255,14 +267,16 @@ class V8_PLATFORM_EXPORT TracingController {
std::unique_ptr<TraceBuffer> trace_buffer_;
std::unique_ptr<TraceConfig> trace_config_;
std::unique_ptr<base::Mutex> mutex_;
std::unordered_set<Platform::TraceStateObserver*> observers_;
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
Mode mode_ = DISABLED;

// Disallow copy and assign
TracingController(const TracingController&) = delete;
void operator=(const TracingController&) = delete;
};

#undef V8_PLATFORM_NON_EXPORTED_BASE

} // namespace tracing
} // namespace platform
} // namespace v8
Expand Down
89 changes: 75 additions & 14 deletions deps/v8/include/v8-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,66 @@ class ConvertableToTraceFormat {
virtual void AppendAsTraceFormat(std::string* out) const = 0;
};

/**
* V8 Tracing controller.
*
* Can be implemented by an embedder to record trace events from V8.
*/
class TracingController {
public:
virtual ~TracingController() = default;

/**
* Called by TRACE_EVENT* macros, don't call this directly.
* The name parameter is a category group for example:
* TRACE_EVENT0("v8,parse", "V8.Parse")
* The pointer returned points to a value with zero or more of the bits
* defined in CategoryGroupEnabledFlags.
**/
virtual const uint8_t* GetCategoryGroupEnabled(const char* name) {
static uint8_t no = 0;
return &no;
}

/**
* Adds a trace event to the platform tracing system. This function call is
* usually the result of a TRACE_* macro from trace_event_common.h when
* tracing and the category of the particular trace are enabled. It is not
* advisable to call this function on its own; it is really only meant to be
* used by the trace macros. The returned handle can be used by
* UpdateTraceEventDuration to update the duration of COMPLETE events.
*/
virtual 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<ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) {
return 0;
}

/**
* Sets the duration field of a COMPLETE trace event. It must be called with
* the handle returned from AddTraceEvent().
**/
virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) {}

class TraceStateObserver {
public:
virtual ~TraceStateObserver() = default;
virtual void OnTraceEnabled() = 0;
virtual void OnTraceDisabled() = 0;
};

/** Adds tracing state change observer. */
virtual void AddTraceStateObserver(TraceStateObserver*) {}

/** Removes tracing state change observer. */
virtual void RemoveTraceStateObserver(TraceStateObserver*) {}
};

/**
* V8 Platform abstraction layer.
*
Expand Down Expand Up @@ -135,6 +195,20 @@ class Platform {
* the epoch.
**/
virtual double MonotonicallyIncreasingTime() = 0;
typedef void (*StackTracePrinter)();

/**
* Returns a function pointer that print a stack trace of the current stack
* on invocation. Disables printing of the stack trace if nullptr.
*/
virtual StackTracePrinter GetStackTracePrinter() { return nullptr; }

/**
* Returns an instance of a v8::TracingController. This must be non-nullptr.
*/
virtual TracingController* GetTracingController() { return nullptr; }

// DEPRECATED methods, use TracingController interface instead.

/**
* Called by TRACE_EVENT* macros, don't call this directly.
Expand Down Expand Up @@ -200,26 +274,13 @@ class Platform {
virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) {}

class TraceStateObserver {
public:
virtual ~TraceStateObserver() = default;
virtual void OnTraceEnabled() = 0;
virtual void OnTraceDisabled() = 0;
};
typedef v8::TracingController::TraceStateObserver TraceStateObserver;

/** Adds tracing state change observer. */
virtual void AddTraceStateObserver(TraceStateObserver*) {}

/** Removes tracing state change observer. */
virtual void RemoveTraceStateObserver(TraceStateObserver*) {}

typedef void (*StackTracePrinter)();

/**
* Returns a function pointer that print a stack trace of the current stack
* on invocation. Disables printing of the stack trace if nullptr.
*/
virtual StackTracePrinter GetStackTracePrinter() { return nullptr; }
};

} // namespace v8
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/libplatform/default-platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ double DefaultPlatform::MonotonicallyIncreasingTime() {
static_cast<double>(base::Time::kMicrosecondsPerSecond);
}

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,
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/libplatform/default-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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;
Expand Down
8 changes: 4 additions & 4 deletions deps/v8/src/libplatform/tracing/tracing-controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const char* TracingController::GetCategoryGroupName(

void TracingController::StartTracing(TraceConfig* trace_config) {
trace_config_.reset(trace_config);
std::unordered_set<Platform::TraceStateObserver*> observers_copy;
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
{
base::LockGuard<base::Mutex> lock(mutex_.get());
mode_ = RECORDING_MODE;
Expand All @@ -113,7 +113,7 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
void TracingController::StopTracing() {
mode_ = DISABLED;
UpdateCategoryGroupEnabledFlags();
std::unordered_set<Platform::TraceStateObserver*> observers_copy;
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
{
base::LockGuard<base::Mutex> lock(mutex_.get());
observers_copy = observers_;
Expand Down Expand Up @@ -196,7 +196,7 @@ const uint8_t* TracingController::GetCategoryGroupEnabledInternal(
}

void TracingController::AddTraceStateObserver(
Platform::TraceStateObserver* observer) {
v8::TracingController::TraceStateObserver* observer) {
{
base::LockGuard<base::Mutex> lock(mutex_.get());
observers_.insert(observer);
Expand All @@ -207,7 +207,7 @@ void TracingController::AddTraceStateObserver(
}

void TracingController::RemoveTraceStateObserver(
Platform::TraceStateObserver* observer) {
v8::TracingController::TraceStateObserver* observer) {
base::LockGuard<base::Mutex> lock(mutex_.get());
DCHECK(observers_.find(observer) != observers_.end());
observers_.erase(observer);
Expand Down
23 changes: 0 additions & 23 deletions deps/v8/test/cctest/heap/test-incremental-marking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,6 @@ class MockPlatform : public v8::Platform {
delete task;
}

using Platform::AddTraceEvent;
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, const char* scope, uint64_t id,
uint64_t bind_id, int numArgs, const char** argNames,
const uint8_t* argTypes, const uint64_t* argValues,
unsigned int flags) override {
return 0;
}

void UpdateTraceEventDuration(const uint8_t* categoryEnabledFlag,
const char* name, uint64_t handle) override {}

const uint8_t* GetCategoryGroupEnabled(const char* name) override {
static uint8_t no = 0;
return &no;
}

const char* GetCategoryGroupName(
const uint8_t* categoryEnabledFlag) override {
static const char* dummy = "dummy";
return dummy;
}

private:
v8::Platform* platform_;
Task* task_;
Expand Down

0 comments on commit c6e2b8a

Please sign in to comment.