trace_event_common.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_TRACE_EVENT_COMMON_TRACE_EVENT_COMMON_H_
  5. #define BASE_TRACE_EVENT_COMMON_TRACE_EVENT_COMMON_H_
  6. // This header file defines the set of trace_event macros without specifying
  7. // how the events actually get collected and stored. If you need to expose trace
  8. // events to some other universe, you can copy-and-paste this file as well as
  9. // trace_event.h, modifying the macros contained there as necessary for the
  10. // target platform. The end result is that multiple libraries can funnel events
  11. // through to a shared trace event collector.
  12. // IMPORTANT: To avoid conflicts, if you need to modify this file for a library,
  13. // land your change in base/ first, and then copy-and-paste it.
  14. // Trace events are for tracking application performance and resource usage.
  15. // Macros are provided to track:
  16. // Begin and end of function calls
  17. // Counters
  18. //
  19. // Events are issued against categories. Whereas LOG's
  20. // categories are statically defined, TRACE categories are created
  21. // implicitly with a string. For example:
  22. // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent",
  23. // TRACE_EVENT_SCOPE_THREAD)
  24. //
  25. // It is often the case that one trace may belong in multiple categories at the
  26. // same time. The first argument to the trace can be a comma-separated list of
  27. // categories, forming a category group, like:
  28. //
  29. // TRACE_EVENT_INSTANT0("input,views", "OnMouseOver", TRACE_EVENT_SCOPE_THREAD)
  30. //
  31. // We can enable/disable tracing of OnMouseOver by enabling/disabling either
  32. // category.
  33. //
  34. // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope:
  35. // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly")
  36. // doSomethingCostly()
  37. // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly")
  38. // Note: our tools can't always determine the correct BEGIN/END pairs unless
  39. // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you
  40. // need them to be in separate scopes.
  41. //
  42. // A common use case is to trace entire function scopes. This
  43. // issues a trace BEGIN and END automatically:
  44. // void doSomethingCostly() {
  45. // TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly");
  46. // ...
  47. // }
  48. //
  49. // Additional parameters can be associated with an event:
  50. // void doSomethingCostly2(int howMuch) {
  51. // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly",
  52. // "howMuch", howMuch);
  53. // ...
  54. // }
  55. //
  56. // The trace system will automatically add to this information the
  57. // current process id, thread id, and a timestamp in microseconds.
  58. //
  59. // To trace an asynchronous procedure such as an IPC send/receive, use
  60. // NESTABLE_ASYNC_BEGIN and NESTABLE_ASYNC_END:
  61. // [single threaded sender code]
  62. // static int send_count = 0;
  63. // ++send_count;
  64. // TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
  65. // "ipc", "message", TRACE_ID_LOCAL(send_count));
  66. // Send(new MyMessage(send_count));
  67. // [receive code]
  68. // void OnMyMessage(send_count) {
  69. // TRACE_NESTABLE_EVENT_ASYNC_END0(
  70. // "ipc", "message", TRACE_ID_LOCAL(send_count));
  71. // }
  72. // The third parameter is a unique ID to match NESTABLE_ASYNC_BEGIN/ASYNC_END
  73. // pairs. NESTABLE_ASYNC_BEGIN and ASYNC_END can occur on any thread of any
  74. // traced process. // Pointers can be used for the ID parameter, and they will
  75. // be annotated internally so that the same pointer on two different processes
  76. // will not match. For example:
  77. // class MyTracedClass {
  78. // public:
  79. // MyTracedClass() {
  80. // TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("category", "MyTracedClass", this);
  81. // }
  82. // ~MyTracedClass() {
  83. // TRACE_EVENT_NESTABLE_ASYNC_END0("category", "MyTracedClass", this);
  84. // }
  85. // }
  86. //
  87. // Trace event also supports counters, which is a way to track a quantity
  88. // as it varies over time. Counters are created with the following macro:
  89. // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue);
  90. //
  91. // Counters are process-specific. The macro itself can be issued from any
  92. // thread, however.
  93. //
  94. // Sometimes, you want to track two counters at once. You can do this with two
  95. // counter macros:
  96. // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]);
  97. // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter1", g_myCounterValue[1]);
  98. // Or you can do it with a combined macro:
  99. // TRACE_COUNTER2("MY_SUBSYSTEM", "myCounter",
  100. // "bytesPinned", g_myCounterValue[0],
  101. // "bytesAllocated", g_myCounterValue[1]);
  102. // This indicates to the tracing UI that these counters should be displayed
  103. // in a single graph, as a summed area chart.
  104. //
  105. // Since counters are in a global namespace, you may want to disambiguate with a
  106. // unique ID, by using the TRACE_COUNTER_ID* variations.
  107. //
  108. // By default, trace collection is compiled in, but turned off at runtime.
  109. // Collecting trace data is the responsibility of the embedding
  110. // application. In Chrome's case, navigating to about:tracing will turn on
  111. // tracing and display data collected across all active processes.
  112. //
  113. //
  114. // Memory scoping note:
  115. // Tracing copies the pointers, not the string content, of the strings passed
  116. // in for category_group, name, and arg_names. Thus, the following code will
  117. // cause problems:
  118. // char* str = strdup("importantName");
  119. // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD!
  120. // free(str); // Trace system now has dangling pointer
  121. //
  122. // To avoid this issue with the |name| and |arg_name| parameters, use the
  123. // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead.
  124. // Notes: The category must always be in a long-lived char* (i.e. static const).
  125. // The |arg_values|, when used, are always deep copied with the _COPY
  126. // macros.
  127. //
  128. // When are string argument values copied:
  129. // const char* arg_values are only referenced by default:
  130. // TRACE_EVENT1("category", "name",
  131. // "arg1", "literal string is only referenced");
  132. // Use TRACE_STR_COPY to force copying of a const char*:
  133. // TRACE_EVENT1("category", "name",
  134. // "arg1", TRACE_STR_COPY("string will be copied"));
  135. // std::string arg_values are always copied:
  136. // TRACE_EVENT1("category", "name",
  137. // "arg1", std::string("string will be copied"));
  138. //
  139. //
  140. // Convertable notes:
  141. // Converting a large data type to a string can be costly. To help with this,
  142. // the trace framework provides an interface ConvertableToTraceFormat. If you
  143. // inherit from it and implement the AppendAsTraceFormat method the trace
  144. // framework will call back to your object to convert a trace output time. This
  145. // means, if the category for the event is disabled, the conversion will not
  146. // happen.
  147. //
  148. // class MyData : public base::trace_event::ConvertableToTraceFormat {
  149. // public:
  150. // MyData() {}
  151. // void AppendAsTraceFormat(std::string* out) const override {
  152. // out->append("{\"foo\":1}");
  153. // }
  154. // private:
  155. // ~MyData() override {}
  156. // DISALLOW_COPY_AND_ASSIGN(MyData);
  157. // };
  158. //
  159. // TRACE_EVENT1("foo", "bar", "data",
  160. // std::unique_ptr<ConvertableToTraceFormat>(new MyData()));
  161. //
  162. // The trace framework will take ownership if the passed pointer and it will
  163. // be free'd when the trace buffer is flushed.
  164. //
  165. // Note, we only do the conversion when the buffer is flushed, so the provided
  166. // data object should not be modified after it's passed to the trace framework.
  167. //
  168. //
  169. // Thread Safety:
  170. // A thread safe singleton and mutex are used for thread safety. Category
  171. // enabled flags are used to limit the performance impact when the system
  172. // is not enabled.
  173. //
  174. // TRACE_EVENT macros first cache a pointer to a category. The categories are
  175. // statically allocated and safe at all times, even after exit. Fetching a
  176. // category is protected by the TraceLog::lock_. Multiple threads initializing
  177. // the static variable is safe, as they will be serialized by the lock and
  178. // multiple calls will return the same pointer to the category.
  179. //
  180. // Then the category_group_enabled flag is checked. This is a unsigned char, and
  181. // not intended to be multithread safe. It optimizes access to AddTraceEvent
  182. // which is threadsafe internally via TraceLog::lock_. The enabled flag may
  183. // cause some threads to incorrectly call or skip calling AddTraceEvent near
  184. // the time of the system being enabled or disabled. This is acceptable as
  185. // we tolerate some data loss while the system is being enabled/disabled and
  186. // because AddTraceEvent is threadsafe internally and checks the enabled state
  187. // again under lock.
  188. //
  189. // Without the use of these static category pointers and enabled flags all
  190. // trace points would carry a significant performance cost of acquiring a lock
  191. // and resolving the category.
  192. // Check that nobody includes this file directly. Clients are supposed to
  193. // include the surrounding "trace_event.h" of their project instead.
  194. #if defined(TRACE_EVENT0)
  195. #error "Another copy of this file has already been included."
  196. #endif
  197. // This will mark the trace event as disabled by default. The user will need
  198. // to explicitly enable the event.
  199. #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
  200. // Records a pair of begin and end events called "name" for the current
  201. // scope, with 0, 1 or 2 associated arguments. If the category is not
  202. // enabled, then this does nothing.
  203. // - category and name strings must have application lifetime (statics or
  204. // literals). They may not include " chars.
  205. #define TRACE_EVENT0(category_group, name) \
  206. INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
  207. #define TRACE_EVENT_WITH_FLOW0(category_group, name, bind_id, flow_flags) \
  208. INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
  209. flow_flags)
  210. #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
  211. INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
  212. #define TRACE_EVENT_WITH_FLOW1(category_group, name, bind_id, flow_flags, \
  213. arg1_name, arg1_val) \
  214. INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
  215. flow_flags, arg1_name, arg1_val)
  216. #define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, \
  217. arg2_val) \
  218. INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val, \
  219. arg2_name, arg2_val)
  220. #define TRACE_EVENT_WITH_FLOW2(category_group, name, bind_id, flow_flags, \
  221. arg1_name, arg1_val, arg2_name, arg2_val) \
  222. INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
  223. flow_flags, arg1_name, arg1_val, \
  224. arg2_name, arg2_val)
  225. // Records a single event called "name" immediately, with 0, 1 or 2
  226. // associated arguments. If the category is not enabled, then this
  227. // does nothing.
  228. // - category and name strings must have application lifetime (statics or
  229. // literals). They may not include " chars.
  230. #define TRACE_EVENT_INSTANT0(category_group, name, scope) \
  231. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  232. TRACE_EVENT_FLAG_NONE | scope)
  233. #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
  234. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  235. TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val)
  236. #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
  237. arg2_name, arg2_val) \
  238. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  239. TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val, \
  240. arg2_name, arg2_val)
  241. #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope) \
  242. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  243. TRACE_EVENT_FLAG_COPY | scope)
  244. #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, arg1_name, \
  245. arg1_val) \
  246. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  247. TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val)
  248. #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, arg1_name, \
  249. arg1_val, arg2_name, arg2_val) \
  250. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  251. TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val, \
  252. arg2_name, arg2_val)
  253. #define TRACE_EVENT_INSTANT_WITH_FLAGS0(category_group, name, scope_and_flags) \
  254. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  255. scope_and_flags)
  256. #define TRACE_EVENT_INSTANT_WITH_FLAGS1(category_group, name, scope_and_flags, \
  257. arg1_name, arg1_val) \
  258. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
  259. scope_and_flags, arg1_name, arg1_val)
  260. #define TRACE_EVENT_INSTANT_WITH_TIMESTAMP0(category_group, name, scope, \
  261. timestamp) \
  262. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  263. TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp, \
  264. TRACE_EVENT_FLAG_NONE | scope)
  265. #define TRACE_EVENT_INSTANT_WITH_TIMESTAMP1(category_group, name, scope, \
  266. timestamp, arg_name, arg_val) \
  267. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  268. TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp, \
  269. TRACE_EVENT_FLAG_NONE | scope, arg_name, arg_val)
  270. // Records a single BEGIN event called "name" immediately, with 0, 1 or 2
  271. // associated arguments. If the category is not enabled, then this
  272. // does nothing.
  273. // - category and name strings must have application lifetime (statics or
  274. // literals). They may not include " chars.
  275. #define TRACE_EVENT_BEGIN0(category_group, name) \
  276. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
  277. TRACE_EVENT_FLAG_NONE)
  278. #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \
  279. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
  280. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  281. #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \
  282. arg2_name, arg2_val) \
  283. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
  284. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
  285. arg2_name, arg2_val)
  286. #define TRACE_EVENT_BEGIN_WITH_FLAGS0(category_group, name, flags) \
  287. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, flags)
  288. #define TRACE_EVENT_BEGIN_WITH_FLAGS1(category_group, name, flags, arg1_name, \
  289. arg1_val) \
  290. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
  291. flags, arg1_name, arg1_val)
  292. #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \
  293. arg2_name, arg2_val) \
  294. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
  295. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
  296. arg2_name, arg2_val)
  297. // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
  298. // - |id| is used to match the _BEGIN event with the _END event.
  299. // Events are considered to match if their category_group, name and id values
  300. // all match. |id| must either be a pointer or an integer value up to 64 bits.
  301. // If it's a pointer, the bits will be xored with a hash of the process ID so
  302. // that the same pointer on two different processes will not collide.
  303. #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
  304. thread_id, timestamp) \
  305. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  306. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
  307. timestamp, TRACE_EVENT_FLAG_NONE)
  308. #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \
  309. category_group, name, id, thread_id, timestamp) \
  310. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  311. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
  312. timestamp, TRACE_EVENT_FLAG_COPY)
  313. #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP1( \
  314. category_group, name, id, thread_id, timestamp, arg1_name, arg1_val) \
  315. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  316. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
  317. timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  318. #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP2( \
  319. category_group, name, id, thread_id, timestamp, arg1_name, arg1_val, \
  320. arg2_name, arg2_val) \
  321. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  322. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
  323. timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, \
  324. arg2_val)
  325. // Records a single END event for "name" immediately. If the category
  326. // is not enabled, then this does nothing.
  327. // - category and name strings must have application lifetime (statics or
  328. // literals). They may not include " chars.
  329. #define TRACE_EVENT_END0(category_group, name) \
  330. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
  331. TRACE_EVENT_FLAG_NONE)
  332. #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \
  333. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
  334. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  335. #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, arg2_name, \
  336. arg2_val) \
  337. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
  338. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
  339. arg2_name, arg2_val)
  340. #define TRACE_EVENT_END_WITH_FLAGS0(category_group, name, flags) \
  341. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, flags)
  342. #define TRACE_EVENT_END_WITH_FLAGS1(category_group, name, flags, arg1_name, \
  343. arg1_val) \
  344. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, flags, \
  345. arg1_name, arg1_val)
  346. #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \
  347. arg2_name, arg2_val) \
  348. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
  349. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
  350. arg2_name, arg2_val)
  351. #define TRACE_EVENT_MARK_WITH_TIMESTAMP0(category_group, name, timestamp) \
  352. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  353. TRACE_EVENT_PHASE_MARK, category_group, name, timestamp, \
  354. TRACE_EVENT_FLAG_NONE)
  355. #define TRACE_EVENT_MARK_WITH_TIMESTAMP1(category_group, name, timestamp, \
  356. arg1_name, arg1_val) \
  357. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  358. TRACE_EVENT_PHASE_MARK, category_group, name, timestamp, \
  359. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  360. #define TRACE_EVENT_MARK_WITH_TIMESTAMP2( \
  361. category_group, name, timestamp, arg1_name, arg1_val, arg2_name, arg2_val) \
  362. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  363. TRACE_EVENT_PHASE_MARK, category_group, name, timestamp, \
  364. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  365. #define TRACE_EVENT_COPY_MARK(category_group, name) \
  366. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_MARK, category_group, name, \
  367. TRACE_EVENT_FLAG_COPY)
  368. #define TRACE_EVENT_COPY_MARK1(category_group, name, arg1_name, arg1_val) \
  369. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_MARK, category_group, name, \
  370. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  371. #define TRACE_EVENT_COPY_MARK_WITH_TIMESTAMP(category_group, name, timestamp) \
  372. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  373. TRACE_EVENT_PHASE_MARK, category_group, name, timestamp, \
  374. TRACE_EVENT_FLAG_COPY)
  375. // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
  376. // - |id| is used to match the _BEGIN event with the _END event.
  377. // Events are considered to match if their category_group, name and id values
  378. // all match. |id| must either be a pointer or an integer value up to 64 bits.
  379. // If it's a pointer, the bits will be xored with a hash of the process ID so
  380. // that the same pointer on two different processes will not collide.
  381. #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
  382. thread_id, timestamp) \
  383. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  384. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
  385. timestamp, TRACE_EVENT_FLAG_NONE)
  386. #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \
  387. category_group, name, id, thread_id, timestamp) \
  388. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  389. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
  390. timestamp, TRACE_EVENT_FLAG_COPY)
  391. #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP1( \
  392. category_group, name, id, thread_id, timestamp, arg1_name, arg1_val) \
  393. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  394. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
  395. timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  396. #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP2( \
  397. category_group, name, id, thread_id, timestamp, arg1_name, arg1_val, \
  398. arg2_name, arg2_val) \
  399. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  400. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
  401. timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, \
  402. arg2_val)
  403. // Records the value of a counter called "name" immediately. Value
  404. // must be representable as a 32 bit integer.
  405. // - category and name strings must have application lifetime (statics or
  406. // literals). They may not include " chars.
  407. #define TRACE_COUNTER1(category_group, name, value) \
  408. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
  409. TRACE_EVENT_FLAG_NONE, "value", \
  410. static_cast<int>(value))
  411. #define TRACE_COUNTER_WITH_FLAG1(category_group, name, flag, value) \
  412. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
  413. flag, "value", static_cast<int>(value))
  414. #define TRACE_COPY_COUNTER1(category_group, name, value) \
  415. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
  416. TRACE_EVENT_FLAG_COPY, "value", \
  417. static_cast<int>(value))
  418. // Records the values of a multi-parted counter called "name" immediately.
  419. // The UI will treat value1 and value2 as parts of a whole, displaying their
  420. // values as a stacked-bar chart.
  421. // - category and name strings must have application lifetime (statics or
  422. // literals). They may not include " chars.
  423. #define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \
  424. value2_name, value2_val) \
  425. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
  426. TRACE_EVENT_FLAG_NONE, value1_name, \
  427. static_cast<int>(value1_val), value2_name, \
  428. static_cast<int>(value2_val))
  429. #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \
  430. value2_name, value2_val) \
  431. INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
  432. TRACE_EVENT_FLAG_COPY, value1_name, \
  433. static_cast<int>(value1_val), value2_name, \
  434. static_cast<int>(value2_val))
  435. // Similar to TRACE_COUNTERx, but with a custom |timestamp| provided.
  436. #define TRACE_COUNTER_WITH_TIMESTAMP1(category_group, name, timestamp, value) \
  437. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  438. TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp, \
  439. TRACE_EVENT_FLAG_NONE, "value", static_cast<int>(value))
  440. #define TRACE_COUNTER_WITH_TIMESTAMP2(category_group, name, timestamp, \
  441. value1_name, value1_val, value2_name, \
  442. value2_val) \
  443. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  444. TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp, \
  445. TRACE_EVENT_FLAG_NONE, value1_name, static_cast<int>(value1_val), \
  446. value2_name, static_cast<int>(value2_val))
  447. // Records the value of a counter called "name" immediately. Value
  448. // must be representable as a 32 bit integer.
  449. // - category and name strings must have application lifetime (statics or
  450. // literals). They may not include " chars.
  451. // - |id| is used to disambiguate counters with the same name. It must either
  452. // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
  453. // will be xored with a hash of the process ID so that the same pointer on
  454. // two different processes will not collide.
  455. #define TRACE_COUNTER_ID1(category_group, name, id, value) \
  456. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
  457. name, id, TRACE_EVENT_FLAG_NONE, "value", \
  458. static_cast<int>(value))
  459. #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \
  460. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
  461. name, id, TRACE_EVENT_FLAG_COPY, "value", \
  462. static_cast<int>(value))
  463. // Records the values of a multi-parted counter called "name" immediately.
  464. // The UI will treat value1 and value2 as parts of a whole, displaying their
  465. // values as a stacked-bar chart.
  466. // - category and name strings must have application lifetime (statics or
  467. // literals). They may not include " chars.
  468. // - |id| is used to disambiguate counters with the same name. It must either
  469. // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
  470. // will be xored with a hash of the process ID so that the same pointer on
  471. // two different processes will not collide.
  472. #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \
  473. value2_name, value2_val) \
  474. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
  475. name, id, TRACE_EVENT_FLAG_NONE, \
  476. value1_name, static_cast<int>(value1_val), \
  477. value2_name, static_cast<int>(value2_val))
  478. #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \
  479. value1_val, value2_name, value2_val) \
  480. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
  481. name, id, TRACE_EVENT_FLAG_COPY, \
  482. value1_name, static_cast<int>(value1_val), \
  483. value2_name, static_cast<int>(value2_val))
  484. #define TRACE_EVENT_SAMPLE_WITH_ID1(category_group, name, id, arg1_name, \
  485. arg1_val) \
  486. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SAMPLE, category_group, \
  487. name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
  488. arg1_val)
  489. // -- TRACE_EVENT_ASYNC is DEPRECATED! --
  490. //
  491. // TRACE_EVENT_ASYNC_* APIs should be only used by legacy code. New code should
  492. // use TRACE_EVENT_NESTABLE_ASYNC_* APIs instead.
  493. //
  494. // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
  495. // associated arguments. If the category is not enabled, then this
  496. // does nothing.
  497. // - category and name strings must have application lifetime (statics or
  498. // literals). They may not include " chars.
  499. // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC
  500. // events are considered to match if their category_group, name and id values
  501. // all match. |id| must either be a pointer or an integer value up to 64 bits.
  502. // If it's a pointer, the bits will be xored with a hash of the process ID so
  503. // that the same pointer on two different processes will not collide.
  504. //
  505. // An asynchronous operation can consist of multiple phases. The first phase is
  506. // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the
  507. // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will
  508. // annotate the block following the call. The ASYNC_STEP_PAST macro will
  509. // annotate the block prior to the call. Note that any particular event must use
  510. // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the
  511. // operation completes, call ASYNC_END.
  512. //
  513. // An ASYNC trace typically occurs on a single thread (if not, they will only be
  514. // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that
  515. // operation must use the same |name| and |id|. Each step can have its own
  516. // args.
  517. #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \
  518. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
  519. category_group, name, id, \
  520. TRACE_EVENT_FLAG_NONE)
  521. #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
  522. arg1_val) \
  523. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
  524. category_group, name, id, \
  525. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  526. #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
  527. arg1_val, arg2_name, arg2_val) \
  528. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  529. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
  530. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  531. #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \
  532. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
  533. category_group, name, id, \
  534. TRACE_EVENT_FLAG_COPY)
  535. #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
  536. arg1_val) \
  537. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
  538. category_group, name, id, \
  539. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  540. #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
  541. arg1_val, arg2_name, arg2_val) \
  542. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  543. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
  544. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
  545. // Similar to TRACE_EVENT_ASYNC_BEGINx but with a custom |at| timestamp
  546. // provided.
  547. #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
  548. timestamp) \
  549. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  550. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
  551. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
  552. #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \
  553. category_group, name, id, timestamp, arg1_name, arg1_val) \
  554. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  555. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
  556. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  557. arg1_name, arg1_val)
  558. #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP2(category_group, name, id, \
  559. timestamp, arg1_name, \
  560. arg1_val, arg2_name, arg2_val) \
  561. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  562. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
  563. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  564. arg1_name, arg1_val, arg2_name, arg2_val)
  565. #define TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
  566. timestamp) \
  567. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  568. TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
  569. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
  570. // Records a single ASYNC_STEP_INTO event for |step| immediately. If the
  571. // category is not enabled, then this does nothing. The |name| and |id| must
  572. // match the ASYNC_BEGIN event above. The |step| param identifies this step
  573. // within the async event. This should be called at the beginning of the next
  574. // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
  575. // ASYNC_STEP_PAST events.
  576. #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step) \
  577. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \
  578. category_group, name, id, \
  579. TRACE_EVENT_FLAG_NONE, "step", step)
  580. #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \
  581. arg1_name, arg1_val) \
  582. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  583. TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id, \
  584. TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
  585. // Similar to TRACE_EVENT_ASYNC_STEP_INTOx but with a custom |at| timestamp
  586. // provided.
  587. #define TRACE_EVENT_ASYNC_STEP_INTO_WITH_TIMESTAMP0(category_group, name, id, \
  588. step, timestamp) \
  589. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  590. TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id, \
  591. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  592. "step", step)
  593. // Records a single ASYNC_STEP_PAST event for |step| immediately. If the
  594. // category is not enabled, then this does nothing. The |name| and |id| must
  595. // match the ASYNC_BEGIN event above. The |step| param identifies this step
  596. // within the async event. This should be called at the beginning of the next
  597. // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
  598. // ASYNC_STEP_INTO events.
  599. #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step) \
  600. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \
  601. category_group, name, id, \
  602. TRACE_EVENT_FLAG_NONE, "step", step)
  603. #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \
  604. arg1_name, arg1_val) \
  605. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  606. TRACE_EVENT_PHASE_ASYNC_STEP_PAST, category_group, name, id, \
  607. TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
  608. // Records a single ASYNC_END event for "name" immediately. If the category
  609. // is not enabled, then this does nothing.
  610. #define TRACE_EVENT_ASYNC_END0(category_group, name, id) \
  611. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
  612. category_group, name, id, \
  613. TRACE_EVENT_FLAG_NONE)
  614. #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \
  615. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
  616. category_group, name, id, \
  617. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  618. #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \
  619. arg2_name, arg2_val) \
  620. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  621. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
  622. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  623. #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \
  624. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
  625. category_group, name, id, \
  626. TRACE_EVENT_FLAG_COPY)
  627. #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \
  628. arg1_val) \
  629. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
  630. category_group, name, id, \
  631. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  632. #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \
  633. arg1_val, arg2_name, arg2_val) \
  634. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  635. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
  636. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
  637. // Similar to TRACE_EVENT_ASYNC_ENDx but with a custom |at| timestamp provided.
  638. #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(category_group, name, id, \
  639. timestamp) \
  640. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  641. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
  642. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
  643. #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1(category_group, name, id, \
  644. timestamp, arg1_name, arg1_val) \
  645. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  646. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
  647. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  648. arg1_name, arg1_val)
  649. #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP2(category_group, name, id, \
  650. timestamp, arg1_name, arg1_val, \
  651. arg2_name, arg2_val) \
  652. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  653. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
  654. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  655. arg1_name, arg1_val, arg2_name, arg2_val)
  656. #define TRACE_EVENT_COPY_ASYNC_END_WITH_TIMESTAMP0(category_group, name, id, \
  657. timestamp) \
  658. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  659. TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
  660. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
  661. // NESTABLE_ASYNC_* APIs are used to describe an async operation, which can
  662. // be nested within a NESTABLE_ASYNC event and/or have inner NESTABLE_ASYNC
  663. // events.
  664. // - category and name strings must have application lifetime (statics or
  665. // literals). They may not include " chars.
  666. // - A pair of NESTABLE_ASYNC_BEGIN event and NESTABLE_ASYNC_END event is
  667. // considered as a match if their category_group, name and id all match.
  668. // - |id| must either be a pointer or an integer value up to 64 bits.
  669. // If it's a pointer, the bits will be xored with a hash of the process ID so
  670. // that the same pointer on two different processes will not collide.
  671. // - |id| is used to match a child NESTABLE_ASYNC event with its parent
  672. // NESTABLE_ASYNC event. Therefore, events in the same nested event tree must
  673. // be logged using the same id and category_group.
  674. //
  675. // Unmatched NESTABLE_ASYNC_END event will be parsed as an event that starts
  676. // at the first NESTABLE_ASYNC event of that id, and unmatched
  677. // NESTABLE_ASYNC_BEGIN event will be parsed as an event that ends at the last
  678. // NESTABLE_ASYNC event of that id. Corresponding warning messages for
  679. // unmatched events will be shown in the analysis view.
  680. // Records a single NESTABLE_ASYNC_BEGIN event called "name" immediately, with
  681. // 0, 1 or 2 associated arguments. If the category is not enabled, then this
  682. // does nothing.
  683. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_group, name, id) \
  684. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
  685. category_group, name, id, \
  686. TRACE_EVENT_FLAG_NONE)
  687. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
  688. arg1_val) \
  689. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
  690. category_group, name, id, \
  691. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  692. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
  693. arg1_val, arg2_name, arg2_val) \
  694. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  695. TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
  696. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  697. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_FLAGS0(category_group, name, id, \
  698. flags) \
  699. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
  700. category_group, name, id, flags)
  701. // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 0
  702. // or 2 associated arguments. If the category is not enabled, then this does
  703. // nothing.
  704. #define TRACE_EVENT_NESTABLE_ASYNC_END0(category_group, name, id) \
  705. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
  706. category_group, name, id, \
  707. TRACE_EVENT_FLAG_NONE)
  708. // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 1
  709. // associated argument. If the category is not enabled, then this does nothing.
  710. #define TRACE_EVENT_NESTABLE_ASYNC_END1(category_group, name, id, arg1_name, \
  711. arg1_val) \
  712. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
  713. category_group, name, id, \
  714. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  715. #define TRACE_EVENT_NESTABLE_ASYNC_END2(category_group, name, id, arg1_name, \
  716. arg1_val, arg2_name, arg2_val) \
  717. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  718. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  719. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  720. #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_FLAGS0(category_group, name, id, \
  721. flags) \
  722. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
  723. category_group, name, id, flags)
  724. // Records a single NESTABLE_ASYNC_INSTANT event called "name" immediately,
  725. // with none, one or two associated argument. If the category is not enabled,
  726. // then this does nothing.
  727. #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT0(category_group, name, id) \
  728. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
  729. category_group, name, id, \
  730. TRACE_EVENT_FLAG_NONE)
  731. #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(category_group, name, id, \
  732. arg1_name, arg1_val) \
  733. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
  734. category_group, name, id, \
  735. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  736. #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( \
  737. category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
  738. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  739. TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
  740. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  741. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TTS2( \
  742. category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
  743. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  744. TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
  745. TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
  746. arg2_name, arg2_val)
  747. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TTS2( \
  748. category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
  749. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  750. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  751. TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
  752. arg2_name, arg2_val)
  753. // Similar to TRACE_EVENT_NESTABLE_ASYNC_{BEGIN,END}x but with a custom
  754. // |timestamp| provided.
  755. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, \
  756. id, timestamp) \
  757. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  758. TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
  759. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
  760. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP1( \
  761. category_group, name, id, timestamp, arg1_name, arg1_val) \
  762. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  763. TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
  764. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  765. arg1_name, arg1_val)
  766. #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP_AND_FLAGS0( \
  767. category_group, name, id, timestamp, flags) \
  768. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  769. TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
  770. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, flags)
  771. #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(category_group, name, \
  772. id, timestamp) \
  773. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  774. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  775. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
  776. #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP1( \
  777. category_group, name, id, timestamp, arg1_name, arg1_val) \
  778. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  779. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  780. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  781. arg1_name, arg1_val)
  782. #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP2( \
  783. category_group, name, id, timestamp, arg1_name, arg1_val, arg2_name, \
  784. arg2_val) \
  785. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  786. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  787. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  788. arg1_name, arg1_val, arg2_name, arg2_val)
  789. #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP_AND_FLAGS0( \
  790. category_group, name, id, timestamp, flags) \
  791. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  792. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  793. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, flags)
  794. #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT_WITH_TIMESTAMP0( \
  795. category_group, name, id, timestamp) \
  796. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  797. TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
  798. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
  799. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN0(category_group, name, id) \
  800. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
  801. category_group, name, id, \
  802. TRACE_EVENT_FLAG_COPY)
  803. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END0(category_group, name, id) \
  804. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
  805. category_group, name, id, \
  806. TRACE_EVENT_FLAG_COPY)
  807. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0( \
  808. category_group, name, id, timestamp) \
  809. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  810. TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
  811. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
  812. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0( \
  813. category_group, name, id, timestamp) \
  814. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  815. TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
  816. TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
  817. #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END1(category_group, name, id, \
  818. arg1_name, arg1_val) \
  819. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
  820. category_group, name, id, \
  821. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  822. // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
  823. // associated arguments. If the category is not enabled, then this
  824. // does nothing.
  825. // - category and name strings must have application lifetime (statics or
  826. // literals). They may not include " chars.
  827. // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
  828. // events are considered to match if their category_group, name and id values
  829. // all match. |id| must either be a pointer or an integer value up to 64 bits.
  830. // If it's a pointer, the bits will be xored with a hash of the process ID so
  831. // that the same pointer on two different processes will not collide.
  832. // FLOW events are different from ASYNC events in how they are drawn by the
  833. // tracing UI. A FLOW defines asynchronous data flow, such as posting a task
  834. // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
  835. // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
  836. // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
  837. // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
  838. // macros. When the operation completes, call FLOW_END. An async operation can
  839. // span threads and processes, but all events in that operation must use the
  840. // same |name| and |id|. Each event can have its own args.
  841. #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \
  842. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
  843. category_group, name, id, \
  844. TRACE_EVENT_FLAG_NONE)
  845. #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \
  846. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
  847. category_group, name, id, \
  848. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
  849. #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \
  850. arg2_name, arg2_val) \
  851. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  852. TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id, \
  853. TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
  854. #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \
  855. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
  856. category_group, name, id, \
  857. TRACE_EVENT_FLAG_COPY)
  858. #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \
  859. arg1_val) \
  860. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
  861. category_group, name, id, \
  862. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
  863. #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \
  864. arg1_val, arg2_name, arg2_val) \
  865. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  866. TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id, \
  867. TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
  868. // Records a single FLOW_STEP event for |step| immediately. If the category
  869. // is not enabled, then this does nothing. The |name| and |id| must match the
  870. // FLOW_BEGIN event above. The |step| param identifies this step within the
  871. // async event. This should be called at the beginning of the next phase of an
  872. // asynchronous operation.
  873. #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \
  874. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
  875. category_group, name, id, \
  876. TRACE_EVENT_FLAG_NONE, "step", step)
  877. #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, arg1_name, \
  878. arg1_val) \
  879. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  880. TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id, \
  881. TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
  882. #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \
  883. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
  884. category_group, name, id, \
  885. TRACE_EVENT_FLAG_COPY, "step", step)
  886. #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, arg1_name, \
  887. arg1_val) \
  888. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  889. TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id, \
  890. TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val)
  891. // Records a single FLOW_END event for "name" immediately. If the category
  892. // is not enabled, then this does nothing.
  893. #define TRACE_EVENT_FLOW_END0(category_group, name, id) \
  894. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  895. name, id, TRACE_EVENT_FLAG_NONE)
  896. #define TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0(category_group, name, id) \
  897. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  898. name, id, \
  899. TRACE_EVENT_FLAG_BIND_TO_ENCLOSING)
  900. #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \
  901. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  902. name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
  903. arg1_val)
  904. #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \
  905. arg2_name, arg2_val) \
  906. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  907. name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
  908. arg1_val, arg2_name, arg2_val)
  909. #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \
  910. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  911. name, id, TRACE_EVENT_FLAG_COPY)
  912. #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \
  913. arg1_val) \
  914. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  915. name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
  916. arg1_val)
  917. #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \
  918. arg1_val, arg2_name, arg2_val) \
  919. INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
  920. name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
  921. arg1_val, arg2_name, arg2_val)
  922. // Special trace event macro to trace task execution with the location where it
  923. // was posted from.
  924. #define TRACE_TASK_EXECUTION(run_function, task) \
  925. INTERNAL_TRACE_TASK_EXECUTION(run_function, task)
  926. #define TRACE_LOG_MESSAGE(file, message, line) \
  927. INTERNAL_TRACE_LOG_MESSAGE(file, message, line)
  928. // TRACE_EVENT_METADATA* events are information related to other
  929. // injected events, not events in their own right.
  930. #define TRACE_EVENT_METADATA1(category_group, name, arg1_name, arg1_val) \
  931. INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, arg1_name, arg1_val)
  932. // Records a clock sync event.
  933. #define TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id) \
  934. INTERNAL_TRACE_EVENT_ADD( \
  935. TRACE_EVENT_PHASE_CLOCK_SYNC, "__metadata", "clock_sync", \
  936. TRACE_EVENT_FLAG_NONE, "sync_id", sync_id)
  937. #define TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts) \
  938. INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
  939. TRACE_EVENT_PHASE_CLOCK_SYNC, "__metadata", "clock_sync", \
  940. issue_end_ts, TRACE_EVENT_FLAG_NONE, \
  941. "sync_id", sync_id, "issue_ts", issue_ts)
  942. // Macros to track the life time and value of arbitrary client objects.
  943. // See also TraceTrackableObject.
  944. #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \
  945. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  946. TRACE_EVENT_PHASE_CREATE_OBJECT, category_group, name, id, \
  947. TRACE_EVENT_FLAG_NONE)
  948. #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, \
  949. snapshot) \
  950. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  951. TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name, \
  952. id, TRACE_EVENT_FLAG_NONE, "snapshot", snapshot)
  953. #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID_AND_TIMESTAMP( \
  954. category_group, name, id, timestamp, snapshot) \
  955. INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
  956. TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name, \
  957. id, TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
  958. "snapshot", snapshot)
  959. #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
  960. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  961. TRACE_EVENT_PHASE_DELETE_OBJECT, category_group, name, id, \
  962. TRACE_EVENT_FLAG_NONE)
  963. // Records entering and leaving trace event contexts. |category_group| and
  964. // |name| specify the context category and type. |context| is a
  965. // snapshotted context object id.
  966. #define TRACE_EVENT_ENTER_CONTEXT(category_group, name, context) \
  967. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  968. TRACE_EVENT_PHASE_ENTER_CONTEXT, category_group, name, context, \
  969. TRACE_EVENT_FLAG_NONE)
  970. #define TRACE_EVENT_LEAVE_CONTEXT(category_group, name, context) \
  971. INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
  972. TRACE_EVENT_PHASE_LEAVE_CONTEXT, category_group, name, context, \
  973. TRACE_EVENT_FLAG_NONE)
  974. // Macro to efficiently determine if a given category group is enabled.
  975. #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \
  976. do { \
  977. INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
  978. if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
  979. *ret = true; \
  980. } else { \
  981. *ret = false; \
  982. } \
  983. } while (0)
  984. // Macro to efficiently determine, through polling, if a new trace has begun.
  985. #define TRACE_EVENT_IS_NEW_TRACE(ret) \
  986. do { \
  987. static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \
  988. int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \
  989. if (num_traces_recorded != -1 && \
  990. num_traces_recorded != \
  991. INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \
  992. INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = num_traces_recorded; \
  993. *ret = true; \
  994. } else { \
  995. *ret = false; \
  996. } \
  997. } while (0)
  998. // Macro for getting the real base::TimeTicks::Now() which can be overridden in
  999. // headless when VirtualTime is enabled.
  1000. #define TRACE_TIME_TICKS_NOW() INTERNAL_TRACE_TIME_TICKS_NOW()
  1001. // Macro for getting the real base::Time::Now() which can be overridden in
  1002. // headless when VirtualTime is enabled.
  1003. #define TRACE_TIME_NOW() INTERNAL_TRACE_TIME_NOW()
  1004. // Notes regarding the following definitions:
  1005. // New values can be added and propagated to third party libraries, but existing
  1006. // definitions must never be changed, because third party libraries may use old
  1007. // definitions.
  1008. // Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
  1009. #define TRACE_EVENT_PHASE_BEGIN ('B')
  1010. #define TRACE_EVENT_PHASE_END ('E')
  1011. #define TRACE_EVENT_PHASE_COMPLETE ('X')
  1012. #define TRACE_EVENT_PHASE_INSTANT ('I')
  1013. #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
  1014. #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T')
  1015. #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p')
  1016. #define TRACE_EVENT_PHASE_ASYNC_END ('F')
  1017. #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN ('b')
  1018. #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_END ('e')
  1019. #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT ('n')
  1020. #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s')
  1021. #define TRACE_EVENT_PHASE_FLOW_STEP ('t')
  1022. #define TRACE_EVENT_PHASE_FLOW_END ('f')
  1023. #define TRACE_EVENT_PHASE_METADATA ('M')
  1024. #define TRACE_EVENT_PHASE_COUNTER ('C')
  1025. #define TRACE_EVENT_PHASE_SAMPLE ('P')
  1026. #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N')
  1027. #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O')
  1028. #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D')
  1029. #define TRACE_EVENT_PHASE_MEMORY_DUMP ('v')
  1030. #define TRACE_EVENT_PHASE_MARK ('R')
  1031. #define TRACE_EVENT_PHASE_CLOCK_SYNC ('c')
  1032. #define TRACE_EVENT_PHASE_ENTER_CONTEXT ('(')
  1033. #define TRACE_EVENT_PHASE_LEAVE_CONTEXT (')')
  1034. // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
  1035. #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0))
  1036. #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0))
  1037. #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1))
  1038. #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 2))
  1039. #define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 3))
  1040. #define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 4))
  1041. #define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 5))
  1042. #define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 6))
  1043. #define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 7))
  1044. #define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 8))
  1045. #define TRACE_EVENT_FLAG_HAS_CONTEXT_ID (static_cast<unsigned int>(1 << 9))
  1046. #define TRACE_EVENT_FLAG_HAS_PROCESS_ID (static_cast<unsigned int>(1 << 10))
  1047. #define TRACE_EVENT_FLAG_HAS_LOCAL_ID (static_cast<unsigned int>(1 << 11))
  1048. #define TRACE_EVENT_FLAG_HAS_GLOBAL_ID (static_cast<unsigned int>(1 << 12))
  1049. // TODO(eseckler): Remove once we have native support for typed proto events in
  1050. // TRACE_EVENT macros.
  1051. #define TRACE_EVENT_FLAG_TYPED_PROTO_ARGS (static_cast<unsigned int>(1 << 15))
  1052. #define TRACE_EVENT_FLAG_JAVA_STRING_LITERALS \
  1053. (static_cast<unsigned int>(1 << 16))
  1054. #define TRACE_EVENT_FLAG_SCOPE_MASK \
  1055. (static_cast<unsigned int>(TRACE_EVENT_FLAG_SCOPE_OFFSET | \
  1056. TRACE_EVENT_FLAG_SCOPE_EXTRA))
  1057. // Type values for identifying types in the TraceValue union.
  1058. #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
  1059. #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
  1060. #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
  1061. #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
  1062. #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
  1063. #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
  1064. #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
  1065. #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8))
  1066. // Enum reflecting the scope of an INSTANT event. Must fit within
  1067. // TRACE_EVENT_FLAG_SCOPE_MASK.
  1068. #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 2))
  1069. #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 2))
  1070. #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 2))
  1071. #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
  1072. #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
  1073. #define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
  1074. #endif // BASE_TRACE_EVENT_COMMON_TRACE_EVENT_COMMON_H_