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

Unified Diff: components/tracing/test/tracing_interface_simulator.h

Issue 2656303003: Test virtual interface [NOT FOR REVIEW] (Closed)
Patch Set: results Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/tracing/test/tracing_interface_simulator.h
diff --git a/components/tracing/test/tracing_interface_simulator.h b/components/tracing/test/tracing_interface_simulator.h
new file mode 100644
index 0000000000000000000000000000000000000000..4fdb56b261fb8e2751c543fed3bf85a0c4a2d856
--- /dev/null
+++ b/components/tracing/test/tracing_interface_simulator.h
@@ -0,0 +1,71 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_TRACING_TEST_TRACING_INTERFACE_SIMULATOR_H_
+#define COMPONENTS_TRACING_TEST_TRACING_INTERFACE_SIMULATOR_H_
+
+#include "base/trace_event/trace_event.h"
+
+namespace tracing {
+
+class TracingInterface {
+ public:
+ virtual base::trace_event::TraceEventHandle AddEvent(
+ const char *category, const unsigned char* cat_enabled,
+ char type, const char *name, bool copy_name) const = 0;
+ virtual const unsigned char*
+ GetCategoryPointer(const char *category) const = 0;
+};
+
+void InitTracingInterface();
+const TracingInterface* GetTracingInterface();
+
+base::trace_event::TraceEventHandle AddEventDirect(
+ const char *category, const unsigned char* cat_enabled,
+ char type, const char *name, bool copy_name);
+const unsigned char* GetCategoryPointerDirect(const char *category);
+
+
+#define TRACE_EVENT_VIRTUAL_TEST(category, name) \
+ TRACE_EVENT_VIRTUAL_TEST_BODY(category, name, \
+ cat_enabled_ptr_ ## __LINE__, cat_enabled_atomic_ ## __LINE__)
+
+#define TRACE_EVENT_VIRTUAL_TEST_BODY(category, name, enabled_ptr, enabled_atomic) \
+ static base::subtle::AtomicWord enabled_atomic = 0; \
+ const unsigned char* enabled_ptr = reinterpret_cast<const unsigned char*>( \
+ base::subtle::NoBarrier_Load(&enabled_atomic)); \
+ if (UNLIKELY(!enabled_ptr)) { \
+ enabled_ptr = GetTracingInterface()->GetCategoryPointer(category); \
+ base::subtle::NoBarrier_Store(&enabled_atomic, \
+ reinterpret_cast<base::subtle::AtomicWord>(enabled_ptr)); \
+ } \
+ trace_event_internal::ScopedTracer scoped_tracer_ ## __LINE__; \
+ if (UNLIKELY(*enabled_ptr)) { \
+ scoped_tracer_ ## __LINE__.Initialize(enabled_ptr, name, \
+ GetTracingInterface()->AddEvent(category, enabled_ptr, 'X', name, false)); \
+ }
+
+
+#define TRACE_EVENT_DIRECT_TEST(category, name) \
+ TRACE_EVENT_DIRECT_TEST_BODY(category, name, \
+ cat_enabled_ptr_ ## __LINE__, cat_enabled_atomic_ ## __LINE__)
+
+#define TRACE_EVENT_DIRECT_TEST_BODY(category, name, enabled_ptr, enabled_atomic) \
+ static base::subtle::AtomicWord enabled_atomic = 0; \
+ const unsigned char* enabled_ptr = reinterpret_cast<const unsigned char*>( \
+ base::subtle::NoBarrier_Load(&enabled_atomic)); \
+ if (UNLIKELY(!enabled_ptr)) { \
+ enabled_ptr = GetCategoryPointerDirect(category); \
+ base::subtle::NoBarrier_Store(&enabled_atomic, \
+ reinterpret_cast<base::subtle::AtomicWord>(enabled_ptr)); \
+ } \
+ trace_event_internal::ScopedTracer scoped_tracer_ ## __LINE__; \
+ if (UNLIKELY(*enabled_ptr)) { \
+ scoped_tracer_ ## __LINE__.Initialize(enabled_ptr, name, \
+ AddEventDirect(category, enabled_ptr, 'X', name, false)); \
+ }
+
+} // namespace tracing
+
+#endif // COMPONENTS_TRACING_TEST_TRACING_INTERFACE_SIMULATOR_H_
« no previous file with comments | « components/tracing/test/trace_event_perftest.cc ('k') | components/tracing/test/tracing_interface_simulator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698