@@ -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+
180193TEST (TestTracingController) {
181194 v8::Platform* old_platform = i::V8::GetCurrentPlatform ();
182195 std::unique_ptr<v8::Platform> default_platform (
0 commit comments