16169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Copyright (c) 2014 Google Inc.
26169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
36169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Use of this source code is governed by a BSD-style license that can be
46169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// found in the LICENSE file.
56169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
66169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// This header file defines the set of trace_event macros without specifying
76169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// how the events actually get collected and stored. If you need to expose trace
86169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// events to some other universe, you can copy-and-paste this file as well as
96169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// trace_event.h, modifying the macros contained there as necessary for the
106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// target platform. The end result is that multiple libraries can funnel events
116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// through to a shared trace event collector.
126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Trace events are for tracking application performance and resource usage.
146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Macros are provided to track:
156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//    Begin and end of function calls
166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//    Counters
176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Events are issued against categories. Whereas LOG's
196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// categories are statically defined, TRACE categories are created
206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// implicitly with a string. For example:
216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent",
226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                        TRACE_EVENT_SCOPE_THREAD)
236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// It is often the case that one trace may belong in multiple categories at the
256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// same time. The first argument to the trace can be a comma-separated list of
266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// categories, forming a category group, like:
276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT_INSTANT0("input,views", "OnMouseOver", TRACE_EVENT_SCOPE_THREAD)
296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// We can enable/disable tracing of OnMouseOver by enabling/disabling either
316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// category.
326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Events can be INSTANT, or can be pairs of BEGIN and END in the same scope:
346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly")
356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   doSomethingCostly()
366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly")
376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Note: our tools can't always determine the correct BEGIN/END pairs unless
386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you
396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// need them to be in separate scopes.
406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// A common use case is to trace entire function scopes. This
426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// issues a trace BEGIN and END automatically:
436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   void doSomethingCostly() {
446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly");
456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     ...
466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   }
476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Additional parameters can be associated with an event:
496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   void doSomethingCostly2(int howMuch) {
506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly",
516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//         "howMuch", howMuch);
526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     ...
536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   }
546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// The trace system will automatically add to this information the
566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// current process id, thread id, and a timestamp in microseconds.
576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// To trace an asynchronous procedure such as an IPC send/receive, use
596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// ASYNC_BEGIN and ASYNC_END:
606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   [single threaded sender code]
616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     static int send_count = 0;
626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     ++send_count;
636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT_ASYNC_BEGIN0("ipc", "message", send_count);
646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     Send(new MyMessage(send_count));
656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   [receive code]
666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     void OnMyMessage(send_count) {
676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//       TRACE_EVENT_ASYNC_END0("ipc", "message", send_count);
686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     }
696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// The third parameter is a unique ID to match ASYNC_BEGIN/ASYNC_END pairs.
706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// ASYNC_BEGIN and ASYNC_END can occur on any thread of any traced process.
716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Pointers can be used for the ID parameter, and they will be mangled
726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// internally so that the same pointer on two different processes will not
736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// match. For example:
746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   class MyTracedClass {
756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//    public:
766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     MyTracedClass() {
776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//       TRACE_EVENT_ASYNC_BEGIN0("category", "MyTracedClass", this);
786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     }
796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     ~MyTracedClass() {
806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//       TRACE_EVENT_ASYNC_END0("category", "MyTracedClass", this);
816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     }
826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   }
836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Trace event also supports counters, which is a way to track a quantity
856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// as it varies over time. Counters are created with the following macro:
866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue);
876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Counters are process-specific. The macro itself can be issued from any
896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// thread, however.
906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Sometimes, you want to track two counters at once. You can do this with two
926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// counter macros:
936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]);
946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter1", g_myCounterValue[1]);
956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Or you can do it with a combined macro:
966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   TRACE_COUNTER2("MY_SUBSYSTEM", "myCounter",
976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//       "bytesPinned", g_myCounterValue[0],
986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//       "bytesAllocated", g_myCounterValue[1]);
996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// This indicates to the tracing UI that these counters should be displayed
1006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// in a single graph, as a summed area chart.
1016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Since counters are in a global namespace, you may want to disambiguate with a
1036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// unique ID, by using the TRACE_COUNTER_ID* variations.
1046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// By default, trace collection is compiled in, but turned off at runtime.
1066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Collecting trace data is the responsibility of the embedding
1076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// application. In Chrome's case, navigating to about:tracing will turn on
1086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// tracing and display data collected across all active processes.
1096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Memory scoping note:
1126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Tracing copies the pointers, not the string content, of the strings passed
1136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// in for category_group, name, and arg_names.  Thus, the following code will
1146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// cause problems:
1156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     char* str = strdup("importantName");
1166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT_INSTANT0("SUBSYSTEM", str);  // BAD!
1176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     free(str);                   // Trace system now has dangling pointer
1186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// To avoid this issue with the |name| and |arg_name| parameters, use the
1206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead.
1216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Notes: The category must always be in a long-lived char* (i.e. static const).
1226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//        The |arg_values|, when used, are always deep copied with the _COPY
1236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//        macros.
1246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// When are string argument values copied:
1266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// const char* arg_values are only referenced by default:
1276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT1("category", "name",
1286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                  "arg1", "literal string is only referenced");
1296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Use TRACE_STR_COPY to force copying of a const char*:
1306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT1("category", "name",
1316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                  "arg1", TRACE_STR_COPY("string will be copied"));
1326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// std::string arg_values are always copied:
1336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT1("category", "name",
1346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                  "arg1", std::string("string will be copied"));
1356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Thread Safety:
1386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// A thread safe singleton and mutex are used for thread safety. Category
1396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// enabled flags are used to limit the performance impact when the system
1406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// is not enabled.
1416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT macros first cache a pointer to a category. The categories are
1436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// statically allocated and safe at all times, even after exit. Fetching a
1446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// category is protected by the TraceLog::lock_. Multiple threads initializing
1456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// the static variable is safe, as they will be serialized by the lock and
1466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// multiple calls will return the same pointer to the category.
1476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Then the category_group_enabled flag is checked. This is a unsigned char, and
1496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// not intended to be multithread safe. It optimizes access to AddTraceEvent
1506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// which is threadsafe internally via TraceLog::lock_. The enabled flag may
1516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// cause some threads to incorrectly call or skip calling AddTraceEvent near
1526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// the time of the system being enabled or disabled. This is acceptable as
1536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// we tolerate some data loss while the system is being enabled/disabled and
1546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// because AddTraceEvent is threadsafe internally and checks the enabled state
1556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// again under lock.
1566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
1576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Without the use of these static category pointers and enabled flags all
1586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// trace points would carry a significant performance cost of acquiring a lock
1596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// and resolving the category.
1606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#ifndef SkTraceEvent_DEFINED
1626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define SkTraceEvent_DEFINED
1636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#include "SkEventTracer.h"
1656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// By default, const char* argument values are assumed to have long-lived scope
1676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// and will not be copied. Use this macro to force a const char* to be copied.
1686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_STR_COPY(str) \
1696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::TraceStringWithCopy(str)
1706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// By default, uint64 ID argument values are not mangled with the Process ID in
1726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling.
1736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_ID_MANGLE(id) \
1746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::TraceID::ForceMangle(id)
1756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC
1776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// macros. Use this macro to prevent Process ID mangling.
1786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_ID_DONT_MANGLE(id) \
1796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::TraceID::DontMangle(id)
1806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a pair of begin and end events called "name" for the current
1826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// scope, with 0, 1 or 2 associated arguments. If the category is not
1836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// enabled, then this does nothing.
1846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
1856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
1866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT0(category_group, name) \
1876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
1886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
1896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
1906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT2( \
1916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
1926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  INTERNAL_TRACE_EVENT_ADD_SCOPED( \
1936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
1946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
1956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing.
1966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Use this where |name| is too generic to accurately aggregate allocations.
1976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_WITH_MEMORY_TAG2( \
1986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \
1996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  INTERNAL_TRACE_EVENT_ADD_SCOPED( \
2006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      category, name, arg1_name, arg1_val, arg2_name, arg2_val)
2016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not
2036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// included in official builds.
2046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#if OFFICIAL_BUILD
2066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#undef TRACING_IS_OFFICIAL_BUILD
2076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACING_IS_OFFICIAL_BUILD 1
2086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#elif !defined(TRACING_IS_OFFICIAL_BUILD)
2096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACING_IS_OFFICIAL_BUILD 0
2106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#endif
2116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#if TRACING_IS_OFFICIAL_BUILD
2136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0
2146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
2156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    (void)0
2166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
2176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                               arg2_name, arg2_val) (void)0
2186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) (void)0
2196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \
2206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                       arg1_name, arg1_val) (void)0
2216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \
2226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                       arg1_name, arg1_val, \
2236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                       arg2_name, arg2_val) (void)0
2246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#else
2256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT0(category_group, name) \
2266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT0(category_group, name)
2276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
2286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
2296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
2306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                               arg2_name, arg2_val) \
2316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
2326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) \
2336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_INSTANT0(category_group, name, scope)
2346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \
2356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                       arg1_name, arg1_val) \
2366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val)
2376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \
2386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                       arg1_name, arg1_val, \
2396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                       arg2_name, arg2_val) \
2406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
2416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                         arg2_name, arg2_val)
2426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#endif
2436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single event called "name" immediately, with 0, 1 or 2
2456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// associated arguments. If the category is not enabled, then this
2466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// does nothing.
2476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
2486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
2496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_INSTANT0(category_group, name, scope) \
2506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
2516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE | scope)
2526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
2536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
2546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE | scope, \
2556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
2566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
2576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                             arg2_name, arg2_val) \
2586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
2596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE | scope, \
2606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
2616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope) \
2626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
2636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY | scope)
2646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, \
2656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                  arg1_name, arg1_val) \
2666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
2676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY | scope, arg1_name, \
2686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val)
2696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, \
2706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                  arg1_name, arg1_val, \
2716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                  arg2_name, arg2_val) \
2726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
2736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY | scope, \
2746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
2756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Sets the current sample state to the given category and name (both must be
2776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// constant strings). These states are intended for a sampling profiler.
2786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation note: we store category and name together because we don't
2796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// want the inconsistency/expense of storing two pointers.
2806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// |thread_bucket| is [0..2] and is used to statically isolate samples in one
2816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// thread from others.
2826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \
2836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    bucket_number, category, name)                 \
2846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        skia::tracing_internals::                     \
2856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name)
2866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Returns a current sampling state of the given bucket.
2886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \
2896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::TraceEventSamplingStateScope<bucket_number>::Current()
2906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
2916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Creates a scope of a sampling state of the given bucket.
2926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
2936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// {  // The sampling state is set within this scope.
2946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//    TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name");
2956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//    ...;
2966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// }
2976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(                   \
2986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    bucket_number, category, name)                                      \
2996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::TraceEventSamplingStateScope<bucket_number>   \
3006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        traceEventSamplingScope(category "\0" name);
3016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
3026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Syntactic sugars for the sampling tracing in the main thread.
3036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \
3046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name)
3056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_GET_SAMPLING_STATE() \
3066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0)
3076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \
3086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name)
3096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
3106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
3116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single BEGIN event called "name" immediately, with 0, 1 or 2
3126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// associated arguments. If the category is not enabled, then this
3136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// does nothing.
3146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
3156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
3166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_BEGIN0(category_group, name) \
3176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
3186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE)
3196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \
3206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
3216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
3226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \
3236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
3246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
3256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
3266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val)
3276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_BEGIN0(category_group, name) \
3286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
3296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY)
3306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \
3316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
3326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
3336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \
3346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
3356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
3366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
3376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val)
3386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
3396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
3406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - |id| is used to match the _BEGIN event with the _END event.
3416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   Events are considered to match if their category_group, name and id values
3426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   all match. |id| must either be a pointer or an integer value up to 64 bits.
3436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   If it's a pointer, the bits will be xored with a hash of the process ID so
3446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   that the same pointer on two different processes will not collide.
3456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, \
3466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        name, id, thread_id) \
3476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
3486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
3496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        timestamp, TRACE_EVENT_FLAG_NONE)
3506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \
3516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, thread_id) \
3526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
3536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
3546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        timestamp, TRACE_EVENT_FLAG_COPY)
3556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
3566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single END event for "name" immediately. If the category
3576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// is not enabled, then this does nothing.
3586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
3596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
3606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_END0(category_group, name) \
3616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
3626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE)
3636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \
3646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
3656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
3666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, \
3676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
3686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
3696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
3706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val)
3716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_END0(category_group, name) \
3726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
3736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY)
3746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \
3756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
3766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
3776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \
3786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
3796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
3806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
3816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val)
3826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
3836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
3846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - |id| is used to match the _BEGIN event with the _END event.
3856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   Events are considered to match if their category_group, name and id values
3866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   all match. |id| must either be a pointer or an integer value up to 64 bits.
3876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   If it's a pointer, the bits will be xored with a hash of the process ID so
3886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   that the same pointer on two different processes will not collide.
3896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, \
3906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        name, id, thread_id) \
3916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
3926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
3936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        timestamp, TRACE_EVENT_FLAG_NONE)
3946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \
3956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, thread_id) \
3966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
3976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
3986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        timestamp, TRACE_EVENT_FLAG_COPY)
3996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
4006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records the value of a counter called "name" immediately. Value
4016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// must be representable as a 32 bit integer.
4026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
4036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
4046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COUNTER1(category_group, name, value) \
4056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
4066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE, \
4076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        "value", static_cast<int>(value))
4086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COPY_COUNTER1(category_group, name, value) \
4096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
4106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY, \
4116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        "value", static_cast<int>(value))
4126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
4136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records the values of a multi-parted counter called "name" immediately.
4146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// The UI will treat value1 and value2 as parts of a whole, displaying their
4156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// values as a stacked-bar chart.
4166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
4176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
4186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \
4196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, value2_val) \
4206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
4216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_NONE, \
4226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value1_name, static_cast<int>(value1_val), \
4236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, static_cast<int>(value2_val))
4246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \
4256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, value2_val) \
4266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
4276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_EVENT_FLAG_COPY, \
4286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value1_name, static_cast<int>(value1_val), \
4296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, static_cast<int>(value2_val))
4306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
4316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records the value of a counter called "name" immediately. Value
4326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// must be representable as a 32 bit integer.
4336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
4346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
4356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - |id| is used to disambiguate counters with the same name. It must either
4366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
4376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   will be xored with a hash of the process ID so that the same pointer on
4386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   two different processes will not collide.
4396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COUNTER_ID1(category_group, name, id, value) \
4406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
4416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, \
4426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        "value", static_cast<int>(value))
4436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \
4446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
4456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
4466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        "value", static_cast<int>(value))
4476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
4486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records the values of a multi-parted counter called "name" immediately.
4496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// The UI will treat value1 and value2 as parts of a whole, displaying their
4506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// values as a stacked-bar chart.
4516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
4526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
4536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - |id| is used to disambiguate counters with the same name. It must either
4546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
4556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   will be xored with a hash of the process ID so that the same pointer on
4566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   two different processes will not collide.
4576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \
4586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, value2_val) \
4596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
4606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, \
4616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value1_name, static_cast<int>(value1_val), \
4626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, static_cast<int>(value2_val))
4636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \
4646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value1_val, value2_name, value2_val) \
4656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
4666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
4676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value1_name, static_cast<int>(value1_val), \
4686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        value2_name, static_cast<int>(value2_val))
4696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
4706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
4716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
4726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// associated arguments. If the category is not enabled, then this
4736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// does nothing.
4746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
4756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
4766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC
4776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   events are considered to match if their category_group, name and id values
4786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   all match. |id| must either be a pointer or an integer value up to 64 bits.
4796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   If it's a pointer, the bits will be xored with a hash of the process ID so
4806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   that the same pointer on two different processes will not collide.
4816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
4826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// An asynchronous operation can consist of multiple phases. The first phase is
4836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// defined by the ASYNC_BEGIN calls. Additional phases can be defined using the
4846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will
4856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// annotate the block following the call. The ASYNC_STEP_PAST macro will
4866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// annotate the block prior to the call. Note that any particular event must use
4876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// only STEP_INTO or STEP_PAST macros; they can not mix and match. When the
4886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// operation completes, call ASYNC_END.
4896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//
4906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// An ASYNC trace typically occurs on a single thread (if not, they will only be
4916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// drawn on the thread defined in the ASYNC_BEGIN event), but all events in that
4926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// operation must use the same |name| and |id|. Each step can have its own
4936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// args.
4946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \
4956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
4966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE)
4976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
4986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val) \
4996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
5006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
5016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
5026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val, arg2_name, arg2_val) \
5036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
5046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, \
5056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
5066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \
5076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
5086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY)
5096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
5106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val) \
5116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
5126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
5136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
5146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
5156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val, arg2_name, arg2_val) \
5166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
5176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
5186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
5196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
5206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single ASYNC_STEP_INTO event for |step| immediately. If the
5216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// category is not enabled, then this does nothing. The |name| and |id| must
5226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// match the ASYNC_BEGIN event above. The |step| param identifies this step
5236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// within the async event. This should be called at the beginning of the next
5246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
5256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// ASYNC_STEP_PAST events.
5266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step) \
5276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \
5286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step)
5296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \
5306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                     arg1_name, arg1_val) \
5316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \
5326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \
5336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
5346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
5356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single ASYNC_STEP_PAST event for |step| immediately. If the
5366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// category is not enabled, then this does nothing. The |name| and |id| must
5376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// match the ASYNC_BEGIN event above. The |step| param identifies this step
5386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// within the async event. This should be called at the beginning of the next
5396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
5406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// ASYNC_STEP_INTO events.
5416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step) \
5426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \
5436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step)
5446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \
5456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                     arg1_name, arg1_val) \
5466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \
5476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \
5486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
5496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
5506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single ASYNC_END event for "name" immediately. If the category
5516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// is not enabled, then this does nothing.
5526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_END0(category_group, name, id) \
5536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
5546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE)
5556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \
5566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
5576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
5586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \
5596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
5606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
5616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, \
5626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
5636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \
5646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
5656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY)
5666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \
5676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val) \
5686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
5696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
5706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
5716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \
5726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val, arg2_name, arg2_val) \
5736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
5746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
5756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
5766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
5776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
5786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
5796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// associated arguments. If the category is not enabled, then this
5806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// does nothing.
5816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - category and name strings must have application lifetime (statics or
5826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   literals). They may not include " chars.
5836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
5846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   events are considered to match if their category_group, name and id values
5856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   all match. |id| must either be a pointer or an integer value up to 64 bits.
5866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   If it's a pointer, the bits will be xored with a hash of the process ID so
5876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//   that the same pointer on two different processes will not collide.
5886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// FLOW events are different from ASYNC events in how they are drawn by the
5896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// tracing UI. A FLOW defines asynchronous data flow, such as posting a task
5906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
5916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
5926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
5936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
5946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// macros. When the operation completes, call FLOW_END. An async operation can
5956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// span threads and processes, but all events in that operation must use the
5966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// same |name| and |id|. Each event can have its own args.
5976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \
5986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
5996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE)
6006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \
6016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
6026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
6036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \
6046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
6056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
6066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, \
6076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
6086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \
6096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
6106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY)
6116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \
6126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val) \
6136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
6146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
6156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
6166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \
6176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val, arg2_name, arg2_val) \
6186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
6196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
6206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
6216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single FLOW_STEP event for |step| immediately. If the category
6236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// is not enabled, then this does nothing. The |name| and |id| must match the
6246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// FLOW_BEGIN event above. The |step| param identifies this step within the
6256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// async event. This should be called at the beginning of the next phase of an
6266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// asynchronous operation.
6276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \
6286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
6296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step)
6306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, \
6316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val) \
6326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
6336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \
6346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
6356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \
6366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
6376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step)
6386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, \
6396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val) \
6406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
6416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \
6426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
6436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Records a single FLOW_END event for "name" immediately. If the category
6456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// is not enabled, then this does nothing.
6466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_END0(category_group, name, id) \
6476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
6486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE)
6496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \
6506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
6516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
6526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \
6536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg2_name, arg2_val) \
6546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
6556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_NONE, \
6566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
6576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \
6586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
6596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY)
6606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \
6616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val) \
6626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
6636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
6646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val)
6656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \
6666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_val, arg2_name, arg2_val) \
6676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
6686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, TRACE_EVENT_FLAG_COPY, \
6696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        arg1_name, arg1_val, arg2_name, arg2_val)
6706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Macros to track the life time and value of arbitrary client objects.
6726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// See also TraceTrackableObject.
6736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \
6746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_CREATE_OBJECT, \
6756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE)
6766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) \
6786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, \
6796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE,\
6806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        "snapshot", snapshot)
6816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
6836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \
6846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE)
6856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
6876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
6886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        (SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags | \
6896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org         SkEventTracer::kEnabledForEventCallback_CategoryGroupEnabledFlags)
6906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
6916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Macro to efficiently determine if a given category group is enabled.
6926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \
6936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    do { \
6946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
6956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
6966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        *ret = true; \
6976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } else { \
6986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        *ret = false; \
6996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } \
7006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    } while (0)
7016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Macro to efficiently determine, through polling, if a new trace has begun.
7036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_IS_NEW_TRACE(ret) \
7046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    do { \
7056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \
7066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \
7076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      if (num_traces_recorded != -1 && \
7086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          num_traces_recorded != \
7096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \
7106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = \
7116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            num_traces_recorded; \
7126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        *ret = true; \
7136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } else { \
7146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        *ret = false; \
7156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } \
7166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    } while (0)
7176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org////////////////////////////////////////////////////////////////////////////////
7196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation specific tracing API definitions.
7206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Get a pointer to the enabled state of the given trace category. Only
7226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// long-lived literal strings should be given as the category group. The
7236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// returned pointer can be held permanently in a local static for example. If
7246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// the unsigned char is non-zero, tracing is enabled. If tracing is enabled,
7256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled
7266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// between the load of the tracing state and the call to
7276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out
7286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// for best performance when tracing is disabled.
7296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// const uint8_t*
7306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
7316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
7326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::GetInstance()->getCategoryGroupEnabled
7336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Get the number of times traces have been recorded. This is used to implement
7356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// the TRACE_EVENT_IS_NEW_TRACE facility.
7366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED()
7376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \
7386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::GetInstance()->getNumTracesRecorded
7396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Add a trace event to the platform tracing system.
7416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// SkEventTracer::Handle TRACE_EVENT_API_ADD_TRACE_EVENT(
7426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    char phase,
7436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    const uint8_t* category_group_enabled,
7446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    const char* name,
7456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    uint64_t id,
7466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    int num_args,
7476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    const char** arg_names,
7486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    const uint8_t* arg_types,
7496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    const uint64_t* arg_values,
7506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//                    unsigned char flags)
7516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_ADD_TRACE_EVENT \
7526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::GetInstance()->addTraceEvent
7536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Set the duration field of a COMPLETE trace event.
7556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
7566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     const uint8_t* category_group_enabled,
7576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     const char* name,
7586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org//     SkEventTracer::Handle id)
7596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
7606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::GetInstance()->updateTraceEventDuration
7616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// These operations are atomic in the Chrome tracing implementation
7636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// to cater to ARM's weak memory consistency; we're just doing read/
7646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// write here because it's not strictly needed for correctness.
7656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// So says Nat.
7666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// FIXME
7676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_ATOMIC_WORD intptr_t
7696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_ATOMIC_LOAD(var) (*(&var))
7706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_ATOMIC_STORE(var, value) (var=value)
7716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Defines visibility for classes in trace_event.h
7736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_CLASS_EXPORT SK_API
7746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// The thread buckets for the sampling profiler.
7766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgTRACE_EVENT_API_CLASS_EXPORT extern \
7776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
7786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket)                           \
7806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    g_trace_state[thread_bucket]
7816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org////////////////////////////////////////////////////////////////////////////////
7836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation detail: trace event macros create temporary variables
7856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// to keep instrumentation overhead low. These macros give each temporary
7866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// variable a unique name based on the line number to prevent name collisions.
7876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_UID3(a,b) \
7886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    trace_event_unique_##a##b
7896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_UID2(a,b) \
7906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_UID3(a,b)
7916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_UID(name_prefix) \
7926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
7936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
7946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation detail: internal macro to create static category.
7956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// No barriers are needed, because this code is designed to operate safely
7966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// even when the unsigned char* points to garbage data (which may be the case
7976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// on processors without cache coherency).
7986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
7996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    category_group, atomic, category_group_enabled) \
8006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    category_group_enabled = \
8016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        reinterpret_cast<const uint8_t*>(TRACE_EVENT_API_ATOMIC_LOAD( \
8026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            atomic)); \
8036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    if (!category_group_enabled) { \
8046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      category_group_enabled = \
8056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \
8066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      TRACE_EVENT_API_ATOMIC_STORE(atomic, \
8076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \
8086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org              category_group_enabled)); \
8096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    }
8106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
8126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
8136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const uint8_t* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \
8146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \
8156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        INTERNAL_TRACE_EVENT_UID(atomic), \
8166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        INTERNAL_TRACE_EVENT_UID(category_group_enabled));
8176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation detail: internal macro to create static category and add
8196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// event if the category is enabled.
8206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
8216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    do { \
8226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
8236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
8246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        skia::tracing_internals::AddTraceEvent( \
8256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
8266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            skia::tracing_internals::kNoEventId, flags, ##__VA_ARGS__); \
8276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } \
8286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    } while (0)
8296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation detail: internal macro to create static category and add begin
8316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// event if the category is enabled. Also adds the end event when the scope
8326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// ends.
8336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
8346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
8356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
8366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
8376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      SkEventTracer::Handle h = skia::tracing_internals::AddTraceEvent( \
8386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          TRACE_EVENT_PHASE_COMPLETE, \
8396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
8406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          name, skia::tracing_internals::kNoEventId, \
8416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
8426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
8436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
8446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    }
8456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation detail: internal macro to create static category and add
8476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// event if the category is enabled.
8486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
8496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                         flags, ...) \
8506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    do { \
8516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
8526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
8536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
8546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        skia::tracing_internals::TraceID trace_event_trace_id( \
8556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            id, &trace_event_flags); \
8566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        skia::tracing_internals::AddTraceEvent( \
8576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
8586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            name, trace_event_trace_id.data(), trace_event_flags, \
8596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            ##__VA_ARGS__); \
8606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } \
8616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    } while (0)
8626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Implementation detail: internal macro to create static category and add
8646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// event if the category is enabled.
8656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \
8666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        category_group, name, id, thread_id, flags, ...) \
8676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    do { \
8686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
8696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
8706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
8716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        skia::tracing_internals::TraceID trace_event_trace_id( \
8726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            id, &trace_event_flags); \
8736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        skia::tracing_internals::AddTraceEventWithThreadIdAndTimestamp( \
8746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
8756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            name, trace_event_trace_id.data(), \
8766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            thread_id, base::TimeTicks::FromInternalValue(timestamp), \
8776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org            trace_event_flags, ##__VA_ARGS__); \
8786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      } \
8796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    } while (0)
8806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Notes regarding the following definitions:
8826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// New values can be added and propagated to third party libraries, but existing
8836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// definitions must never be changed, because third party libraries may use old
8846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// definitions.
8856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
8866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
8876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_BEGIN    ('B')
8886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_END      ('E')
8896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_COMPLETE ('X')
8906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_INSTANT  ('i')
8916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
8926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_ASYNC_STEP_INTO  ('T')
8936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_ASYNC_STEP_PAST  ('p')
8946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_ASYNC_END   ('F')
8956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_FLOW_BEGIN ('s')
8966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_FLOW_STEP  ('t')
8976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_FLOW_END   ('f')
8986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_METADATA ('M')
8996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_COUNTER  ('C')
9006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_SAMPLE  ('P')
9016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_CREATE_OBJECT ('N')
9026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O')
9036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_PHASE_DELETE_OBJECT ('D')
9046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
9066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLAG_NONE         (static_cast<unsigned char>(0))
9076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLAG_COPY         (static_cast<unsigned char>(1 << 0))
9086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLAG_HAS_ID       (static_cast<unsigned char>(1 << 1))
9096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLAG_MANGLE_ID    (static_cast<unsigned char>(1 << 2))
9106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned char>(1 << 3))
9116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_FLAG_SCOPE_MASK   (static_cast<unsigned char>( \
9136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_FLAG_SCOPE_OFFSET | (TRACE_EVENT_FLAG_SCOPE_OFFSET << 1)))
9146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Type values for identifying types in the TraceValue union.
9166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_BOOL         (static_cast<unsigned char>(1))
9176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_UINT         (static_cast<unsigned char>(2))
9186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_INT          (static_cast<unsigned char>(3))
9196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_DOUBLE       (static_cast<unsigned char>(4))
9206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_POINTER      (static_cast<unsigned char>(5))
9216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_STRING       (static_cast<unsigned char>(6))
9226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_COPY_STRING  (static_cast<unsigned char>(7))
9236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_VALUE_TYPE_CONVERTABLE  (static_cast<unsigned char>(8))
9246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Enum reflecting the scope of an INSTANT event. Must fit within
9266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TRACE_EVENT_FLAG_SCOPE_MASK.
9276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPE_GLOBAL  (static_cast<unsigned char>(0 << 3))
9286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3))
9296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPE_THREAD  (static_cast<unsigned char>(2 << 3))
9306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPE_NAME_GLOBAL  ('g')
9326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
9336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_SCOPE_NAME_THREAD  ('t')
9346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgnamespace skia {
9366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgnamespace tracing_internals {
9376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Specify these values when the corresponding argument of AddTraceEvent is not
9396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// used.
9406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgconst int kZeroNumArgs = 0;
9416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgconst uint64_t kNoEventId = 0;
9426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
9446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// are by default mangled with the Process ID so that they are unlikely to
9456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// collide when the same pointer is used on different processes.
9466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass TraceID {
9476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org public:
9486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  class DontMangle {
9496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org   public:
9506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(const void* id)
9516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(
9523e15f9006cc0a6a9f1f153e87d08149b73531d01cjacek              reinterpret_cast<uintptr_t>(id))) {}
9536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(uint64_t id) : data_(id) {}
9546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(unsigned int id) : data_(id) {}
9556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(unsigned short id) : data_(id) {}
9566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(unsigned char id) : data_(id) {}
9576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(long long id)
9586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(long id)
9606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(int id)
9626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(short id)
9646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit DontMangle(signed char id)
9666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t data() const { return data_; }
9686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org   private:
9696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t data_;
9706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  };
9716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  class ForceMangle {
9736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org   public:
9746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(uint64_t id) : data_(id) {}
9756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(unsigned int id) : data_(id) {}
9766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(unsigned short id) : data_(id) {}
9776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(unsigned char id) : data_(id) {}
9786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(long long id)
9796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(long id)
9816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(int id)
9836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(short id)
9856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    explicit ForceMangle(signed char id)
9876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        : data_(static_cast<uint64_t>(id)) {}
9886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t data() const { return data_; }
9896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org   private:
9906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t data_;
9916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  };
9926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
9936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(const void* id, unsigned char* flags)
9946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(static_cast<uint64_t>(
9953e15f9006cc0a6a9f1f153e87d08149b73531d01cjacek              reinterpret_cast<uintptr_t>(id))) {
9966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    *flags |= TRACE_EVENT_FLAG_MANGLE_ID;
9976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
9986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) {
9996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    *flags |= TRACE_EVENT_FLAG_MANGLE_ID;
10006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
10016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(DontMangle id, unsigned char* flags) : data_(id.data()) {
10026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
10036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(uint64_t id, unsigned char* flags)
10046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(id) { (void)flags; }
10056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(unsigned int id, unsigned char* flags)
10066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(id) { (void)flags; }
10076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(unsigned short id, unsigned char* flags)
10086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(id) { (void)flags; }
10096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(unsigned char id, unsigned char* flags)
10106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(id) { (void)flags; }
10116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(long long id, unsigned char* flags)
10126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(static_cast<uint64_t>(id)) { (void)flags; }
10136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(long id, unsigned char* flags)
10146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(static_cast<uint64_t>(id)) { (void)flags; }
10156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(int id, unsigned char* flags)
10166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(static_cast<uint64_t>(id)) { (void)flags; }
10176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(short id, unsigned char* flags)
10186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(static_cast<uint64_t>(id)) { (void)flags; }
10196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceID(signed char id, unsigned char* flags)
10206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      : data_(static_cast<uint64_t>(id)) { (void)flags; }
10216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  uint64_t data() const { return data_; }
10236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org private:
10256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  uint64_t data_;
10266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
10276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Simple union to store various types as uint64_t.
10296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgunion TraceValueUnion {
10306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  bool as_bool;
10316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  uint64_t as_uint;
10326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  long long as_int;
10336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  double as_double;
10346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const void* as_pointer;
10356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const char* as_string;
10366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
10376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Simple container for const char* that should be copied instead of retained.
10396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass TraceStringWithCopy {
10406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org public:
10416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  explicit TraceStringWithCopy(const char* str) : str_(str) {}
10426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  operator const char* () const { return str_; }
10436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org private:
10446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const char* str_;
10456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
10466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Define SetTraceValue for each allowed type. It stores the type and
10486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// value in the return arguments. This allows this API to avoid declaring any
10496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// structures so that it is portable to third_party libraries.
10506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \
10516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                         union_member, \
10526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                         value_type_id) \
10536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    static inline void SetTraceValue( \
10546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        actual_type arg, \
10556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        unsigned char* type, \
10566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        uint64_t* value) { \
10576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      TraceValueUnion type_value; \
10586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      type_value.union_member = arg; \
10596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      *type = value_type_id; \
10606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      *value = type_value.as_uint; \
10616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    }
10626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Simpler form for int types that can be safely casted.
10636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \
10646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                             value_type_id) \
10656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    static inline void SetTraceValue( \
10666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        actual_type arg, \
10676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        unsigned char* type, \
10686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        uint64_t* value) { \
10696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      *type = value_type_id; \
10706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      *value = static_cast<uint64_t>(arg); \
10716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    }
10726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint64_t, TRACE_VALUE_TYPE_UINT)
10746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT)
10756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT)
10766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT)
10776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT)
10786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT)
10796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT)
10806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT)
10816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT)
10826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL)
10836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE)
10846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer,
10856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                 TRACE_VALUE_TYPE_POINTER)
10866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string,
10876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                 TRACE_VALUE_TYPE_STRING)
10886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgINTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string,
10896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                 TRACE_VALUE_TYPE_COPY_STRING)
10906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#undef INTERNAL_DECLARE_SET_TRACE_VALUE
10926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT
10936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
10946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// These AddTraceEvent and AddTraceEvent template
10956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// functions are defined here instead of in the macro, because the arg_values
10966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// could be temporary objects, such as std::string. In order to store
10976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// pointers to the internal c_str and pass through to the tracing API,
10986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// the arg_values must live throughout these procedures.
10996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgstatic inline SkEventTracer::Handle
11016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgAddTraceEvent(
11026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    char phase,
11036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const uint8_t* category_group_enabled,
11046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* name,
11056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t id,
11066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    unsigned char flags) {
11076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  return TRACE_EVENT_API_ADD_TRACE_EVENT(
11086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      phase, category_group_enabled, name, id,
11096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      kZeroNumArgs, NULL, NULL, NULL, flags);
11106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}
11116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgtemplate<class ARG1_TYPE>
11136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgstatic inline SkEventTracer::Handle
11146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgAddTraceEvent(
11156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    char phase,
11166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const uint8_t* category_group_enabled,
11176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* name,
11186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t id,
11196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    unsigned char flags,
11206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* arg1_name,
11216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const ARG1_TYPE& arg1_val) {
11226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const int num_args = 1;
11236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  uint8_t arg_types[1];
11246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  uint64_t arg_values[1];
11256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
11266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  return TRACE_EVENT_API_ADD_TRACE_EVENT(
11276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      phase, category_group_enabled, name, id,
11286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      num_args, &arg1_name, arg_types, arg_values, flags);
11296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}
11306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgtemplate<class ARG1_TYPE, class ARG2_TYPE>
11326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgstatic inline SkEventTracer::Handle
11336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgAddTraceEvent(
11346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    char phase,
11356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const uint8_t* category_group_enabled,
11366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* name,
11376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    uint64_t id,
11386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    unsigned char flags,
11396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* arg1_name,
11406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const ARG1_TYPE& arg1_val,
11416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* arg2_name,
11426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const ARG2_TYPE& arg2_val) {
11436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const int num_args = 2;
11446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const char* arg_names[2] = { arg1_name, arg2_name };
11456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  unsigned char arg_types[2];
11466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  uint64_t arg_values[2];
11476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
11486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
11496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  return TRACE_EVENT_API_ADD_TRACE_EVENT(
11506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      phase, category_group_enabled, name, id,
11516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      num_args, arg_names, arg_types, arg_values, flags);
11526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}
11536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Used by TRACE_EVENTx macros. Do not use directly.
11556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
11566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org public:
11576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  // Note: members of data_ intentionally left uninitialized. See Initialize.
11586169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  ScopedTracer() : p_data_(NULL) {}
11596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11606169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  ~ScopedTracer() {
11616169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    if (p_data_ && *data_.category_group_enabled)
11626169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
11636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org          data_.category_group_enabled, data_.name, data_.event_handle);
11646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
11656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  void Initialize(const uint8_t* category_group_enabled,
11676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                  const char* name,
11686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                  SkEventTracer::Handle event_handle) {
11696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    data_.category_group_enabled = category_group_enabled;
11706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    data_.name = name;
11716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    data_.event_handle = event_handle;
11726169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    p_data_ = &data_;
11736169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
11746169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11756169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org private:
11766169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  // This Data struct workaround is to avoid initializing all the members
11776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  // in Data during construction of this object, since this object is always
11786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  // constructed, even when tracing is disabled. If the members of Data were
11796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  // members of this class instead, compiler warnings occur about potential
11806169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  // uninitialized accesses.
11816169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  struct Data {
11826169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const uint8_t* category_group_enabled;
11836169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    const char* name;
11846169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::Handle event_handle;
11856169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  };
11866169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  Data* p_data_;
11876169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  Data data_;
11886169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
11896169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11906169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
11916169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient {
11926169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org public:
11936169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  ScopedTraceBinaryEfficient(const char* category_group, const char* name);
11946169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  ~ScopedTraceBinaryEfficient();
11956169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
11966169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org private:
11976169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const uint8_t* category_group_enabled_;
11986169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const char* name_;
11996169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  SkEventTracer::Handle event_handle_;
12006169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
12016169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12026169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// This macro generates less code then TRACE_EVENT0 but is also
12036169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// slower to execute when tracing is off. It should generally only be
12046169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// used with code that is seldom executed or conditionally executed
12056169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// when debugging.
12066169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// For now the category_group must be "gpu".
12076169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \
12086169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    skia::tracing_internals::ScopedTraceBinaryEfficient \
12096169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name);
12106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// TraceEventSamplingStateScope records the current sampling state
12126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// and sets a new sampling state. When the scope exists, it restores
12136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// the sampling state having recorded.
12146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgtemplate<size_t BucketNumber>
12156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass TraceEventSamplingStateScope {
12166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org public:
12176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  TraceEventSamplingStateScope(const char* category_and_name) {
12186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current();
12196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name);
12206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
12216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  ~TraceEventSamplingStateScope() {
12236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_);
12246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
12256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  static inline const char* Current() {
12276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD(
12286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      g_trace_state[BucketNumber]));
12296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
12306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  static inline void Set(const char* category_and_name) {
12326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    TRACE_EVENT_API_ATOMIC_STORE(
12336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      g_trace_state[BucketNumber],
12346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
12356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        const_cast<char*>(category_and_name)));
12366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  }
12376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org private:
12396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org  const char* previous_state_;
12406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
12416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}  // namespace tracing_internals
12436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}  // namespace skia
12446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
12456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#endif
1246