Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: test/cctest/libplatform/test-tracing.cc

Issue 2369073003: [tracing] Implement Add/RemoveTraceStateObserver for default platform. (Closed)
Patch Set: addressing comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/libplatform/tracing/tracing-controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 CHECK_EQ(all_args[18], "\"aa\":11,\"ll\":\"100\""); 300 CHECK_EQ(all_args[18], "\"aa\":11,\"ll\":\"100\"");
301 CHECK_EQ(all_args[19], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\""); 301 CHECK_EQ(all_args[19], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\"");
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], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\""); 305 CHECK_EQ(all_args[21], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\"");
306 306
307 i::V8::SetPlatformForTesting(old_platform); 307 i::V8::SetPlatformForTesting(old_platform);
308 } 308 }
309 309
310 namespace {
311
312 class TraceStateObserverImpl : public Platform::TraceStateObserver {
313 public:
314 void OnTraceEnabled() override { ++enabled_count; }
315 void OnTraceDisabled() override { ++disabled_count; }
316
317 int enabled_count = 0;
318 int disabled_count = 0;
319 };
320
321 } // namespace
322
323 TEST(TracingObservers) {
324 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
325 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
326 i::V8::SetPlatformForTesting(default_platform);
327
328 v8::platform::tracing::TracingController tracing_controller;
329 v8::platform::SetTracingController(default_platform, &tracing_controller);
330 MockTraceWriter* writer = new MockTraceWriter();
331 v8::platform::tracing::TraceBuffer* ring_buffer =
332 v8::platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(1,
333 writer);
334 tracing_controller.Initialize(ring_buffer);
335 v8::platform::tracing::TraceConfig* trace_config =
336 new v8::platform::tracing::TraceConfig();
337 trace_config->AddIncludedCategory("v8");
338
339 TraceStateObserverImpl observer;
340 default_platform->AddTraceStateObserver(&observer);
341
342 CHECK_EQ(0, observer.enabled_count);
343 CHECK_EQ(0, observer.disabled_count);
344
345 tracing_controller.StartTracing(trace_config);
346
347 CHECK_EQ(1, observer.enabled_count);
348 CHECK_EQ(0, observer.disabled_count);
349
350 tracing_controller.StopTracing();
351
352 CHECK_EQ(1, observer.enabled_count);
353 CHECK_EQ(1, observer.disabled_count);
354
355 default_platform->RemoveTraceStateObserver(&observer);
356
357 CHECK_EQ(1, observer.enabled_count);
358 CHECK_EQ(1, observer.disabled_count);
359
360 trace_config = new v8::platform::tracing::TraceConfig();
361 tracing_controller.StartTracing(trace_config);
362 tracing_controller.StopTracing();
363
364 CHECK_EQ(1, observer.enabled_count);
365 CHECK_EQ(1, observer.disabled_count);
366
367 i::V8::SetPlatformForTesting(old_platform);
368 }
369
310 } // namespace tracing 370 } // namespace tracing
311 } // namespace platform 371 } // namespace platform
312 } // namespace v8 372 } // namespace v8
OLDNEW
« no previous file with comments | « src/libplatform/tracing/tracing-controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698