From 8d12a45c6a436439b752dba9d2c068f510a11cdd Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 21 Feb 2019 22:42:49 -0800 Subject: [PATCH] Allow embedders to add events to the timeline. (flutter/engine#7917) Fixes https://github.com/flutter/flutter/issues/28283 --- .../shell/platform/embedder/embedder.cc | 13 +++++++++++ .../shell/platform/embedder/embedder.h | 22 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/engine/src/flutter/shell/platform/embedder/embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder.cc index 6444104a1c..d3e05daa1d 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder.cc @@ -24,6 +24,7 @@ #include "flutter/fml/make_copyable.h" #include "flutter/fml/message_loop.h" #include "flutter/fml/paths.h" +#include "flutter/fml/trace_event.h" #include "flutter/shell/common/persistent_cache.h" #include "flutter/shell/common/rasterizer.h" #include "flutter/shell/common/switches.h" @@ -808,3 +809,15 @@ FlutterEngineResult FlutterEngineDispatchSemanticsAction( } return kSuccess; } + +void FlutterEngineTraceEventDurationBegin(const char* name) { + fml::tracing::TraceEvent0("flutter", name); +} + +void FlutterEngineTraceEventDurationEnd(const char* name) { + fml::tracing::TraceEventEnd(name); +} + +void FlutterEngineTraceEventInstant(const char* name) { + fml::tracing::TraceEventInstant0("flutter", name); +} diff --git a/engine/src/flutter/shell/platform/embedder/embedder.h b/engine/src/flutter/shell/platform/embedder/embedder.h index 0bcd163d59..0186ecb2f1 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.h +++ b/engine/src/flutter/shell/platform/embedder/embedder.h @@ -596,6 +596,28 @@ FlutterEngineResult FlutterEngineDispatchSemanticsAction( const uint8_t* data, size_t data_length); +// A profiling utility. Logs a trace duration begin event to the timeline. If +// the timeline is unavailable or disabled, this has no effect. Must be +// balanced with an duration end event (via +// |FlutterEngineTraceEventDurationEnd|) with the same name on the same thread. +// Can be called on any thread. +FLUTTER_EXPORT +void FlutterEngineTraceEventDurationBegin(const char* name); + +// A profiling utility. Logs a trace duration end event to the timeline. If +// the timeline is unavailable or disabled, this has no effect. This call must +// be preceeded by a trace duration begin call (via +// |FlutterEngineTraceEventDurationBegin|) with the same name on the same +// thread. Can be called on any thread. +FLUTTER_EXPORT +void FlutterEngineTraceEventDurationEnd(const char* name); + +// A profiling utility. Logs a trace duration instant event to the timeline. If +// the timeline is unavailable or disabled, this has no effect. Can be called +// on any thread. +FLUTTER_EXPORT +void FlutterEngineTraceEventInstant(const char* name); + #if defined(__cplusplus) } // extern "C" #endif