[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}
This commit is contained in:
parent
89348016ff
commit
814577e3fd
@ -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,
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user