6#if defined(DART_HOST_OS_FUCHSIA) && defined(SUPPORT_TIMELINE)
7#include <lib/trace-engine/context.h>
8#include <lib/trace-engine/instrumentation.h>
9#include <zircon/syscalls.h>
17void TimelineEventFuchsiaRecorder::OnEvent(TimelineEvent*
event) {
18 if (
event ==
nullptr) {
21 TimelineStream*
stream =
event->stream_;
22 trace_string_ref_t category;
23 trace_context_t* context = trace_acquire_context_for_category_cached(
24 stream->fuchsia_name(),
stream->trace_site(), &category);
25 if (context ==
nullptr) {
29 trace_string_ref_t
name;
30 if (
event->owns_label()) {
33 name = trace_context_make_registered_string_copy(context,
event->label(),
34 strlen(
event->label()));
39 trace_context_make_registered_string_literal(context,
event->label());
42 trace_thread_ref_t thread;
43 trace_context_register_current_thread(context, &thread);
45 trace_arg_t
args[TRACE_MAX_ARGS];
47 event->arguments_length(),
static_cast<intptr_t
>(TRACE_MAX_ARGS));
49 for (intptr_t
i = 0;
i < num_args;
i++) {
50 const char*
name =
event->arguments()[
i].name;
51 const char*
value =
event->arguments()[
i].value;
52 trace_string_ref_t arg_name =
53 trace_context_make_registered_string_literal(context,
name);
54 trace_string_ref_t arg_value =
55 trace_make_inline_string_ref(
value, strlen(
value));
56 args[
i] = trace_make_arg(arg_name, trace_make_string_arg_value(arg_value));
60 const uint64_t start_time =
event->LowTime() * time_scale;
61 const uint64_t end_time =
event->HighTime() * time_scale;
66 switch (
event->event_type()) {
67 case TimelineEvent::kBegin:
68 trace_context_write_duration_begin_event_record(
69 context, start_time, &thread, &category, &
name,
args, num_args);
71 case TimelineEvent::kEnd:
72 trace_context_write_duration_end_event_record(
73 context, start_time, &thread, &category, &
name,
args, num_args);
75 case TimelineEvent::kInstant:
76 trace_context_write_instant_event_record(
77 context, start_time, &thread, &category, &
name, TRACE_SCOPE_THREAD,
80 case TimelineEvent::kAsyncBegin:
81 trace_context_write_async_begin_event_record(context, start_time, &thread,
85 case TimelineEvent::kAsyncEnd:
86 trace_context_write_async_end_event_record(context, end_time, &thread,
90 case TimelineEvent::kAsyncInstant:
91 trace_context_write_async_instant_event_record(
92 context, start_time, &thread, &category, &
name,
event->Id(),
args,
95 case TimelineEvent::kDuration:
96 trace_context_write_duration_event_record(context, start_time, end_time,
100 case TimelineEvent::kFlowBegin:
101 trace_context_write_flow_begin_event_record(context, start_time, &thread,
105 case TimelineEvent::kFlowStep:
106 trace_context_write_flow_step_event_record(context, start_time, &thread,
110 case TimelineEvent::kFlowEnd:
111 trace_context_write_flow_end_event_record(context, start_time, &thread,
119 trace_release_context(context);
static T Minimum(T x, T y)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
constexpr intptr_t kMicrosecondsPerSecond