21
21
::fml::tracing::TraceCounterNopHACK ((a), (b), (c), (arg1), __VA_ARGS__);
22
22
23
23
#define FML_TRACE_EVENT (a, b, args... ) TRACE_DURATION(a, b)
24
+ // On Fuchsia, the flow_id arguments to this macro are ignored.
25
+ #define FML_TRACE_EVENT_WITH_FLOW_IDS (category_group, name, flow_id_count, \
26
+ flow_ids, ...) \
27
+ FML_TRACE_EVENT (category_group, name)
24
28
25
29
#define TRACE_EVENT0 (a, b ) TRACE_DURATION(a, b)
30
+ // On Fuchsia, the flow_id arguments to this macro are ignored.
31
+ #define TRACE_EVENT0_WITH_FLOW_IDS (category_group, name, flow_id_count, \
32
+ flow_ids) \
33
+ TRACE_EVENT0 (category_group, name)
26
34
#define TRACE_EVENT1 (a, b, c, d ) TRACE_DURATION(a, b, c, d)
35
+ // On Fuchsia, the flow_id arguments to this macro are ignored.
36
+ #define TRACE_EVENT1_WITH_FLOW_IDS (category_group, name, flow_id_count, \
37
+ flow_ids, arg1_name, arg1_val) \
38
+ TRACE_EVENT1 (category_group, name, arg1_name, arg1_val)
27
39
#define TRACE_EVENT2 (a, b, c, d, e, f ) TRACE_DURATION(a, b, c, d, e, f)
28
40
#define TRACE_EVENT_ASYNC_BEGIN0 (a, b, c ) TRACE_ASYNC_BEGIN(a, b, c)
41
+ // On Fuchsia, the flow_id arguments to this macro are ignored.
42
+ #define TRACE_EVENT_ASYNC_BEGIN0_WITH_FLOW_IDS (category_group, name, id, \
43
+ flow_id_count, flow_ids) \
44
+ TRACE_EVENT_ASYNC_BEGIN0 (category_group, name, id)
29
45
#define TRACE_EVENT_ASYNC_END0 (a, b, c ) TRACE_ASYNC_END(a, b, c)
30
46
#define TRACE_EVENT_ASYNC_BEGIN1 (a, b, c, d, e ) TRACE_ASYNC_BEGIN(a, b, c, d, e)
31
47
#define TRACE_EVENT_ASYNC_END1 (a, b, c, d, e ) TRACE_ASYNC_END(a, b, c, d, e)
83
99
// ```
84
100
//
85
101
// Instead, either use different `name` or `arg1` parameter names.
86
- #define FML_TRACE_EVENT (category_group, name, ...) \
87
- ::fml::tracing::TraceEvent ((category_group), (name), __VA_ARGS__); \
102
+ #define FML_TRACE_EVENT_WITH_FLOW_IDS (category_group, name, flow_id_count, \
103
+ flow_ids, ...) \
104
+ ::fml::tracing::TraceEvent ((category_group), (name), (flow_id_count), \
105
+ (flow_ids), __VA_ARGS__); \
88
106
__FML__AUTO_TRACE_END (name)
89
107
90
- #define TRACE_EVENT0 (category_group, name ) \
91
- ::fml::tracing::TraceEvent0 (category_group, name); \
108
+ // Avoid using the same `name` and `argX_name` for nested traces, which can
109
+ // lead to double free errors. E.g. the following code should be avoided:
110
+ //
111
+ // ```cpp
112
+ // {
113
+ // TRACE_EVENT1("flutter", "Foo::Bar", "count", "initial_count_value");
114
+ // ...
115
+ // TRACE_EVENT_INSTANT1("flutter", "Foo::Bar",
116
+ // "count", "updated_count_value");
117
+ // }
118
+ // ```
119
+ //
120
+ // Instead, either use different `name` or `arg1` parameter names.
121
+ #define FML_TRACE_EVENT (category_group, name, ...) \
122
+ FML_TRACE_EVENT_WITH_FLOW_IDS ((category_group), (name), \
123
+ /* flow_id_count=*/ (0 ), /* flow_ids=*/ (nullptr ), \
124
+ __VA_ARGS__)
125
+
126
+ #define TRACE_EVENT0_WITH_FLOW_IDS (category_group, name, flow_id_count, \
127
+ flow_ids) \
128
+ ::fml::tracing::TraceEvent0 (category_group, name, flow_id_count, flow_ids); \
92
129
__FML__AUTO_TRACE_END (name)
93
130
94
- #define TRACE_EVENT1 (category_group, name, arg1_name, arg1_val ) \
95
- ::fml::tracing::TraceEvent1 (category_group, name, arg1_name, arg1_val); \
131
+ #define TRACE_EVENT0 (category_group, name ) \
132
+ TRACE_EVENT0_WITH_FLOW_IDS (category_group, name, /* flow_id_count=*/ 0 , \
133
+ /* flow_ids=*/ nullptr )
134
+
135
+ #define TRACE_EVENT1_WITH_FLOW_IDS (category_group, name, flow_id_count, \
136
+ flow_ids, arg1_name, arg1_val) \
137
+ ::fml::tracing::TraceEvent1 (category_group, name, flow_id_count, flow_ids, \
138
+ arg1_name, arg1_val); \
96
139
__FML__AUTO_TRACE_END (name)
97
140
141
+ #define TRACE_EVENT1 (category_group, name, arg1_name, arg1_val ) \
142
+ TRACE_EVENT1_WITH_FLOW_IDS (category_group, name, /* flow_id_count=*/ 0 , \
143
+ /* flow_ids=*/ nullptr , arg1_name, arg1_val)
144
+
98
145
#define TRACE_EVENT2 (category_group, name, arg1_name, arg1_val, arg2_name, \
99
146
arg2_val) \
100
- ::fml::tracing::TraceEvent2 (category_group, name, arg1_name, arg1_val, \
147
+ ::fml::tracing::TraceEvent2 (category_group, name, /* flow_id_count=*/ 0 , \
148
+ /* flow_ids=*/ nullptr , arg1_name, arg1_val, \
101
149
arg2_name, arg2_val); \
102
150
__FML__AUTO_TRACE_END (name)
103
151
152
+ #define TRACE_EVENT_ASYNC_BEGIN0_WITH_FLOW_IDS (category_group, name, id, \
153
+ flow_id_count, flow_ids) \
154
+ ::fml::tracing::TraceEventAsyncBegin0 (category_group, name, id, \
155
+ flow_id_count, flow_ids);
156
+
104
157
#define TRACE_EVENT_ASYNC_BEGIN0 (category_group, name, id ) \
105
- ::fml::tracing::TraceEventAsyncBegin0 (category_group, name, id);
158
+ TRACE_EVENT_ASYNC_BEGIN0_WITH_FLOW_IDS ( \
159
+ category_group, name, id, /* flow_id_count=*/ 0 , /* flow_ids=*/ nullptr )
106
160
107
161
#define TRACE_EVENT_ASYNC_END0 (category_group, name, id ) \
108
162
::fml::tracing::TraceEventAsyncEnd0 (category_group, name, id);
109
163
110
- #define TRACE_EVENT_ASYNC_BEGIN1 (category_group, name, id, arg1_name, \
111
- arg1_val) \
112
- ::fml::tracing::TraceEventAsyncBegin1 (category_group, name, id, arg1_name, \
113
- arg1_val);
164
+ #define TRACE_EVENT_ASYNC_BEGIN1 (category_group, name, id, arg1_name, \
165
+ arg1_val) \
166
+ ::fml::tracing::TraceEventAsyncBegin1 ( \
167
+ category_group, name, id, /* flow_id_count=*/ 0 , /* flow_ids=*/ nullptr , \
168
+ arg1_name, arg1_val);
114
169
115
170
#define TRACE_EVENT_ASYNC_END1 (category_group, name, id, arg1_name, arg1_val ) \
116
- ::fml::tracing::TraceEventAsyncEnd1 (category_group, name, id, arg1_name, \
117
- arg1_val);
171
+ ::fml::tracing::TraceEventAsyncEnd1 ( \
172
+ category_group, name, id, /* flow_id_count=*/ 0 , /* flow_ids=*/ nullptr , \
173
+ arg1_name, arg1_val);
118
174
119
175
#define TRACE_EVENT_INSTANT0 (category_group, name ) \
120
- ::fml::tracing::TraceEventInstant0 (category_group, name);
176
+ ::fml::tracing::TraceEventInstant0 ( \
177
+ category_group, name, /* flow_id_count=*/ 0 , /* flow_ids=*/ nullptr );
121
178
122
179
#define TRACE_EVENT_INSTANT1 (category_group, name, arg1_name, arg1_val ) \
123
- ::fml::tracing::TraceEventInstant1 (category_group, name, arg1_name, arg1_val);
180
+ ::fml::tracing::TraceEventInstant1 ( \
181
+ category_group, name, /* flow_id_count=*/ 0 , /* flow_ids=*/ nullptr , \
182
+ arg1_name, arg1_val);
124
183
125
184
#define TRACE_EVENT_INSTANT2 (category_group, name, arg1_name, arg1_val, \
126
185
arg2_name, arg2_val) \
127
- ::fml::tracing::TraceEventInstant2 (category_group, name, arg1_name, \
128
- arg1_val, arg2_name, arg2_val);
186
+ ::fml::tracing::TraceEventInstant2 ( \
187
+ category_group, name, /* flow_id_count=*/ 0 , /* flow_ids=*/ nullptr , \
188
+ arg1_name, arg1_val, arg2_name, arg2_val);
129
189
130
190
#define TRACE_FLOW_BEGIN (category, name, id ) \
131
191
::fml::tracing::TraceEventFlowBegin0 (category, name, id);
@@ -157,6 +217,8 @@ void TraceSetAllowlist(const std::vector<std::string>& allowlist);
157
217
typedef void (*TimelineEventHandler)(const char *,
158
218
int64_t ,
159
219
int64_t ,
220
+ intptr_t ,
221
+ const int64_t *,
160
222
Dart_Timeline_Event_Type,
161
223
intptr_t ,
162
224
const char **,
@@ -176,13 +238,17 @@ void TraceTimelineEvent(TraceArg category_group,
176
238
TraceArg name,
177
239
int64_t timestamp_micros,
178
240
TraceIDArg id,
241
+ size_t flow_id_count,
242
+ const uint64_t * flow_ids,
179
243
Dart_Timeline_Event_Type type,
180
244
const std::vector<const char *>& names,
181
245
const std::vector<std::string>& values);
182
246
183
247
void TraceTimelineEvent (TraceArg category_group,
184
248
TraceArg name,
185
249
TraceIDArg id,
250
+ size_t flow_id_count,
251
+ const uint64_t * flow_ids,
186
252
Dart_Timeline_Event_Type type,
187
253
const std::vector<const char *>& names,
188
254
const std::vector<std::string>& values);
@@ -241,7 +307,8 @@ void TraceCounter(TraceArg category,
241
307
Args... args) {
242
308
#if FLUTTER_TIMELINE_ENABLED
243
309
auto split = SplitArguments (args...);
244
- TraceTimelineEvent (category, name, identifier, Dart_Timeline_Event_Counter,
310
+ TraceTimelineEvent (category, name, identifier, /* flow_id_count=*/ 0 ,
311
+ /* flow_ids=*/ nullptr , Dart_Timeline_Event_Counter,
245
312
split.first , split.second );
246
313
#endif // FLUTTER_TIMELINE_ENABLED
247
314
}
@@ -255,23 +322,34 @@ void TraceCounterNopHACK(TraceArg category,
255
322
Args... args) {}
256
323
257
324
template <typename ... Args>
258
- void TraceEvent (TraceArg category, TraceArg name, Args... args) {
325
+ void TraceEvent (TraceArg category,
326
+ TraceArg name,
327
+ size_t flow_id_count,
328
+ const uint64_t * flow_ids,
329
+ Args... args) {
259
330
#if FLUTTER_TIMELINE_ENABLED
260
331
auto split = SplitArguments (args...);
261
- TraceTimelineEvent (category, name, 0 , Dart_Timeline_Event_Begin, split. first ,
262
- split.second );
332
+ TraceTimelineEvent (category, name, 0 , flow_id_count, flow_ids ,
333
+ Dart_Timeline_Event_Begin, split. first , split.second );
263
334
#endif // FLUTTER_TIMELINE_ENABLED
264
335
}
265
336
266
- void TraceEvent0 (TraceArg category_group, TraceArg name);
337
+ void TraceEvent0 (TraceArg category_group,
338
+ TraceArg name,
339
+ size_t flow_id_count,
340
+ const uint64_t * flow_ids);
267
341
268
342
void TraceEvent1 (TraceArg category_group,
269
343
TraceArg name,
344
+ size_t flow_id_count,
345
+ const uint64_t * flow_ids,
270
346
TraceArg arg1_name,
271
347
TraceArg arg1_val);
272
348
273
349
void TraceEvent2 (TraceArg category_group,
274
350
TraceArg name,
351
+ size_t flow_id_count,
352
+ const uint64_t * flow_ids,
275
353
TraceArg arg1_name,
276
354
TraceArg arg1_val,
277
355
TraceArg arg2_name,
@@ -300,6 +378,8 @@ void TraceEventAsyncComplete(TraceArg category_group,
300
378
name, // name
301
379
begin_micros, // timestamp_micros
302
380
identifier, // identifier
381
+ 0 , // flow_id_count
382
+ nullptr , // flow_ids
303
383
Dart_Timeline_Event_Async_Begin, // type
304
384
split.first , // names
305
385
split.second // values
@@ -309,6 +389,8 @@ void TraceEventAsyncComplete(TraceArg category_group,
309
389
name, // name
310
390
end_micros, // timestamp_micros
311
391
identifier, // identifier
392
+ 0 , // flow_id_count
393
+ nullptr , // flow_ids
312
394
Dart_Timeline_Event_Async_End, // type
313
395
split.first , // names
314
396
split.second // values
@@ -318,13 +400,17 @@ void TraceEventAsyncComplete(TraceArg category_group,
318
400
319
401
void TraceEventAsyncBegin0 (TraceArg category_group,
320
402
TraceArg name,
321
- TraceIDArg id);
403
+ TraceIDArg id,
404
+ size_t flow_id_count,
405
+ const uint64_t * flow_ids);
322
406
323
407
void TraceEventAsyncEnd0 (TraceArg category_group, TraceArg name, TraceIDArg id);
324
408
325
409
void TraceEventAsyncBegin1 (TraceArg category_group,
326
410
TraceArg name,
327
411
TraceIDArg id,
412
+ size_t flow_id_count,
413
+ const uint64_t * flow_ids,
328
414
TraceArg arg1_name,
329
415
TraceArg arg1_val);
330
416
@@ -334,15 +420,22 @@ void TraceEventAsyncEnd1(TraceArg category_group,
334
420
TraceArg arg1_name,
335
421
TraceArg arg1_val);
336
422
337
- void TraceEventInstant0 (TraceArg category_group, TraceArg name);
423
+ void TraceEventInstant0 (TraceArg category_group,
424
+ TraceArg name,
425
+ size_t flow_id_count,
426
+ const uint64_t * flow_ids);
338
427
339
428
void TraceEventInstant1 (TraceArg category_group,
340
429
TraceArg name,
430
+ size_t flow_id_count,
431
+ const uint64_t * flow_ids,
341
432
TraceArg arg1_name,
342
433
TraceArg arg1_val);
343
434
344
435
void TraceEventInstant2 (TraceArg category_group,
345
436
TraceArg name,
437
+ size_t flow_id_count,
438
+ const uint64_t * flow_ids,
346
439
TraceArg arg1_name,
347
440
TraceArg arg1_val,
348
441
TraceArg arg2_name,
@@ -376,7 +469,10 @@ class ScopedInstantEnd {
376
469
class TraceFlow {
377
470
public:
378
471
explicit TraceFlow (const char * label) : label_(label), nonce_(TraceNonce()) {
472
+ TraceEvent0 (" flutter" , label_, /* flow_id_count=*/ 1 ,
473
+ /* flow_ids=*/ &nonce_);
379
474
TraceEventFlowBegin0 (" flutter" , label_, nonce_);
475
+ TraceEventEnd (label_);
380
476
}
381
477
382
478
~TraceFlow () { End (label_); }
@@ -386,19 +482,25 @@ class TraceFlow {
386
482
}
387
483
388
484
void Step (const char * label = nullptr ) const {
485
+ TraceEvent0 (" flutter" , label ? label : label_, /* flow_id_count=*/ 1 ,
486
+ /* flow_ids=*/ &nonce_);
389
487
TraceEventFlowStep0 (" flutter" , label ? label : label_, nonce_);
488
+ TraceEventEnd (label ? label : label_);
390
489
}
391
490
392
491
void End (const char * label = nullptr ) {
393
492
if (nonce_ != 0 ) {
493
+ TraceEvent0 (" flutter" , label ? label : label_, /* flow_id_count=*/ 1 ,
494
+ /* flow_ids=*/ &nonce_);
394
495
TraceEventFlowEnd0 (" flutter" , label ? label : label_, nonce_);
496
+ TraceEventEnd (label ? label : label_);
395
497
nonce_ = 0 ;
396
498
}
397
499
}
398
500
399
501
private:
400
502
const char * label_;
401
- size_t nonce_;
503
+ uint64_t nonce_;
402
504
403
505
FML_DISALLOW_COPY_AND_ASSIGN (TraceFlow);
404
506
};
0 commit comments