Skip to content

Commit cb94601

Browse files
eugeneoMylesBorins
authored andcommitted
deps: cherry-pick 23652c5f from upstream V8
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]>
1 parent 165971d commit cb94601

File tree

4 files changed

+62
-37
lines changed

4 files changed

+62
-37
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class V8_PLATFORM_EXPORT TraceWriter {
112112
virtual void Flush() = 0;
113113

114114
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
115+
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream,
116+
const std::string& tag);
115117

116118
private:
117119
// Disallow copy and assign

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ void JSONTraceWriter::AppendArgValue(ConvertableToTraceFormat* value) {
119119
stream_ << arg_stringified;
120120
}
121121

122-
JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) {
123-
stream_ << "{\"traceEvents\":[";
122+
JSONTraceWriter::JSONTraceWriter(std::ostream& stream)
123+
: JSONTraceWriter(stream, "traceEvents") {}
124+
125+
JSONTraceWriter::JSONTraceWriter(std::ostream& stream, const std::string& tag)
126+
: stream_(stream) {
127+
stream_ << "{\"" << tag << "\":[";
124128
}
125129

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

178+
TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream,
179+
const std::string& tag) {
180+
return new JSONTraceWriter(stream, tag);
181+
}
182+
174183
} // namespace tracing
175184
} // namespace platform
176185
} // namespace v8

deps/v8/src/libplatform/tracing/trace-writer.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace tracing {
1414
class JSONTraceWriter : public TraceWriter {
1515
public:
1616
explicit JSONTraceWriter(std::ostream& stream);
17+
JSONTraceWriter(std::ostream& stream, const std::string& tag);
1718
~JSONTraceWriter();
1819
void AppendTraceEvent(TraceObject* trace_event) override;
1920
void Flush() override;

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

+48-35
Original file line numberDiff line numberDiff line change
@@ -128,44 +128,42 @@ TEST(TestTraceBufferRingBuffer) {
128128
delete ring_buffer;
129129
}
130130

131-
TEST(TestJSONTraceWriter) {
132-
std::ostringstream stream;
133-
// Create a scope for the tracing controller to terminate the trace writer.
134-
{
135-
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
136-
std::unique_ptr<v8::Platform> default_platform(
137-
v8::platform::NewDefaultPlatform());
138-
i::V8::SetPlatformForTesting(default_platform.get());
139-
auto tracing =
140-
base::make_unique<v8::platform::tracing::TracingController>();
141-
v8::platform::tracing::TracingController* tracing_controller =
142-
tracing.get();
143-
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
144-
->SetTracingController(std::move(tracing));
145-
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
131+
void PopulateJSONWriter(TraceWriter* writer) {
132+
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
133+
std::unique_ptr<v8::Platform> default_platform(
134+
v8::platform::NewDefaultPlatform());
135+
i::V8::SetPlatformForTesting(default_platform.get());
136+
auto tracing = base::make_unique<v8::platform::tracing::TracingController>();
137+
v8::platform::tracing::TracingController* tracing_controller = tracing.get();
138+
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
139+
->SetTracingController(std::move(tracing));
146140

147-
TraceBuffer* ring_buffer =
148-
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
149-
tracing_controller->Initialize(ring_buffer);
150-
TraceConfig* trace_config = new TraceConfig();
151-
trace_config->AddIncludedCategory("v8-cat");
152-
tracing_controller->StartTracing(trace_config);
141+
TraceBuffer* ring_buffer =
142+
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
143+
tracing_controller->Initialize(ring_buffer);
144+
TraceConfig* trace_config = new TraceConfig();
145+
trace_config->AddIncludedCategory("v8-cat");
146+
tracing_controller->StartTracing(trace_config);
153147

154-
TraceObject trace_object;
155-
trace_object.InitializeForTesting(
156-
'X', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test0",
157-
v8::internal::tracing::kGlobalScope, 42, 123, 0, nullptr, nullptr,
158-
nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID, 11, 22, 100, 50, 33, 44);
159-
writer->AppendTraceEvent(&trace_object);
160-
trace_object.InitializeForTesting(
161-
'Y', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test1",
162-
v8::internal::tracing::kGlobalScope, 43, 456, 0, nullptr, nullptr,
163-
nullptr, nullptr, 0, 55, 66, 110, 55, 77, 88);
164-
writer->AppendTraceEvent(&trace_object);
165-
tracing_controller->StopTracing();
166-
i::V8::SetPlatformForTesting(old_platform);
167-
}
148+
TraceObject trace_object;
149+
trace_object.InitializeForTesting(
150+
'X', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test0",
151+
v8::internal::tracing::kGlobalScope, 42, 123, 0, nullptr, nullptr,
152+
nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID, 11, 22, 100, 50, 33, 44);
153+
writer->AppendTraceEvent(&trace_object);
154+
trace_object.InitializeForTesting(
155+
'Y', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test1",
156+
v8::internal::tracing::kGlobalScope, 43, 456, 0, nullptr, nullptr,
157+
nullptr, nullptr, 0, 55, 66, 110, 55, 77, 88);
158+
writer->AppendTraceEvent(&trace_object);
159+
tracing_controller->StopTracing();
160+
i::V8::SetPlatformForTesting(old_platform);
161+
}
168162

163+
TEST(TestJSONTraceWriter) {
164+
std::ostringstream stream;
165+
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
166+
PopulateJSONWriter(writer);
169167
std::string trace_str = stream.str();
170168
std::string expected_trace_str =
171169
"{\"traceEvents\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50,"
@@ -177,6 +175,21 @@ TEST(TestJSONTraceWriter) {
177175
CHECK_EQ(expected_trace_str, trace_str);
178176
}
179177

178+
TEST(TestJSONTraceWriterWithCustomtag) {
179+
std::ostringstream stream;
180+
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream, "customTag");
181+
PopulateJSONWriter(writer);
182+
std::string trace_str = stream.str();
183+
std::string expected_trace_str =
184+
"{\"customTag\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50,"
185+
"\"ph\":\"X\",\"cat\":\"v8-cat\",\"name\":\"Test0\",\"dur\":33,"
186+
"\"tdur\":44,\"id\":\"0x2a\",\"args\":{}},{\"pid\":55,\"tid\":66,"
187+
"\"ts\":110,\"tts\":55,\"ph\":\"Y\",\"cat\":\"v8-cat\",\"name\":"
188+
"\"Test1\",\"dur\":77,\"tdur\":88,\"args\":{}}]}";
189+
190+
CHECK_EQ(expected_trace_str, trace_str);
191+
}
192+
180193
TEST(TestTracingController) {
181194
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
182195
std::unique_ptr<v8::Platform> default_platform(

0 commit comments

Comments
 (0)