Skip to content

Commit

Permalink
deps: cherry-pick 23652c5f from upstream V8
Browse files Browse the repository at this point in the history
Original commit message:
    Custom tag for the traceEvents array

    This API will be used by Node.js to provide output compatible with
    Chrome devtools.

    Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
    Change-Id: I265495f8af39bfc78d7fdbe43ac308f0920e817d
    Reviewed-on: https://chromium-review.googlesource.com/1044491
    Reviewed-by: Aleksey Kozyatinskiy <[email protected]>
    Reviewed-by: Ulan Degenbaev <[email protected]>
    Commit-Queue: Eugene Ostroukhov <[email protected]>
    Cr-Commit-Position: refs/heads/master@{#53041}

PR-URL: #20608
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
eugeneo authored and MylesBorins committed May 22, 2018
1 parent 165971d commit cb94601
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 37 deletions.
2 changes: 2 additions & 0 deletions deps/v8/include/libplatform/v8-tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class V8_PLATFORM_EXPORT TraceWriter {
virtual void Flush() = 0;

static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream,
const std::string& tag);

private:
// Disallow copy and assign
Expand Down
13 changes: 11 additions & 2 deletions deps/v8/src/libplatform/tracing/trace-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ void JSONTraceWriter::AppendArgValue(ConvertableToTraceFormat* value) {
stream_ << arg_stringified;
}

JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) {
stream_ << "{\"traceEvents\":[";
JSONTraceWriter::JSONTraceWriter(std::ostream& stream)
: JSONTraceWriter(stream, "traceEvents") {}

JSONTraceWriter::JSONTraceWriter(std::ostream& stream, const std::string& tag)
: stream_(stream) {
stream_ << "{\"" << tag << "\":[";
}

JSONTraceWriter::~JSONTraceWriter() { stream_ << "]}"; }
Expand Down Expand Up @@ -171,6 +175,11 @@ TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) {
return new JSONTraceWriter(stream);
}

TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream,
const std::string& tag) {
return new JSONTraceWriter(stream, tag);
}

} // namespace tracing
} // namespace platform
} // namespace v8
1 change: 1 addition & 0 deletions deps/v8/src/libplatform/tracing/trace-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace tracing {
class JSONTraceWriter : public TraceWriter {
public:
explicit JSONTraceWriter(std::ostream& stream);
JSONTraceWriter(std::ostream& stream, const std::string& tag);
~JSONTraceWriter();
void AppendTraceEvent(TraceObject* trace_event) override;
void Flush() override;
Expand Down
83 changes: 48 additions & 35 deletions deps/v8/test/cctest/libplatform/test-tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,44 +128,42 @@ TEST(TestTraceBufferRingBuffer) {
delete ring_buffer;
}

TEST(TestJSONTraceWriter) {
std::ostringstream stream;
// Create a scope for the tracing controller to terminate the trace writer.
{
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform());
i::V8::SetPlatformForTesting(default_platform.get());
auto tracing =
base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller =
tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
void PopulateJSONWriter(TraceWriter* writer) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform());
i::V8::SetPlatformForTesting(default_platform.get());
auto tracing = base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller = tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));

TraceBuffer* ring_buffer =
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
tracing_controller->Initialize(ring_buffer);
TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory("v8-cat");
tracing_controller->StartTracing(trace_config);
TraceBuffer* ring_buffer =
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
tracing_controller->Initialize(ring_buffer);
TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory("v8-cat");
tracing_controller->StartTracing(trace_config);

TraceObject trace_object;
trace_object.InitializeForTesting(
'X', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test0",
v8::internal::tracing::kGlobalScope, 42, 123, 0, nullptr, nullptr,
nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID, 11, 22, 100, 50, 33, 44);
writer->AppendTraceEvent(&trace_object);
trace_object.InitializeForTesting(
'Y', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test1",
v8::internal::tracing::kGlobalScope, 43, 456, 0, nullptr, nullptr,
nullptr, nullptr, 0, 55, 66, 110, 55, 77, 88);
writer->AppendTraceEvent(&trace_object);
tracing_controller->StopTracing();
i::V8::SetPlatformForTesting(old_platform);
}
TraceObject trace_object;
trace_object.InitializeForTesting(
'X', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test0",
v8::internal::tracing::kGlobalScope, 42, 123, 0, nullptr, nullptr,
nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID, 11, 22, 100, 50, 33, 44);
writer->AppendTraceEvent(&trace_object);
trace_object.InitializeForTesting(
'Y', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test1",
v8::internal::tracing::kGlobalScope, 43, 456, 0, nullptr, nullptr,
nullptr, nullptr, 0, 55, 66, 110, 55, 77, 88);
writer->AppendTraceEvent(&trace_object);
tracing_controller->StopTracing();
i::V8::SetPlatformForTesting(old_platform);
}

TEST(TestJSONTraceWriter) {
std::ostringstream stream;
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
PopulateJSONWriter(writer);
std::string trace_str = stream.str();
std::string expected_trace_str =
"{\"traceEvents\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50,"
Expand All @@ -177,6 +175,21 @@ TEST(TestJSONTraceWriter) {
CHECK_EQ(expected_trace_str, trace_str);
}

TEST(TestJSONTraceWriterWithCustomtag) {
std::ostringstream stream;
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream, "customTag");
PopulateJSONWriter(writer);
std::string trace_str = stream.str();
std::string expected_trace_str =
"{\"customTag\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50,"
"\"ph\":\"X\",\"cat\":\"v8-cat\",\"name\":\"Test0\",\"dur\":33,"
"\"tdur\":44,\"id\":\"0x2a\",\"args\":{}},{\"pid\":55,\"tid\":66,"
"\"ts\":110,\"tts\":55,\"ph\":\"Y\",\"cat\":\"v8-cat\",\"name\":"
"\"Test1\",\"dur\":77,\"tdur\":88,\"args\":{}}]}";

CHECK_EQ(expected_trace_str, trace_str);
}

TEST(TestTracingController) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform(
Expand Down

0 comments on commit cb94601

Please sign in to comment.