Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include <limits> | 4 #include <limits> |
| 5 | 5 |
| 6 #include "include/libplatform/v8-tracing.h" | 6 #include "include/libplatform/v8-tracing.h" |
| 7 #include "src/tracing/trace-event.h" | 7 #include "src/tracing/trace-event.h" |
| 8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 | 302 |
| 303 CHECK_EQ(all_names[20], "INIT"); | 303 CHECK_EQ(all_names[20], "INIT"); |
| 304 CHECK_EQ(all_names[21], "INIT"); | 304 CHECK_EQ(all_names[21], "INIT"); |
| 305 CHECK_EQ(all_args[21], "\"INIT\":\"INIT\""); | 305 CHECK_EQ(all_args[21], "\"INIT\":\"INIT\""); |
| 306 CHECK_EQ(all_names[22], "INIT"); | 306 CHECK_EQ(all_names[22], "INIT"); |
| 307 CHECK_EQ(all_args[22], "\"INIT\":\"INIT\",\"INIT\":\"INIT\""); | 307 CHECK_EQ(all_args[22], "\"INIT\":\"INIT\",\"INIT\":\"INIT\""); |
| 308 | 308 |
| 309 i::V8::SetPlatformForTesting(old_platform); | 309 i::V8::SetPlatformForTesting(old_platform); |
| 310 } | 310 } |
| 311 | 311 |
| 312 TEST(TestAsyncTraceEvent) { | |
|
fmeawad
2016/08/03 06:48:02
All test names are based on Classes and not trace
rskang
2016/08/03 20:41:45
Done.
| |
| 313 std::ostringstream stream; | |
| 314 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | |
| 315 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform(); | |
| 316 i::V8::SetPlatformForTesting(default_platform); | |
| 317 | |
| 318 uint64_t x = 0xdeadbeef5; | |
| 319 uint64_t* p = &x; | |
| 320 | |
| 321 // Create a scope for the tracing controller to terminate the trace writer. | |
| 322 { | |
| 323 TracingController tracing_controller; | |
| 324 platform::SetTracingController(default_platform, &tracing_controller); | |
| 325 TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream); | |
| 326 | |
| 327 TraceBuffer* ring_buffer = | |
| 328 TraceBuffer::CreateTraceBufferRingBuffer(1, writer); | |
| 329 tracing_controller.Initialize(ring_buffer); | |
| 330 TraceConfig* trace_config = new TraceConfig(); | |
| 331 trace_config->AddIncludedCategory("v8"); | |
| 332 tracing_controller.StartTracing(trace_config); | |
| 333 | |
| 334 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("v8", "Test1", x); | |
| 335 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("v8", "Test2", p); | |
|
fmeawad
2016/08/03 06:48:02
Can you add an END for these trace events?
rskang
2016/08/03 20:41:45
Not needed after merging into TestJSONTraceWriter.
| |
| 336 | |
| 337 tracing_controller.StopTracing(); | |
| 338 } | |
| 339 | |
| 340 std::string trace_str = stream.str(); | |
| 341 | |
| 342 std::vector<std::string> all_ids, all_ts; | |
| 343 GetJSONStrings(all_ids, trace_str, "\"id\"", "\"", "\""); | |
| 344 GetJSONStrings(all_ts, trace_str, "\"ts\"", ":", ","); | |
| 345 | |
| 346 CHECK_EQ(all_ids.size(), 2); | |
| 347 CHECK_EQ(all_ids[0], "0xdeadbeef5"); | |
| 348 std::ostringstream pointer_stream; | |
| 349 pointer_stream << "0x" << std::hex << reinterpret_cast<uint64_t>(&x); | |
| 350 CHECK_EQ(all_ids[1], pointer_stream.str()); | |
| 351 | |
| 352 // Ensure decimal values did not get corrupted due to hex ids. | |
| 353 CHECK(std::all_of(all_ts[1].begin() + 1, all_ts[1].end() - 1, isdigit)); | |
| 354 | |
| 355 i::V8::SetPlatformForTesting(old_platform); | |
| 356 } | |
| 357 | |
| 312 } // namespace tracing | 358 } // namespace tracing |
| 313 } // namespace platform | 359 } // namespace platform |
| 314 } // namespace v8 | 360 } // namespace v8 |
| OLD | NEW |