Skip to content

Commit 51054da

Browse files
committed
deps: cherry-pick c3bb73f from upstream V8
Original commit message: [tracing] implement TRACE_EVENT_ADD_WITH_TIMESTAMP Bug: Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: Icb3cf7b7f96704e1eaa4c5fbf773b94b70cddc85 Reviewed-on: https://chromium-review.googlesource.com/861302 Reviewed-by: Fadi Meawad <fmeawad@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com> Cr-Commit-Position: refs/heads/master@{#50549} Refs: v8/v8@c3bb73f Refs: #17349 PR-URL: #18196 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
1 parent 7d7a549 commit 51054da

File tree

6 files changed

+168
-10
lines changed

6 files changed

+168
-10
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Reset this number to 0 on major V8 upgrades.
2929
# Increment by one for each non-official patch applied to deps/v8.
30-
'v8_embedder_string': '-node.7',
30+
'v8_embedder_string': '-node.8',
3131

3232
# Enable disassembler for `--print-code` v8 options
3333
'v8_enable_disassembler': 1,

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ class V8_PLATFORM_EXPORT TracingController
247247
const uint64_t* arg_values,
248248
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
249249
unsigned int flags) override;
250+
uint64_t AddTraceEventWithTimestamp(
251+
char phase, const uint8_t* category_enabled_flag, const char* name,
252+
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
253+
const char** arg_names, const uint8_t* arg_types,
254+
const uint64_t* arg_values,
255+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
256+
unsigned int flags, int64_t timestamp) override;
250257
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
251258
const char* name, uint64_t handle) override;
252259
void AddTraceStateObserver(

deps/v8/include/v8-platform.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ class TracingController {
119119
}
120120

121121
/**
122-
* Adds a trace event to the platform tracing system. This function call is
122+
* Adds a trace event to the platform tracing system. These function calls are
123123
* usually the result of a TRACE_* macro from trace_event_common.h when
124124
* tracing and the category of the particular trace are enabled. It is not
125-
* advisable to call this function on its own; it is really only meant to be
126-
* used by the trace macros. The returned handle can be used by
125+
* advisable to call these functions on their own; they are really only meant
126+
* to be used by the trace macros. The returned handle can be used by
127127
* UpdateTraceEventDuration to update the duration of COMPLETE events.
128128
*/
129129
virtual uint64_t AddTraceEvent(
@@ -135,6 +135,15 @@ class TracingController {
135135
unsigned int flags) {
136136
return 0;
137137
}
138+
virtual uint64_t AddTraceEventWithTimestamp(
139+
char phase, const uint8_t* category_enabled_flag, const char* name,
140+
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
141+
const char** arg_names, const uint8_t* arg_types,
142+
const uint64_t* arg_values,
143+
std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
144+
unsigned int flags, int64_t timestamp) {
145+
return 0;
146+
}
138147

139148
/**
140149
* Sets the duration field of a COMPLETE trace event. It must be called with

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ uint64_t TracingController::AddTraceEvent(
7575
return handle;
7676
}
7777

78+
uint64_t TracingController::AddTraceEventWithTimestamp(
79+
char phase, const uint8_t* category_enabled_flag, const char* name,
80+
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
81+
const char** arg_names, const uint8_t* arg_types,
82+
const uint64_t* arg_values,
83+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
84+
unsigned int flags, int64_t timestamp) {
85+
uint64_t handle;
86+
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
87+
if (trace_object) {
88+
trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
89+
bind_id, num_args, arg_names, arg_types,
90+
arg_values, arg_convertables, flags, timestamp,
91+
CurrentCpuTimestampMicroseconds());
92+
}
93+
return handle;
94+
}
95+
7896
void TracingController::UpdateTraceEventDuration(
7997
const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {
8098
TraceObject* trace_object = trace_buffer_->GetEventByHandle(handle);

deps/v8/src/tracing/trace-event.h

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ enum CategoryGroupEnabledFlags {
9696
// unsigned int flags)
9797
#define TRACE_EVENT_API_ADD_TRACE_EVENT v8::internal::tracing::AddTraceEventImpl
9898

99+
// Add a trace event to the platform tracing system.
100+
// uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
101+
// char phase,
102+
// const uint8_t* category_group_enabled,
103+
// const char* name,
104+
// const char* scope,
105+
// uint64_t id,
106+
// uint64_t bind_id,
107+
// int num_args,
108+
// const char** arg_names,
109+
// const uint8_t* arg_types,
110+
// const uint64_t* arg_values,
111+
// unsigned int flags,
112+
// int64_t timestamp)
113+
#define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP \
114+
v8::internal::tracing::AddTraceEventWithTimestampImpl
115+
99116
// Set the duration field of a COMPLETE trace event.
100117
// void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
101118
// const uint8_t* category_group_enabled,
@@ -212,10 +229,18 @@ enum CategoryGroupEnabledFlags {
212229
} \
213230
} while (0)
214231

215-
// Adds a trace event with a given timestamp. Not Implemented.
232+
// Adds a trace event with a given timestamp.
216233
#define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \
217234
timestamp, flags, ...) \
218-
UNIMPLEMENTED()
235+
do { \
236+
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
237+
if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
238+
v8::internal::tracing::AddTraceEventWithTimestamp( \
239+
phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
240+
v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
241+
v8::internal::tracing::kNoId, flags, timestamp, ##__VA_ARGS__); \
242+
} \
243+
} while (0)
219244

220245
// Adds a trace event with a given id and timestamp. Not Implemented.
221246
#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \
@@ -431,6 +456,28 @@ static V8_INLINE uint64_t AddTraceEventImpl(
431456
arg_values, arg_convertables, flags);
432457
}
433458

459+
static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
460+
char phase, const uint8_t* category_group_enabled, const char* name,
461+
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
462+
const char** arg_names, const uint8_t* arg_types,
463+
const uint64_t* arg_values, unsigned int flags, int64_t timestamp) {
464+
std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2];
465+
if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) {
466+
arg_convertables[0].reset(reinterpret_cast<ConvertableToTraceFormat*>(
467+
static_cast<intptr_t>(arg_values[0])));
468+
}
469+
if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) {
470+
arg_convertables[1].reset(reinterpret_cast<ConvertableToTraceFormat*>(
471+
static_cast<intptr_t>(arg_values[1])));
472+
}
473+
DCHECK_LE(num_args, 2);
474+
v8::TracingController* controller =
475+
v8::internal::tracing::TraceEventHelper::GetTracingController();
476+
return controller->AddTraceEventWithTimestamp(
477+
phase, category_group_enabled, name, scope, id, bind_id, num_args,
478+
arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
479+
}
480+
434481
// Define SetTraceValue for each allowed type. It stores the type and
435482
// value in the return arguments. This allows this API to avoid declaring any
436483
// structures so that it is portable to third_party libraries.
@@ -533,6 +580,48 @@ static V8_INLINE uint64_t AddTraceEvent(
533580
arg_names, arg_types, arg_values, flags);
534581
}
535582

583+
static V8_INLINE uint64_t AddTraceEventWithTimestamp(
584+
char phase, const uint8_t* category_group_enabled, const char* name,
585+
const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
586+
int64_t timestamp) {
587+
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
588+
phase, category_group_enabled, name, scope, id, bind_id, kZeroNumArgs,
589+
nullptr, nullptr, nullptr, flags, timestamp);
590+
}
591+
592+
template <class ARG1_TYPE>
593+
static V8_INLINE uint64_t AddTraceEventWithTimestamp(
594+
char phase, const uint8_t* category_group_enabled, const char* name,
595+
const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
596+
int64_t timestamp, const char* arg1_name, ARG1_TYPE&& arg1_val) {
597+
const int num_args = 1;
598+
uint8_t arg_type;
599+
uint64_t arg_value;
600+
SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
601+
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
602+
phase, category_group_enabled, name, scope, id, bind_id, num_args,
603+
&arg1_name, &arg_type, &arg_value, flags, timestamp);
604+
}
605+
606+
template <class ARG1_TYPE, class ARG2_TYPE>
607+
static V8_INLINE uint64_t AddTraceEventWithTimestamp(
608+
char phase, const uint8_t* category_group_enabled, const char* name,
609+
const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
610+
int64_t timestamp, const char* arg1_name, ARG1_TYPE&& arg1_val,
611+
const char* arg2_name, ARG2_TYPE&& arg2_val) {
612+
const int num_args = 2;
613+
const char* arg_names[2] = {arg1_name, arg2_name};
614+
unsigned char arg_types[2];
615+
uint64_t arg_values[2];
616+
SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0],
617+
&arg_values[0]);
618+
SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1],
619+
&arg_values[1]);
620+
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
621+
phase, category_group_enabled, name, scope, id, bind_id, num_args,
622+
arg_names, arg_types, arg_values, flags, timestamp);
623+
}
624+
536625
// Used by TRACE_EVENTx macros. Do not use directly.
537626
class ScopedTracer {
538627
public:

deps/v8/test/cctest/test-trace-event.cc

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ struct MockTraceObject {
2222
uint64_t bind_id;
2323
int num_args;
2424
unsigned int flags;
25+
int64_t timestamp;
2526
MockTraceObject(char phase, std::string name, uint64_t id, uint64_t bind_id,
26-
int num_args, int flags)
27+
int num_args, int flags, int64_t timestamp)
2728
: phase(phase),
2829
name(name),
2930
id(id),
3031
bind_id(bind_id),
3132
num_args(num_args),
32-
flags(flags) {}
33+
flags(flags),
34+
timestamp(timestamp) {}
3335
};
3436

3537
typedef std::vector<MockTraceObject*> MockTraceObjectList;
@@ -51,8 +53,20 @@ class MockTracingController : public v8::TracingController {
5153
const uint64_t* arg_values,
5254
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
5355
unsigned int flags) override {
54-
MockTraceObject* to = new MockTraceObject(phase, std::string(name), id,
55-
bind_id, num_args, flags);
56+
return AddTraceEventWithTimestamp(
57+
phase, category_enabled_flag, name, scope, id, bind_id, num_args,
58+
arg_names, arg_types, arg_values, arg_convertables, flags, 0);
59+
}
60+
61+
uint64_t AddTraceEventWithTimestamp(
62+
char phase, const uint8_t* category_enabled_flag, const char* name,
63+
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
64+
const char** arg_names, const uint8_t* arg_types,
65+
const uint64_t* arg_values,
66+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
67+
unsigned int flags, int64_t timestamp) override {
68+
MockTraceObject* to = new MockTraceObject(
69+
phase, std::string(name), id, bind_id, num_args, flags, timestamp);
5670
trace_object_list_.push_back(to);
5771
return 0;
5872
}
@@ -239,3 +253,24 @@ TEST(TestEventInContext) {
239253
CHECK_EQ("Isolate", GET_TRACE_OBJECT(2)->name);
240254
CHECK_EQ(isolate_id, GET_TRACE_OBJECT(2)->id);
241255
}
256+
257+
TEST(TestEventWithTimestamp) {
258+
MockTracingPlatform platform;
259+
260+
TRACE_EVENT_INSTANT_WITH_TIMESTAMP0("v8-cat", "0arg",
261+
TRACE_EVENT_SCOPE_GLOBAL, 1729);
262+
TRACE_EVENT_INSTANT_WITH_TIMESTAMP1("v8-cat", "1arg",
263+
TRACE_EVENT_SCOPE_GLOBAL, 4104, "val", 1);
264+
TRACE_EVENT_MARK_WITH_TIMESTAMP2("v8-cat", "mark", 13832, "a", 1, "b", 2);
265+
266+
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
267+
268+
CHECK_EQ(1729, GET_TRACE_OBJECT(0)->timestamp);
269+
CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
270+
271+
CHECK_EQ(4104, GET_TRACE_OBJECT(1)->timestamp);
272+
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
273+
274+
CHECK_EQ(13832, GET_TRACE_OBJECT(2)->timestamp);
275+
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
276+
}

0 commit comments

Comments
 (0)