summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Ijaz Sheikh <ofrobots@google.com>2018-01-16 16:49:14 -0800
committerAli Ijaz Sheikh <ofrobots@google.com>2018-01-24 09:58:16 -0800
commit51054dac541cdefabe54a076f009ebf4c3c5d144 (patch)
treefad392485c17f74b165d56628d48f5357ec87d7a
parent7d7a549219baeecadbbd6e2b9b29b57fd80897f7 (diff)
downloadnode-new-51054dac541cdefabe54a076f009ebf4c3c5d144.tar.gz
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: https://github.com/v8/v8/commit/c3bb73f6b95c280cee3a4d6b03c87fce93d617c7 Refs: https://github.com/nodejs/node/issues/17349 PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r--common.gypi2
-rw-r--r--deps/v8/include/libplatform/v8-tracing.h7
-rw-r--r--deps/v8/include/v8-platform.h15
-rw-r--r--deps/v8/src/libplatform/tracing/tracing-controller.cc18
-rw-r--r--deps/v8/src/tracing/trace-event.h93
-rw-r--r--deps/v8/test/cctest/test-trace-event.cc43
6 files changed, 168 insertions, 10 deletions
diff --git a/common.gypi b/common.gypi
index 2cd0db7dc4..7cceef8759 100644
--- a/common.gypi
+++ b/common.gypi
@@ -27,7 +27,7 @@
# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
- 'v8_embedder_string': '-node.7',
+ 'v8_embedder_string': '-node.8',
# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
diff --git a/deps/v8/include/libplatform/v8-tracing.h b/deps/v8/include/libplatform/v8-tracing.h
index 55189b4837..9dcf3d7bca 100644
--- a/deps/v8/include/libplatform/v8-tracing.h
+++ b/deps/v8/include/libplatform/v8-tracing.h
@@ -247,6 +247,13 @@ class V8_PLATFORM_EXPORT TracingController
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) override;
+ uint64_t AddTraceEventWithTimestamp(
+ 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, int64_t timestamp) override;
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) override;
void AddTraceStateObserver(
diff --git a/deps/v8/include/v8-platform.h b/deps/v8/include/v8-platform.h
index f814543e66..43420a972c 100644
--- a/deps/v8/include/v8-platform.h
+++ b/deps/v8/include/v8-platform.h
@@ -119,11 +119,11 @@ class TracingController {
}
/**
- * Adds a trace event to the platform tracing system. This function call is
+ * Adds a trace event to the platform tracing system. These function calls are
* 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
+ * advisable to call these functions on their own; they are 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(
@@ -135,6 +135,15 @@ class TracingController {
unsigned int flags) {
return 0;
}
+ virtual uint64_t AddTraceEventWithTimestamp(
+ 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, int64_t timestamp) {
+ return 0;
+ }
/**
* Sets the duration field of a COMPLETE trace event. It must be called with
diff --git a/deps/v8/src/libplatform/tracing/tracing-controller.cc b/deps/v8/src/libplatform/tracing/tracing-controller.cc
index 372a152f83..c024f18291 100644
--- a/deps/v8/src/libplatform/tracing/tracing-controller.cc
+++ b/deps/v8/src/libplatform/tracing/tracing-controller.cc
@@ -75,6 +75,24 @@ uint64_t TracingController::AddTraceEvent(
return handle;
}
+uint64_t TracingController::AddTraceEventWithTimestamp(
+ 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, int64_t timestamp) {
+ uint64_t handle;
+ TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
+ if (trace_object) {
+ trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
+ bind_id, num_args, arg_names, arg_types,
+ arg_values, arg_convertables, flags, timestamp,
+ CurrentCpuTimestampMicroseconds());
+ }
+ return handle;
+}
+
void TracingController::UpdateTraceEventDuration(
const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {
TraceObject* trace_object = trace_buffer_->GetEventByHandle(handle);
diff --git a/deps/v8/src/tracing/trace-event.h b/deps/v8/src/tracing/trace-event.h
index 6ca39506f4..0ff2b82503 100644
--- a/deps/v8/src/tracing/trace-event.h
+++ b/deps/v8/src/tracing/trace-event.h
@@ -96,6 +96,23 @@ enum CategoryGroupEnabledFlags {
// unsigned int flags)
#define TRACE_EVENT_API_ADD_TRACE_EVENT v8::internal::tracing::AddTraceEventImpl
+// Add a trace event to the platform tracing system.
+// uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
+// char phase,
+// const uint8_t* category_group_enabled,
+// 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,
+// unsigned int flags,
+// int64_t timestamp)
+#define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP \
+ v8::internal::tracing::AddTraceEventWithTimestampImpl
+
// Set the duration field of a COMPLETE trace event.
// void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
// const uint8_t* category_group_enabled,
@@ -212,10 +229,18 @@ enum CategoryGroupEnabledFlags {
} \
} while (0)
-// Adds a trace event with a given timestamp. Not Implemented.
+// Adds a trace event with a given timestamp.
#define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \
timestamp, flags, ...) \
- UNIMPLEMENTED()
+ do { \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
+ v8::internal::tracing::AddTraceEventWithTimestamp( \
+ phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
+ v8::internal::tracing::kNoId, flags, timestamp, ##__VA_ARGS__); \
+ } \
+ } while (0)
// Adds a trace event with a given id and timestamp. Not Implemented.
#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \
@@ -431,6 +456,28 @@ static V8_INLINE uint64_t AddTraceEventImpl(
arg_values, arg_convertables, flags);
}
+static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
+ char phase, const uint8_t* category_group_enabled, 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, unsigned int flags, int64_t timestamp) {
+ std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2];
+ if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) {
+ arg_convertables[0].reset(reinterpret_cast<ConvertableToTraceFormat*>(
+ static_cast<intptr_t>(arg_values[0])));
+ }
+ if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) {
+ arg_convertables[1].reset(reinterpret_cast<ConvertableToTraceFormat*>(
+ static_cast<intptr_t>(arg_values[1])));
+ }
+ DCHECK_LE(num_args, 2);
+ v8::TracingController* controller =
+ v8::internal::tracing::TraceEventHelper::GetTracingController();
+ return controller->AddTraceEventWithTimestamp(
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
+ arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
+}
+
// Define SetTraceValue for each allowed type. It stores the type and
// value in the return arguments. This allows this API to avoid declaring any
// structures so that it is portable to third_party libraries.
@@ -533,6 +580,48 @@ static V8_INLINE uint64_t AddTraceEvent(
arg_names, arg_types, arg_values, flags);
}
+static V8_INLINE uint64_t AddTraceEventWithTimestamp(
+ char phase, const uint8_t* category_group_enabled, const char* name,
+ const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
+ int64_t timestamp) {
+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
+ phase, category_group_enabled, name, scope, id, bind_id, kZeroNumArgs,
+ nullptr, nullptr, nullptr, flags, timestamp);
+}
+
+template <class ARG1_TYPE>
+static V8_INLINE uint64_t AddTraceEventWithTimestamp(
+ char phase, const uint8_t* category_group_enabled, const char* name,
+ const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
+ int64_t timestamp, const char* arg1_name, ARG1_TYPE&& arg1_val) {
+ const int num_args = 1;
+ uint8_t arg_type;
+ uint64_t arg_value;
+ SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
+ &arg1_name, &arg_type, &arg_value, flags, timestamp);
+}
+
+template <class ARG1_TYPE, class ARG2_TYPE>
+static V8_INLINE uint64_t AddTraceEventWithTimestamp(
+ char phase, const uint8_t* category_group_enabled, const char* name,
+ const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
+ int64_t timestamp, const char* arg1_name, ARG1_TYPE&& arg1_val,
+ const char* arg2_name, ARG2_TYPE&& arg2_val) {
+ const int num_args = 2;
+ const char* arg_names[2] = {arg1_name, arg2_name};
+ unsigned char arg_types[2];
+ uint64_t arg_values[2];
+ SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0],
+ &arg_values[0]);
+ SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1],
+ &arg_values[1]);
+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
+ arg_names, arg_types, arg_values, flags, timestamp);
+}
+
// Used by TRACE_EVENTx macros. Do not use directly.
class ScopedTracer {
public:
diff --git a/deps/v8/test/cctest/test-trace-event.cc b/deps/v8/test/cctest/test-trace-event.cc
index 9705afb4ef..471619062a 100644
--- a/deps/v8/test/cctest/test-trace-event.cc
+++ b/deps/v8/test/cctest/test-trace-event.cc
@@ -22,14 +22,16 @@ struct MockTraceObject {
uint64_t bind_id;
int num_args;
unsigned int flags;
+ int64_t timestamp;
MockTraceObject(char phase, std::string name, uint64_t id, uint64_t bind_id,
- int num_args, int flags)
+ int num_args, int flags, int64_t timestamp)
: phase(phase),
name(name),
id(id),
bind_id(bind_id),
num_args(num_args),
- flags(flags) {}
+ flags(flags),
+ timestamp(timestamp) {}
};
typedef std::vector<MockTraceObject*> MockTraceObjectList;
@@ -51,8 +53,20 @@ class MockTracingController : public v8::TracingController {
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) override {
- MockTraceObject* to = new MockTraceObject(phase, std::string(name), id,
- bind_id, num_args, flags);
+ return AddTraceEventWithTimestamp(
+ phase, category_enabled_flag, name, scope, id, bind_id, num_args,
+ arg_names, arg_types, arg_values, arg_convertables, flags, 0);
+ }
+
+ uint64_t AddTraceEventWithTimestamp(
+ 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, int64_t timestamp) override {
+ MockTraceObject* to = new MockTraceObject(
+ phase, std::string(name), id, bind_id, num_args, flags, timestamp);
trace_object_list_.push_back(to);
return 0;
}
@@ -239,3 +253,24 @@ TEST(TestEventInContext) {
CHECK_EQ("Isolate", GET_TRACE_OBJECT(2)->name);
CHECK_EQ(isolate_id, GET_TRACE_OBJECT(2)->id);
}
+
+TEST(TestEventWithTimestamp) {
+ MockTracingPlatform platform;
+
+ TRACE_EVENT_INSTANT_WITH_TIMESTAMP0("v8-cat", "0arg",
+ TRACE_EVENT_SCOPE_GLOBAL, 1729);
+ TRACE_EVENT_INSTANT_WITH_TIMESTAMP1("v8-cat", "1arg",
+ TRACE_EVENT_SCOPE_GLOBAL, 4104, "val", 1);
+ TRACE_EVENT_MARK_WITH_TIMESTAMP2("v8-cat", "mark", 13832, "a", 1, "b", 2);
+
+ CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
+
+ CHECK_EQ(1729, GET_TRACE_OBJECT(0)->timestamp);
+ CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
+
+ CHECK_EQ(4104, GET_TRACE_OBJECT(1)->timestamp);
+ CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
+
+ CHECK_EQ(13832, GET_TRACE_OBJECT(2)->timestamp);
+ CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
+}