Skip to content

Commit c6e2b8a

Browse files
Matt LoringMylesBorins
Matt Loring
authored andcommitted
deps: backport c4852ea from upstream V8
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]>
1 parent ca3ec90 commit c6e2b8a

File tree

6 files changed

+107
-50
lines changed

6 files changed

+107
-50
lines changed

deps/v8/include/libplatform/v8-tracing.h

+23-9
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,15 @@ class V8_PLATFORM_EXPORT TraceConfig {
209209
void operator=(const TraceConfig&) = delete;
210210
};
211211

212-
class V8_PLATFORM_EXPORT TracingController {
212+
#if defined(_MSC_VER)
213+
#define V8_PLATFORM_NON_EXPORTED_BASE(code) \
214+
__pragma(warning(suppress : 4275)) code
215+
#else
216+
#define V8_PLATFORM_NON_EXPORTED_BASE(code) code
217+
#endif // defined(_MSC_VER)
218+
219+
class V8_PLATFORM_EXPORT TracingController
220+
: public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
213221
public:
214222
enum Mode { DISABLED = 0, RECORDING_MODE };
215223

@@ -227,25 +235,29 @@ class V8_PLATFORM_EXPORT TracingController {
227235
};
228236

229237
TracingController();
230-
~TracingController();
238+
~TracingController() override;
231239
void Initialize(TraceBuffer* trace_buffer);
232-
const uint8_t* GetCategoryGroupEnabled(const char* category_group);
233-
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
240+
241+
// v8::TracingController implementation.
242+
const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
234243
uint64_t AddTraceEvent(
235244
char phase, const uint8_t* category_enabled_flag, const char* name,
236245
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
237246
const char** arg_names, const uint8_t* arg_types,
238247
const uint64_t* arg_values,
239248
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
240-
unsigned int flags);
249+
unsigned int flags) override;
241250
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
242-
const char* name, uint64_t handle);
251+
const char* name, uint64_t handle) override;
252+
void AddTraceStateObserver(
253+
v8::TracingController::TraceStateObserver* observer) override;
254+
void RemoveTraceStateObserver(
255+
v8::TracingController::TraceStateObserver* observer) override;
243256

244257
void StartTracing(TraceConfig* trace_config);
245258
void StopTracing();
246259

247-
void AddTraceStateObserver(Platform::TraceStateObserver* observer);
248-
void RemoveTraceStateObserver(Platform::TraceStateObserver* observer);
260+
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
249261

250262
private:
251263
const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group);
@@ -255,14 +267,16 @@ class V8_PLATFORM_EXPORT TracingController {
255267
std::unique_ptr<TraceBuffer> trace_buffer_;
256268
std::unique_ptr<TraceConfig> trace_config_;
257269
std::unique_ptr<base::Mutex> mutex_;
258-
std::unordered_set<Platform::TraceStateObserver*> observers_;
270+
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
259271
Mode mode_ = DISABLED;
260272

261273
// Disallow copy and assign
262274
TracingController(const TracingController&) = delete;
263275
void operator=(const TracingController&) = delete;
264276
};
265277

278+
#undef V8_PLATFORM_NON_EXPORTED_BASE
279+
266280
} // namespace tracing
267281
} // namespace platform
268282
} // namespace v8

deps/v8/include/v8-platform.h

+75-14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,66 @@ class ConvertableToTraceFormat {
5252
virtual void AppendAsTraceFormat(std::string* out) const = 0;
5353
};
5454

55+
/**
56+
* V8 Tracing controller.
57+
*
58+
* Can be implemented by an embedder to record trace events from V8.
59+
*/
60+
class TracingController {
61+
public:
62+
virtual ~TracingController() = default;
63+
64+
/**
65+
* Called by TRACE_EVENT* macros, don't call this directly.
66+
* The name parameter is a category group for example:
67+
* TRACE_EVENT0("v8,parse", "V8.Parse")
68+
* The pointer returned points to a value with zero or more of the bits
69+
* defined in CategoryGroupEnabledFlags.
70+
**/
71+
virtual const uint8_t* GetCategoryGroupEnabled(const char* name) {
72+
static uint8_t no = 0;
73+
return &no;
74+
}
75+
76+
/**
77+
* Adds a trace event to the platform tracing system. This function call is
78+
* usually the result of a TRACE_* macro from trace_event_common.h when
79+
* tracing and the category of the particular trace are enabled. It is not
80+
* advisable to call this function on its own; it is really only meant to be
81+
* used by the trace macros. The returned handle can be used by
82+
* UpdateTraceEventDuration to update the duration of COMPLETE events.
83+
*/
84+
virtual uint64_t AddTraceEvent(
85+
char phase, const uint8_t* category_enabled_flag, const char* name,
86+
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
87+
const char** arg_names, const uint8_t* arg_types,
88+
const uint64_t* arg_values,
89+
std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
90+
unsigned int flags) {
91+
return 0;
92+
}
93+
94+
/**
95+
* Sets the duration field of a COMPLETE trace event. It must be called with
96+
* the handle returned from AddTraceEvent().
97+
**/
98+
virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
99+
const char* name, uint64_t handle) {}
100+
101+
class TraceStateObserver {
102+
public:
103+
virtual ~TraceStateObserver() = default;
104+
virtual void OnTraceEnabled() = 0;
105+
virtual void OnTraceDisabled() = 0;
106+
};
107+
108+
/** Adds tracing state change observer. */
109+
virtual void AddTraceStateObserver(TraceStateObserver*) {}
110+
111+
/** Removes tracing state change observer. */
112+
virtual void RemoveTraceStateObserver(TraceStateObserver*) {}
113+
};
114+
55115
/**
56116
* V8 Platform abstraction layer.
57117
*
@@ -135,6 +195,20 @@ class Platform {
135195
* the epoch.
136196
**/
137197
virtual double MonotonicallyIncreasingTime() = 0;
198+
typedef void (*StackTracePrinter)();
199+
200+
/**
201+
* Returns a function pointer that print a stack trace of the current stack
202+
* on invocation. Disables printing of the stack trace if nullptr.
203+
*/
204+
virtual StackTracePrinter GetStackTracePrinter() { return nullptr; }
205+
206+
/**
207+
* Returns an instance of a v8::TracingController. This must be non-nullptr.
208+
*/
209+
virtual TracingController* GetTracingController() { return nullptr; }
210+
211+
// DEPRECATED methods, use TracingController interface instead.
138212

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

203-
class TraceStateObserver {
204-
public:
205-
virtual ~TraceStateObserver() = default;
206-
virtual void OnTraceEnabled() = 0;
207-
virtual void OnTraceDisabled() = 0;
208-
};
277+
typedef v8::TracingController::TraceStateObserver TraceStateObserver;
209278

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

213282
/** Removes tracing state change observer. */
214283
virtual void RemoveTraceStateObserver(TraceStateObserver*) {}
215-
216-
typedef void (*StackTracePrinter)();
217-
218-
/**
219-
* Returns a function pointer that print a stack trace of the current stack
220-
* on invocation. Disables printing of the stack trace if nullptr.
221-
*/
222-
virtual StackTracePrinter GetStackTracePrinter() { return nullptr; }
223284
};
224285

225286
} // namespace v8

deps/v8/src/libplatform/default-platform.cc

+4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ double DefaultPlatform::MonotonicallyIncreasingTime() {
272272
static_cast<double>(base::Time::kMicrosecondsPerSecond);
273273
}
274274

275+
TracingController* DefaultPlatform::GetTracingController() {
276+
return tracing_controller_.get();
277+
}
278+
275279
uint64_t DefaultPlatform::AddTraceEvent(
276280
char phase, const uint8_t* category_enabled_flag, const char* name,
277281
const char* scope, uint64_t id, uint64_t bind_id, int num_args,

deps/v8/src/libplatform/default-platform.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
5858
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override;
5959
bool IdleTasksEnabled(Isolate* isolate) override;
6060
double MonotonicallyIncreasingTime() override;
61+
TracingController* GetTracingController() override;
6162
const uint8_t* GetCategoryGroupEnabled(const char* name) override;
6263
const char* GetCategoryGroupName(
6364
const uint8_t* category_enabled_flag) override;

deps/v8/src/libplatform/tracing/tracing-controller.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const char* TracingController::GetCategoryGroupName(
9898

9999
void TracingController::StartTracing(TraceConfig* trace_config) {
100100
trace_config_.reset(trace_config);
101-
std::unordered_set<Platform::TraceStateObserver*> observers_copy;
101+
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
102102
{
103103
base::LockGuard<base::Mutex> lock(mutex_.get());
104104
mode_ = RECORDING_MODE;
@@ -113,7 +113,7 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
113113
void TracingController::StopTracing() {
114114
mode_ = DISABLED;
115115
UpdateCategoryGroupEnabledFlags();
116-
std::unordered_set<Platform::TraceStateObserver*> observers_copy;
116+
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
117117
{
118118
base::LockGuard<base::Mutex> lock(mutex_.get());
119119
observers_copy = observers_;
@@ -196,7 +196,7 @@ const uint8_t* TracingController::GetCategoryGroupEnabledInternal(
196196
}
197197

198198
void TracingController::AddTraceStateObserver(
199-
Platform::TraceStateObserver* observer) {
199+
v8::TracingController::TraceStateObserver* observer) {
200200
{
201201
base::LockGuard<base::Mutex> lock(mutex_.get());
202202
observers_.insert(observer);
@@ -207,7 +207,7 @@ void TracingController::AddTraceStateObserver(
207207
}
208208

209209
void TracingController::RemoveTraceStateObserver(
210-
Platform::TraceStateObserver* observer) {
210+
v8::TracingController::TraceStateObserver* observer) {
211211
base::LockGuard<base::Mutex> lock(mutex_.get());
212212
DCHECK(observers_.find(observer) != observers_.end());
213213
observers_.erase(observer);

deps/v8/test/cctest/heap/test-incremental-marking.cc

-23
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,6 @@ class MockPlatform : public v8::Platform {
7171
delete task;
7272
}
7373

74-
using Platform::AddTraceEvent;
75-
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
76-
const char* name, const char* scope, uint64_t id,
77-
uint64_t bind_id, int numArgs, const char** argNames,
78-
const uint8_t* argTypes, const uint64_t* argValues,
79-
unsigned int flags) override {
80-
return 0;
81-
}
82-
83-
void UpdateTraceEventDuration(const uint8_t* categoryEnabledFlag,
84-
const char* name, uint64_t handle) override {}
85-
86-
const uint8_t* GetCategoryGroupEnabled(const char* name) override {
87-
static uint8_t no = 0;
88-
return &no;
89-
}
90-
91-
const char* GetCategoryGroupName(
92-
const uint8_t* categoryEnabledFlag) override {
93-
static const char* dummy = "dummy";
94-
return dummy;
95-
}
96-
9774
private:
9875
v8::Platform* platform_;
9976
Task* task_;

0 commit comments

Comments
 (0)