Flutter Engine
flutter::FlutterEventTracer Class Reference
Inheritance diagram for flutter::FlutterEventTracer:

Public Member Functions

 FlutterEventTracer (bool enabled, const std::optional< std::vector< std::string >> &allowlist)
 
SkEventTracer::Handle addTraceEvent (char phase, const uint8_t *category_enabled_flag, const char *name, uint64_t id, int num_args, const char **p_arg_names, const uint8_t *p_arg_types, const uint64_t *p_arg_values, uint8_t flags) override
 
void updateTraceEventDuration (const uint8_t *category_enabled_flag, const char *name, SkEventTracer::Handle handle) override
 
const uint8_t * getCategoryGroupEnabled (const char *name) override
 
const char * getCategoryGroupName (const uint8_t *category_enabled_flag) override
 

Static Public Attributes

static constexpr const char * kSkiaTag = "skia"
 
static constexpr uint8_t kYes = 1
 
static constexpr uint8_t kNo = 0
 

Detailed Description

Definition at line 76 of file skia_event_tracer_impl.cc.

Constructor & Destructor Documentation

◆ FlutterEventTracer()

flutter::FlutterEventTracer::FlutterEventTracer ( bool  enabled,
const std::optional< std::vector< std::string >> &  allowlist 
)
inline

Definition at line 82 of file skia_event_tracer_impl.cc.

Referenced by flutter::InitSkiaEventTracer().

84  : enabled_(enabled ? kYes : kNo), shaders_category_flag_(nullptr) {
85  if (allowlist.has_value()) {
86  allowlist_.emplace();
87  for (const std::string& category : *allowlist) {
88  allowlist_->insert(std::string(kTraceCategoryPrefix) + category);
89  }
90  }
91  };
static constexpr uint8_t kNo
static constexpr uint8_t kYes

Member Function Documentation

◆ addTraceEvent()

SkEventTracer::Handle flutter::FlutterEventTracer::addTraceEvent ( char  phase,
const uint8_t *  category_enabled_flag,
const char *  name,
uint64_t  id,
int  num_args,
const char **  p_arg_names,
const uint8_t *  p_arg_types,
const uint64_t *  p_arg_values,
uint8_t  flags 
)
inlineoverride

Definition at line 93 of file skia_event_tracer_impl.cc.

References FML_DCHECK, fml::tracing::TraceEvent0(), fml::tracing::TraceEvent1(), fml::tracing::TraceEventAsyncBegin0(), fml::tracing::TraceEventAsyncBegin1(), fml::tracing::TraceEventAsyncEnd0(), fml::tracing::TraceEventAsyncEnd1(), fml::tracing::TraceEventEnd(), fml::tracing::TraceEventInstant0(), and fml::tracing::TraceEventInstant1().

101  {
102 #if defined(OS_FUCHSIA)
103  static trace_site_t trace_site;
104  trace_string_ref_t category_ref;
105  trace_context_t* trace_context = trace_acquire_context_for_category_cached(
106  kSkiaTag, &trace_site, &category_ref);
107 
108  if (likely(!trace_context)) {
109  return 0;
110  }
111 
112  trace_ticks_t ticks = zx_ticks_get();
113 
114  trace_thread_ref_t thread_ref;
115  trace_context_register_current_thread(trace_context, &thread_ref);
116  trace_string_ref_t name_ref;
117  trace_context_register_string_literal(trace_context, name, &name_ref);
118 
119  constexpr int kMaxArgs = 2;
120  trace_arg_t trace_args[kMaxArgs] = {};
121  FML_DCHECK(num_args >= 0);
122  int num_trace_args = std::min(kMaxArgs, num_args);
123 
124  for (int i = 0; i < num_trace_args; i++) {
125  const char* arg_name = p_arg_names[i];
126  const uint8_t arg_type = p_arg_types[i];
127  const uint64_t arg_value = p_arg_values[i];
128 
129  trace_string_ref_t arg_name_string_ref =
130  trace_context_make_registered_string_literal(trace_context, arg_name);
131 
132  trace_arg_value_t trace_arg_value;
133  switch (arg_type) {
134  case TRACE_VALUE_TYPE_BOOL: {
135  trace_arg_value = trace_make_bool_arg_value(!!arg_value);
136  break;
137  }
138  case TRACE_VALUE_TYPE_UINT:
139  trace_arg_value = trace_make_uint64_arg_value(arg_value);
140  break;
141  case TRACE_VALUE_TYPE_INT:
142  trace_arg_value =
143  trace_make_int64_arg_value(BitCast<int64_t>(arg_value));
144  break;
145  case TRACE_VALUE_TYPE_DOUBLE:
146  trace_arg_value =
147  trace_make_double_arg_value(BitCast<double>(arg_value));
148  break;
149  case TRACE_VALUE_TYPE_POINTER:
150  trace_arg_value =
151  trace_make_pointer_arg_value(BitCast<uintptr_t>(arg_value));
152  break;
153  case TRACE_VALUE_TYPE_STRING: {
154  trace_string_ref_t arg_value_string_ref =
155  trace_context_make_registered_string_literal(
156  trace_context, reinterpret_cast<const char*>(arg_value));
157  trace_arg_value = trace_make_string_arg_value(arg_value_string_ref);
158  break;
159  }
160  case TRACE_VALUE_TYPE_COPY_STRING: {
161  const char* arg_value_as_cstring =
162  reinterpret_cast<const char*>(arg_value);
163  trace_string_ref_t arg_value_string_ref =
164  trace_context_make_registered_string_copy(
165  trace_context, arg_value_as_cstring,
166  strlen(arg_value_as_cstring));
167  trace_arg_value = trace_make_string_arg_value(arg_value_string_ref);
168  break;
169  }
170  case TRACE_VALUE_TYPE_CONVERTABLE:
171  trace_arg_value = trace_make_null_arg_value();
172  break;
173  default:
174  trace_arg_value = trace_make_null_arg_value();
175  }
176 
177  trace_args[i] = trace_make_arg(arg_name_string_ref, trace_arg_value);
178  }
179 
180  switch (phase) {
181  case TRACE_EVENT_PHASE_BEGIN:
182  case TRACE_EVENT_PHASE_COMPLETE:
183  trace_context_write_duration_begin_event_record(
184  trace_context, ticks, &thread_ref, &category_ref, &name_ref,
185  trace_args, num_trace_args);
186  break;
187  case TRACE_EVENT_PHASE_END:
188  trace_context_write_duration_end_event_record(
189  trace_context, ticks, &thread_ref, &category_ref, &name_ref,
190  trace_args, num_trace_args);
191  break;
192  case TRACE_EVENT_PHASE_INSTANT:
193  trace_context_write_instant_event_record(
194  trace_context, ticks, &thread_ref, &category_ref, &name_ref,
195  TRACE_SCOPE_THREAD, trace_args, num_trace_args);
196  break;
197  case TRACE_EVENT_PHASE_ASYNC_BEGIN:
198  trace_context_write_async_begin_event_record(
199  trace_context, ticks, &thread_ref, &category_ref, &name_ref, id,
200  trace_args, num_trace_args);
201  break;
202  case TRACE_EVENT_PHASE_ASYNC_END:
203  trace_context_write_async_end_event_record(
204  trace_context, ticks, &thread_ref, &category_ref, &name_ref, id,
205  trace_args, num_trace_args);
206  break;
207  default:
208  break;
209  }
210 
211  trace_release_context(trace_context);
212 
213 #else // defined(OS_FUCHSIA)
214  const char* devtoolsTag = nullptr;
215  if (shaders_category_flag_ &&
216  category_enabled_flag == shaders_category_flag_) {
217  devtoolsTag = kShadersDevtoolsTag;
218  }
219  switch (phase) {
220  case TRACE_EVENT_PHASE_BEGIN:
221  case TRACE_EVENT_PHASE_COMPLETE:
222  if (devtoolsTag) {
223  fml::tracing::TraceEvent1(kSkiaTag, name, kDevtoolsTagArg,
224  devtoolsTag);
225  } else {
227  }
228  break;
229  case TRACE_EVENT_PHASE_END:
231  break;
232  case TRACE_EVENT_PHASE_INSTANT:
233  if (devtoolsTag) {
235  devtoolsTag);
236  } else {
238  }
239  break;
240  case TRACE_EVENT_PHASE_ASYNC_BEGIN:
241  if (devtoolsTag) {
243  kDevtoolsTagArg, devtoolsTag);
244  } else {
246  }
247  break;
248  case TRACE_EVENT_PHASE_ASYNC_END:
249  if (devtoolsTag) {
250  fml::tracing::TraceEventAsyncEnd1(kSkiaTag, name, id, kDevtoolsTagArg,
251  devtoolsTag);
252  } else {
254  }
255  break;
256  default:
257  break;
258  }
259 #endif // defined(OS_FUCHSIA)
260  return 0;
261  }
void TraceEventInstant1(TraceArg category_group, TraceArg name, TraceArg arg1_name, TraceArg arg1_val)
Definition: trace_event.cc:360
void TraceEventAsyncEnd0(TraceArg category_group, TraceArg name, TraceIDArg id)
Definition: trace_event.cc:342
#define FML_DCHECK(condition)
Definition: logging.h:86
void TraceEventEnd(TraceArg name)
Definition: trace_event.cc:331
void TraceEvent1(TraceArg category_group, TraceArg name, TraceArg arg1_name, TraceArg arg1_val)
Definition: trace_event.cc:319
void TraceEventInstant0(TraceArg category_group, TraceArg name)
Definition: trace_event.cc:358
void TraceEventAsyncEnd1(TraceArg category_group, TraceArg name, TraceIDArg id, TraceArg arg1_name, TraceArg arg1_val)
Definition: trace_event.cc:352
void TraceEventAsyncBegin0(TraceArg category_group, TraceArg name, TraceIDArg id)
Definition: trace_event.cc:338
const char * name
Definition: fuchsia.cc:50
static constexpr const char * kSkiaTag
void TraceEvent0(TraceArg category_group, TraceArg name)
Definition: trace_event.cc:317
void TraceEventAsyncBegin1(TraceArg category_group, TraceArg name, TraceIDArg id, TraceArg arg1_name, TraceArg arg1_val)
Definition: trace_event.cc:346

◆ getCategoryGroupEnabled()

const uint8_t* flutter::FlutterEventTracer::getCategoryGroupEnabled ( const char *  name)
inlineoverride

Definition at line 275 of file skia_event_tracer_impl.cc.

References flag.

275  {
276  // Skia will only use long-lived string literals as event names.
277  auto flag_it = category_flag_map_.find(name);
278  if (flag_it == category_flag_map_.end()) {
279  bool allowed;
280  if (enabled_) {
281  allowed = !allowlist_.has_value() ||
282  allowlist_->find(name) != allowlist_->end();
283  } else {
284  allowed = false;
285  }
286  flag_it = category_flag_map_.insert(std::make_pair(name, allowed)).first;
287  const uint8_t* flag = &flag_it->second;
288  reverse_flag_map_.insert(std::make_pair(flag, name));
289  if (kShaderCategoryName == name) {
290  shaders_category_flag_ = flag;
291  }
292  }
293  return &flag_it->second;
294  }
FlutterSemanticsFlag flag
const char * name
Definition: fuchsia.cc:50

◆ getCategoryGroupName()

const char* flutter::FlutterEventTracer::getCategoryGroupName ( const uint8_t *  category_enabled_flag)
inlineoverride

Definition at line 296 of file skia_event_tracer_impl.cc.

References kSkiaTag.

297  {
298  auto reverse_it = reverse_flag_map_.find(category_enabled_flag);
299  if (reverse_it != reverse_flag_map_.end()) {
300  return reverse_it->second;
301  } else {
302  return kSkiaTag;
303  }
304  }
static constexpr const char * kSkiaTag

◆ updateTraceEventDuration()

void flutter::FlutterEventTracer::updateTraceEventDuration ( const uint8_t *  category_enabled_flag,
const char *  name,
SkEventTracer::Handle  handle 
)
inlineoverride

Definition at line 263 of file skia_event_tracer_impl.cc.

References fml::tracing::TraceEventEnd().

265  {
266  // This is only ever called from a scoped trace event so we will just end
267  // the section.
268 #if defined(OS_FUCHSIA)
269  TRACE_DURATION_END(kSkiaTag, name);
270 #else
272 #endif
273  }
void TraceEventEnd(TraceArg name)
Definition: trace_event.cc:331
const char * name
Definition: fuchsia.cc:50
static constexpr const char * kSkiaTag

Member Data Documentation

◆ kNo

constexpr uint8_t flutter::FlutterEventTracer::kNo = 0
static

Definition at line 80 of file skia_event_tracer_impl.cc.

◆ kSkiaTag

constexpr const char* flutter::FlutterEventTracer::kSkiaTag = "skia"
static

Definition at line 78 of file skia_event_tracer_impl.cc.

Referenced by getCategoryGroupName().

◆ kYes

constexpr uint8_t flutter::FlutterEventTracer::kYes = 1
static

Definition at line 79 of file skia_event_tracer_impl.cc.


The documentation for this class was generated from the following file: