From a1c5dddbb2a2d6373adf31ab6fe0dfab40b871fb Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Tue, 16 Jan 2018 16:49:01 -0800 Subject: [PATCH] deps: cherry-pick 814577e from upstream V8 Original commit message: [tracing] allow embedders to provide own tracing timestamps Make it possible for embedders to provide their own tracing timetamps by providing an overridable virtual function on V8's tracing controller. Bug: Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I727e633cb7f63d4b41c2e427ecca3c9174c90bfe Reviewed-on: https://chromium-review.googlesource.com/847690 Reviewed-by: Yang Guo Reviewed-by: Fadi Meawad Commit-Queue: Ali Ijaz Sheikh Cr-Commit-Position: refs/heads/master@{#50489} Refs: https://github.com/v8/v8/commit/814577e3fd097ef772fd6d92a1ad3abd934506e6 Refs: https://github.com/nodejs/node/issues/17349 PR-URL: https://github.com/nodejs/node/pull/18196 Refs: https://github.com/nodejs/node/pull/18360 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Andreas Madsen --- common.gypi | 2 +- deps/v8/include/libplatform/v8-tracing.h | 8 ++++++-- .../src/libplatform/tracing/trace-object.cc | 12 ++++++------ .../libplatform/tracing/tracing-controller.cc | 19 +++++++++++++++---- .../test/cctest/libplatform/test-tracing.cc | 4 ++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/common.gypi b/common.gypi index 2f1efe4f56c787..10c6c31a61d1f2 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.1', + 'v8_embedder_string': '-node.2', # 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 8c1febf7627ae7..55189b48377978 100644 --- a/deps/v8/include/libplatform/v8-tracing.h +++ b/deps/v8/include/libplatform/v8-tracing.h @@ -43,8 +43,8 @@ class V8_PLATFORM_EXPORT TraceObject { const char** arg_names, const uint8_t* arg_types, const uint64_t* arg_values, std::unique_ptr* arg_convertables, - unsigned int flags); - void UpdateDuration(); + unsigned int flags, int64_t timestamp, int64_t cpu_timestamp); + void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp); void InitializeForTesting( char phase, const uint8_t* category_enabled_flag, const char* name, const char* scope, uint64_t id, uint64_t bind_id, int num_args, @@ -259,6 +259,10 @@ class V8_PLATFORM_EXPORT TracingController static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); + protected: + virtual int64_t CurrentTimestampMicroseconds(); + virtual int64_t CurrentCpuTimestampMicroseconds(); + private: const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group); void UpdateCategoryGroupEnabledFlag(size_t category_index); diff --git a/deps/v8/src/libplatform/tracing/trace-object.cc b/deps/v8/src/libplatform/tracing/trace-object.cc index 6d1a6d62b5d317..6b6e0cf404d3fd 100644 --- a/deps/v8/src/libplatform/tracing/trace-object.cc +++ b/deps/v8/src/libplatform/tracing/trace-object.cc @@ -37,7 +37,7 @@ void TraceObject::Initialize( const char** arg_names, const uint8_t* arg_types, const uint64_t* arg_values, std::unique_ptr* arg_convertables, - unsigned int flags) { + unsigned int flags, int64_t timestamp, int64_t cpu_timestamp) { pid_ = base::OS::GetCurrentProcessId(); tid_ = base::OS::GetCurrentThreadId(); phase_ = phase; @@ -47,8 +47,8 @@ void TraceObject::Initialize( id_ = id; bind_id_ = bind_id; flags_ = flags; - ts_ = base::TimeTicks::HighResolutionNow().ToInternalValue(); - tts_ = base::ThreadTicks::Now().ToInternalValue(); + ts_ = timestamp; + tts_ = cpu_timestamp; duration_ = 0; cpu_duration_ = 0; @@ -103,9 +103,9 @@ void TraceObject::Initialize( TraceObject::~TraceObject() { delete[] parameter_copy_storage_; } -void TraceObject::UpdateDuration() { - duration_ = base::TimeTicks::HighResolutionNow().ToInternalValue() - ts_; - cpu_duration_ = base::ThreadTicks::Now().ToInternalValue() - tts_; +void TraceObject::UpdateDuration(int64_t timestamp, int64_t cpu_timestamp) { + duration_ = timestamp - ts_; + cpu_duration_ = cpu_timestamp - tts_; } void TraceObject::InitializeForTesting( diff --git a/deps/v8/src/libplatform/tracing/tracing-controller.cc b/deps/v8/src/libplatform/tracing/tracing-controller.cc index 0c44e227349f38..bdc2d5d4a31610 100644 --- a/deps/v8/src/libplatform/tracing/tracing-controller.cc +++ b/deps/v8/src/libplatform/tracing/tracing-controller.cc @@ -9,6 +9,7 @@ #include "src/base/atomicops.h" #include "src/base/platform/mutex.h" +#include "src/base/platform/time.h" namespace v8 { namespace platform { @@ -48,6 +49,14 @@ void TracingController::Initialize(TraceBuffer* trace_buffer) { mutex_.reset(new base::Mutex()); } +int64_t TracingController::CurrentTimestampMicroseconds() { + return base::TimeTicks::HighResolutionNow().ToInternalValue(); +} + +int64_t TracingController::CurrentCpuTimestampMicroseconds() { + return base::ThreadTicks::Now().ToInternalValue(); +} + uint64_t TracingController::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,9 +67,10 @@ uint64_t TracingController::AddTraceEvent( 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); + trace_object->Initialize( + phase, category_enabled_flag, name, scope, id, bind_id, num_args, + arg_names, arg_types, arg_values, arg_convertables, flags, + CurrentTimestampMicroseconds(), CurrentCpuTimestampMicroseconds()); } return handle; } @@ -69,7 +79,8 @@ void TracingController::UpdateTraceEventDuration( const uint8_t* category_enabled_flag, const char* name, uint64_t handle) { TraceObject* trace_object = trace_buffer_->GetEventByHandle(handle); if (!trace_object) return; - trace_object->UpdateDuration(); + trace_object->UpdateDuration(CurrentTimestampMicroseconds(), + CurrentCpuTimestampMicroseconds()); } const uint8_t* TracingController::GetCategoryGroupEnabled( diff --git a/deps/v8/test/cctest/libplatform/test-tracing.cc b/deps/v8/test/cctest/libplatform/test-tracing.cc index dd3f30d621f445..da202057de312c 100644 --- a/deps/v8/test/cctest/libplatform/test-tracing.cc +++ b/deps/v8/test/cctest/libplatform/test-tracing.cc @@ -42,7 +42,7 @@ TEST(TestTraceObject) { uint8_t category_enabled_flag = 41; trace_object.Initialize('X', &category_enabled_flag, "Test.Trace", "Test.Scope", 42, 123, 0, nullptr, nullptr, nullptr, - nullptr, 0); + nullptr, 0, 1729, 4104); CHECK_EQ('X', trace_object.phase()); CHECK_EQ(category_enabled_flag, *trace_object.category_enabled_flag()); CHECK_EQ(std::string("Test.Trace"), std::string(trace_object.name())); @@ -96,7 +96,7 @@ TEST(TestTraceBufferRingBuffer) { CHECK_NOT_NULL(trace_object); trace_object->Initialize('X', &category_enabled_flag, names[i].c_str(), "Test.Scope", 42, 123, 0, nullptr, nullptr, - nullptr, nullptr, 0); + nullptr, nullptr, 0, 1729, 4104); trace_object = ring_buffer->GetEventByHandle(handles[i]); CHECK_NOT_NULL(trace_object); CHECK_EQ('X', trace_object->phase());