Skip to content

Commit a1c5ddd

Browse files
committed
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 <yangguo@chromium.org> Reviewed-by: Fadi Meawad <fmeawad@chromium.org> Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com> Cr-Commit-Position: refs/heads/master@{#50489} Refs: v8/v8@814577e Refs: #17349 PR-URL: #18196 Refs: #18360 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 990959d commit a1c5ddd

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
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.1',
30+
'v8_embedder_string': '-node.2',
3131

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class V8_PLATFORM_EXPORT TraceObject {
4343
const char** arg_names, const uint8_t* arg_types,
4444
const uint64_t* arg_values,
4545
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
46-
unsigned int flags);
47-
void UpdateDuration();
46+
unsigned int flags, int64_t timestamp, int64_t cpu_timestamp);
47+
void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp);
4848
void InitializeForTesting(
4949
char phase, const uint8_t* category_enabled_flag, const char* name,
5050
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
@@ -259,6 +259,10 @@ class V8_PLATFORM_EXPORT TracingController
259259

260260
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
261261

262+
protected:
263+
virtual int64_t CurrentTimestampMicroseconds();
264+
virtual int64_t CurrentCpuTimestampMicroseconds();
265+
262266
private:
263267
const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group);
264268
void UpdateCategoryGroupEnabledFlag(size_t category_index);

deps/v8/src/libplatform/tracing/trace-object.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void TraceObject::Initialize(
3737
const char** arg_names, const uint8_t* arg_types,
3838
const uint64_t* arg_values,
3939
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
40-
unsigned int flags) {
40+
unsigned int flags, int64_t timestamp, int64_t cpu_timestamp) {
4141
pid_ = base::OS::GetCurrentProcessId();
4242
tid_ = base::OS::GetCurrentThreadId();
4343
phase_ = phase;
@@ -47,8 +47,8 @@ void TraceObject::Initialize(
4747
id_ = id;
4848
bind_id_ = bind_id;
4949
flags_ = flags;
50-
ts_ = base::TimeTicks::HighResolutionNow().ToInternalValue();
51-
tts_ = base::ThreadTicks::Now().ToInternalValue();
50+
ts_ = timestamp;
51+
tts_ = cpu_timestamp;
5252
duration_ = 0;
5353
cpu_duration_ = 0;
5454

@@ -103,9 +103,9 @@ void TraceObject::Initialize(
103103

104104
TraceObject::~TraceObject() { delete[] parameter_copy_storage_; }
105105

106-
void TraceObject::UpdateDuration() {
107-
duration_ = base::TimeTicks::HighResolutionNow().ToInternalValue() - ts_;
108-
cpu_duration_ = base::ThreadTicks::Now().ToInternalValue() - tts_;
106+
void TraceObject::UpdateDuration(int64_t timestamp, int64_t cpu_timestamp) {
107+
duration_ = timestamp - ts_;
108+
cpu_duration_ = cpu_timestamp - tts_;
109109
}
110110

111111
void TraceObject::InitializeForTesting(

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "src/base/atomicops.h"
1111
#include "src/base/platform/mutex.h"
12+
#include "src/base/platform/time.h"
1213

1314
namespace v8 {
1415
namespace platform {
@@ -48,6 +49,14 @@ void TracingController::Initialize(TraceBuffer* trace_buffer) {
4849
mutex_.reset(new base::Mutex());
4950
}
5051

52+
int64_t TracingController::CurrentTimestampMicroseconds() {
53+
return base::TimeTicks::HighResolutionNow().ToInternalValue();
54+
}
55+
56+
int64_t TracingController::CurrentCpuTimestampMicroseconds() {
57+
return base::ThreadTicks::Now().ToInternalValue();
58+
}
59+
5160
uint64_t TracingController::AddTraceEvent(
5261
char phase, const uint8_t* category_enabled_flag, const char* name,
5362
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
@@ -58,9 +67,10 @@ uint64_t TracingController::AddTraceEvent(
5867
uint64_t handle;
5968
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
6069
if (trace_object) {
61-
trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
62-
bind_id, num_args, arg_names, arg_types,
63-
arg_values, arg_convertables, flags);
70+
trace_object->Initialize(
71+
phase, category_enabled_flag, name, scope, id, bind_id, num_args,
72+
arg_names, arg_types, arg_values, arg_convertables, flags,
73+
CurrentTimestampMicroseconds(), CurrentCpuTimestampMicroseconds());
6474
}
6575
return handle;
6676
}
@@ -69,7 +79,8 @@ void TracingController::UpdateTraceEventDuration(
6979
const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {
7080
TraceObject* trace_object = trace_buffer_->GetEventByHandle(handle);
7181
if (!trace_object) return;
72-
trace_object->UpdateDuration();
82+
trace_object->UpdateDuration(CurrentTimestampMicroseconds(),
83+
CurrentCpuTimestampMicroseconds());
7384
}
7485

7586
const uint8_t* TracingController::GetCategoryGroupEnabled(

deps/v8/test/cctest/libplatform/test-tracing.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TEST(TestTraceObject) {
4242
uint8_t category_enabled_flag = 41;
4343
trace_object.Initialize('X', &category_enabled_flag, "Test.Trace",
4444
"Test.Scope", 42, 123, 0, nullptr, nullptr, nullptr,
45-
nullptr, 0);
45+
nullptr, 0, 1729, 4104);
4646
CHECK_EQ('X', trace_object.phase());
4747
CHECK_EQ(category_enabled_flag, *trace_object.category_enabled_flag());
4848
CHECK_EQ(std::string("Test.Trace"), std::string(trace_object.name()));
@@ -96,7 +96,7 @@ TEST(TestTraceBufferRingBuffer) {
9696
CHECK_NOT_NULL(trace_object);
9797
trace_object->Initialize('X', &category_enabled_flag, names[i].c_str(),
9898
"Test.Scope", 42, 123, 0, nullptr, nullptr,
99-
nullptr, nullptr, 0);
99+
nullptr, nullptr, 0, 1729, 4104);
100100
trace_object = ring_buffer->GetEventByHandle(handles[i]);
101101
CHECK_NOT_NULL(trace_object);
102102
CHECK_EQ('X', trace_object->phase());

0 commit comments

Comments
 (0)