Skip to content

Commit

Permalink
deps: cherry-pick 814577e from upstream V8
Browse files Browse the repository at this point in the history
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 <[email protected]>
    Reviewed-by: Fadi Meawad <[email protected]>
    Commit-Queue: Ali Ijaz Sheikh <[email protected]>
    Cr-Commit-Position: refs/heads/master@{#50489}

Refs: v8/v8@814577e
Refs: #17349
PR-URL: #18196
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Andreas Madsen <[email protected]>
  • Loading branch information
ofrobots committed Jan 24, 2018
1 parent 2313424 commit 7d7a549
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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.6',
'v8_embedder_string': '-node.7',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
8 changes: 6 additions & 2 deletions deps/v8/include/libplatform/v8-tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::ConvertableToTraceFormat>* 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,
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions deps/v8/src/libplatform/tracing/trace-object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void TraceObject::Initialize(
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, int64_t timestamp, int64_t cpu_timestamp) {
pid_ = base::OS::GetCurrentProcessId();
tid_ = base::OS::GetCurrentThreadId();
phase_ = phase;
Expand All @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
19 changes: 15 additions & 4 deletions deps/v8/src/libplatform/tracing/tracing-controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/test/cctest/libplatform/test-tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 7d7a549

Please sign in to comment.