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 R=fmeawad@chromium.org 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 <jochen@chromium.org> Reviewed-by: Fadi Meawad <fmeawad@chromium.org> Cr-Commit-Position: refs/heads/master@{#46118}
This commit is contained in:
parent
a1a05e5e86
commit
c4852ea94c
@ -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 };
|
||||
|
||||
@ -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);
|
||||
@ -255,7 +267,7 @@ 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
|
||||
@ -263,6 +275,8 @@ class V8_PLATFORM_EXPORT TracingController {
|
||||
void operator=(const TracingController&) = delete;
|
||||
};
|
||||
|
||||
#undef V8_PLATFORM_NON_EXPORTED_BASE
|
||||
|
||||
} // namespace tracing
|
||||
} // namespace platform
|
||||
} // namespace v8
|
||||
|
@ -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.
|
||||
*
|
||||
@ -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.
|
||||
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
@ -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_;
|
||||
@ -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);
|
||||
@ -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);
|
||||
|
@ -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_;
|
||||
|
Loading…
Reference in New Issue
Block a user