141 Commits

Author SHA1 Message Date
Chris Bracken
f173e72e06 Migrate Fuchsia runners to SDK tracing API (flutter/engine#10478)
Migrates the Fuchsia Flutter and Dart runners off the internal tracing
APIs and onto the public SDK.
2019-08-06 11:26:34 -07:00
Nathan Rogers
436b76d9fe Use Fuchsia trace macros when targeting Fuchsia SDK (flutter/engine#10634)
When |OS_FUCHSIA| is defined (even when |FUCHSIA_SDK| is defined as
well), use the Fuchsia SDK trace macros rather than the Dart timeline.

Reasons for doing this include:

Fuchsia's trace macros support categories.  This allows one to
distinguish between (e.g.) "flutter" and "skia" trace events for trace
recording and trace visualization.

Fuchsia has existing in tree benchmarks that depend on finding certain
events under category "flutter".

See the Fuchsia performance mailing list discussion for more context.
2019-08-05 12:52:36 -07:00
Jason Simmons
62415d538c Log dlopen errors only in debug mode (flutter/engine#9890)
dlopen errors are expected behavior when locating libapp.so on some older
Android devices (see https://github.com/flutter/engine/pull/9762)
2019-07-17 12:51:03 -07:00
Kaushik Iska
419d1b9cae Add the functionality to merge and unmerge MessageLoopTaskQueues (flutter/engine#9436)
- Add the functionality to merge and unmerge MessageLoopTaskQueues

This introduces a notion of a "owning" and "subsumed" queue ids.
Owning queue will take care of the tasks submitted to both that and it's
subsumed queue.

- The tasks submitted still maintain the queue affinity
- Same for the task observers

- Also adds MergedQueuesRunner which grabs both the locks owner
  and subsumed queues in RAII fashion.

- Also use task queue id to verify if we are running
  in the same thread.

- This is to enable merging the backed message loop task
  queues to enable dynamic thread merging in IOS.
2019-07-12 16:55:33 -07:00
gaaclarke
6acae05b3c Synchronize main thread and gpu thread for first render frame (flutter/engine#9506)
Got rid of the black frame by synchronizing the main thread with the
gpu thread to make sure a frame is rendered before presenting the
view.
2019-07-10 13:14:07 -07:00
Chinmay Garde
3d231d854c Use libc++ variant of string view and remove the FML variant. (flutter/engine#9737) 2019-07-10 12:11:39 -07:00
Chinmay Garde
a5799c0964 Rework image & texture management to use concurrent message queues. (flutter/engine#9486)
This patch reworks image decompression and collection in the following ways
because of misbehavior in the described edge cases.

The current flow for realizing a texture on the GPU from a blob of compressed
bytes is to first pass it to the IO thread for image decompression and then
upload to the GPU. The handle to the texture on the GPU is then passed back to
the UI thread so that it can be included in subsequent layer trees for
rendering. The GPU contexts on the Render & IO threads are in the same
sharegroup so the texture ends up being visible to the Render Thread context
during rendering. This works fine and does not block the UI thread. All
references to the image are owned on UI thread by Dart objects. When the final
reference to the image is dropped, the texture cannot be collected on the UI
thread (because it has not GPU context). Instead, it must be passed to either
the GPU or IO threads. The GPU thread is usually in the middle of a frame
workload so we redirect the same to the IO thread for eventual collection. While
texture collections are usually (comparatively) fast, texture decompression and
upload are slow (order of magnitude of frame intervals).

For application that end up creating (by not necessarily using) numerous large
textures in straight-line execution, it could be the case that texture
collection tasks are pending on the IO task runner after all the image
decompressions (and upload) are done. Put simply, the collection of the first
image could be waiting for the decompression and upload of the last image in the
queue.

This is exacerbated by two other hacks added to workaround unrelated issues.
* First, creating a codec with a single image frame immediately kicks of
  decompression and upload of that frame image (even if the frame was never
  request from the codec). This hack was added because we wanted to get rid of
  the compressed image allocation ASAP. The expectation was codecs would only be
  created with the sole purpose of getting the decompressed image bytes.
  However, for applications that only create codecs to get image sizes (but
  never actually decompress the same), we would end up replacing the compressed
  image allocation with a larger allocation (device resident no less) for no
  obvious use. This issue is particularly insidious when you consider that the
  codec is usually asked for the native image size first before the frame is
  requested at a smaller size (usually using a new codec with same data but new
  targetsize). This would cause the creation of a whole extra texture (at 1:1)
  when the caller was trying to “optimize” for memory use by requesting a
  texture of a smaller size.
* Second, all image collections we delayed in by the unref queue by 250ms
  because of observations that the calling thread (the UI thread) was being
  descheduled unnecessarily when a task with a timeout of zero was posted from
  the same (recall that a task has to be posted to the IO thread for the
  collection of that texture). 250ms is multiple frame intervals worth of
  potentially unnecessary textures.

The net result of these issues is that we may end up creating textures when all
that the application needs is to ask it’s codec for details about the same (but
not necessarily access its bytes). Texture collection could also be delayed
behind other jobs to decompress the textures on the IO thread. Also, all texture
collections are delayed for an arbitrary amount of time.

These issues cause applications to be susceptible to OOM situations. These
situations manifest in various ways. Host memory exhaustion causes the usual OOM
issues. Device memory exhaustion seems to manifest in different ways on iOS and
Android. On Android, allocation of a new texture seems to be causing an
assertion (in the driver). On iOS, the call hangs (presumably waiting for
another thread to release textures which we won’t do because those tasks are
blocked behind the current task completing).

To address peak memory usage, the following changes have been made:
* Image decompression and upload/collection no longer happen on the same thread.
  All image decompression will now be handled on a workqueue. The number of
  worker threads in this workqueue is equal to the number of processors on the
  device. These threads have a lower priority that either the UI or Render
  threads. These workers are shared between all Flutter applications in the
  process.
* Both the images and their codec now report the correct allocation size to Dart
  for GC purposes. The Dart VM uses this to pick objects for collection. Earlier
  the image allocation was assumed to 32bpp with no mipmapping overhead
  reported. Now, the correct image size is reported and the mipmapping overhead
  is accounted for. Image codec sizes were not reported to the VM earlier and
  now are. Expect “External” VM allocations to be higher than previously
  reported and the numbers in Observatory to line up more closely with actual
  memory usage (device and host).
* Decoding images to a specific size used to decode to 1:1 before performing a
  resize to the correct dimensions before texture upload. This has now been
  reworked so that images are first decompressed to a smaller size supported
  natively by the codec before final resizing to the requested target size. The
  intermediate copy is now smaller and more promptly collected. Resizing also
  happens on the workqueue worker.
* The drain interval of the unref queue is now sub-frame-interval. I am hesitant
  to remove the delay entirely because I have not been able to instrument the
  performance overhead of the same. That is next on my list. But now, multiple
  frame intervals worth of textures no longer stick around.

The following issues have been addressed:
* https://github.com/flutter/flutter/issues/34070 Since this was the first usage
  of the concurrent message loops, the number of idle wakes were determined to
  be too high and this component has been rewritten to be simpler and not use
  the existing task runner and MessageLoopImpl interface.
* Image decoding had no tests. The new `ui_unittests` harness has been added
  that sets up a GPU test harness on the host using SwiftShader. Tests have been
  added for image decompression, upload and resizing.
* The device memory exhaustion in this benchmark has been addressed. That
  benchmark is still not viable for inclusion in any harness however because it
  creates 9 million codecs in straight-line execution. Because these codecs are
  destroyed in the microtask callbacks, these are referenced till those
  callbacks are executed. So now, instead of device memory exhaustion, this will
  lead to (slower) exhaustion of host memory. This is expected and working as
  intended.

This patch only addresses peak memory use and makes collection of unused images
and textures more prompt. It does NOT address memory use by images referenced
strongly by the application or framework.
2019-07-09 14:59:34 -07:00
Kaushik Iska
5baec7447f Message loop task heaps are shared (flutter/engine#9335) 2019-06-19 14:03:14 -07:00
Chinmay Garde
5f5821e8c1 Replace lock_guard with scoped_lock and use class template argument deduction. (flutter/engine#9338) 2019-06-17 10:08:45 -07:00
Chinmay Garde
8c2cd91934 Roll buildroot to 75660ad5 and complete the C++ 17 transition. (flutter/engine#9319) 2019-06-14 12:52:03 -07:00
Kaushik Iska
38b19e6462 MessageLoopTaskQueue schedules Wakes (flutter/engine#9316)
* Refactor to move Task Queue to its own class

- This is to help with sharing task queue among
  multiple message loops going forward.

- currently there is 1:1 mapping between task queue
  and message loop, we are still maintaining the semantics
  for this change.

* Add mutex include

* Most of the waking up changes minus test failures

* Refactor MessageLoopImpl to be Wakeable

- Makes testing easier by letting us putting a TestWakeable

- Also move the waking up logic to the task queue

* add tests

* Fix formatting and license
2019-06-13 17:44:44 -07:00
Kaushik Iska
f751033171 Refactor: move Task Queue to its own class (flutter/engine#9301)
* Refactor to move Task Queue to its own class

- This is to help with sharing task queue among
  multiple message loops going forward.

- currently there is 1:1 mapping between task queue
  and message loop, we are still maintaining the semantics
  for this change.

* Add mutex include

* Add unit tests for task queue

* fix formatting

* license
2019-06-13 10:14:13 -07:00
Zachary Anderson
35107c4dca Revert tracing changes (flutter/engine#9296)
* Revert "[fuchsia] Fix alignment of Fuchsia/non-Fuchsia tracing (#9289)"

This reverts commit e7d406fe36790b1a8161d4687a6a4a144ba44254.

* Revert "Align fuchsia and non-fuchsia tracing (#9199)"

This reverts commit 1ccb372e5f8ceaaf90f5b43b42df617d7f18d955.
2019-06-12 10:25:49 -07:00
Kaushik Iska
deaaaf3d53 Refactor Delayed Tasks to their own file (flutter/engine#9290)
* Refactor Delayed Tasks to their own class

* fix some comments

* Update BUILD.gn
2019-06-11 18:33:04 -07:00
Dan Field
e7d406fe36 [fuchsia] Fix alignment of Fuchsia/non-Fuchsia tracing (flutter/engine#9289) 2019-06-11 18:02:15 -07:00
Dan Field
1ccb372e5f Align fuchsia and non-fuchsia tracing (flutter/engine#9199) 2019-06-05 15:14:27 -07:00
Kaushik Iska
f5c2ed1a61 Allow the task queues to be swapped in MessageLoops (flutter/engine#9189) 2019-06-04 21:19:44 -07:00
liyuqian
30a6b323b4 Add missing ifndef guard for count_down_latch.h (flutter/engine#9143)
I discovered this while experimenting with the timing API.
2019-05-30 14:17:08 -07:00
Chinmay Garde
cb00aac583 Allow specifying both Dart and non-Dart fixtures in engine unit-tests. (flutter/engine#9113)
* Allow specifying both Dart and non-Dart fixtures in engine unittests.

This fixes numerous issues in the way in which fixtures were managed
in the engine unit-tests.

* Instead of only being able to specify Dart fixtures, unit-tests may specify
  non-Dart fixtures as well. These are simply copied over to the fixtures
  directory known to the unit-test at runtime.
* An issue where numerous Dart files could be given to the kernel snapshotter
  has been addressed. It was anticipated that such a (legal) invocation to the
  kernel snapshotter would produce a snapshot with the contents of all the Dart
  files added to the root library. This is incorrect and the behavior in this
  case is undefined.
* Dart files referenced by the main Dart file are correctly tracked via a
  depfile.
* The snapshotter arguments have been cleaned up to get rid of unused
  arguments (`—strong`) and  the use of the VM product mode argument has been
  corrected to no longer depend on the Flutter product mode.
2019-05-28 19:11:47 -07:00
Chris Bracken
21fd6fb32a Correct typos, adopt US spellings (flutter/engine#9081)
Corects a bnuch of typeos throughout teh engien codebsae. Also makes
a couple minor Commonwealth -> US spelling adjustments for consistency
with the rest of Flutter's codebase.

Made use of `misspell` tool:
https://github.com/client9/misspell
2019-05-25 13:14:46 -07:00
Adam Barth
e1c043fe58 [fuchsia] Update zx_clock_get callers (flutter/engine#8998)
Fuchsia is changing zx_clock_get to return a zx_status_t. This change
prepares us for that change.
2019-05-17 16:37:28 -07:00
Matthew Dempsky
0bca459e28 Replace ararysize macro with fml::size function (flutter/engine#8975)
This is forward compatible with std::size and similar to how Chromium
removed use of the arraysize macro.
2019-05-15 12:43:47 -07:00
Chinmay Garde
74f9cc79b3 Avoid disabling sources assignment filters are these have been removed. (flutter/engine#8954) 2019-05-13 18:38:28 -07:00
stuartmorgan
4bb9f5d60d Standardize TimePoint implementaion on std::chrono (flutter/engine#8913)
In practice, the implementations of std::chrono seem to match our
implementations, so this makes the code simpler and easier to maintain,
as well as potentially improving over time without changes on our part.
2019-05-09 10:33:36 -04:00
stuartmorgan
501354c207 Fix TimePoint on Windows (flutter/engine#8910)
Addresses overflow issues with timer multiplication by using std::chrono
instead of QueryPerformanceCounter. The Windows implementation of
std::chrono uses QPC, so this should have no impact on performance or
clock resolution.

Fixes #32121
2019-05-08 23:20:32 -04:00
Chinmay Garde
56e7bf84b1 Wire up Fuchsia SDK related updated for shell dependencies. #8869
This does not actually import the runners into the engine. It only sets up the targets so they need no modifications are necessary when the migration is done. The engine has been verified to build in both buildroots.
2019-05-06 18:01:59 -07:00
Matthew Dempsky
ea70585830 Fix header include guards for fml/thread_local.h (flutter/engine#8721)
While working on #8659, I had planned on renaming this file to
thread_local_unique_ptr.h, but decided against that at the last minute
before sending for review. However, when reverting the file rename, I
forgot to also revert the header guard change.
2019-04-29 11:07:04 -07:00
Dan Field
c7e9c7b016 Fix crash when cursor ends up at invalid position (flutter/engine#8747) 2019-04-26 15:43:44 -07:00
liyuqian
358e88cabf Revert "Only allow mappings for ICU initialization. (#8656)" (flutter/engine#8682)
This reverts commit dfaa1c9292238e73c56d36f7264adc63ea53745c.

Reverts flutter/engine#8656

Reason:  https://github.com/flutter/engine/pull/8656 seems to break the framework windows tests and the engine roll (see https://cirrus-ci.com/task/4704667236827136 and https://github.com/flutter/flutter/pull/31330). The failure has been consistent for 7 consecutive engine-to-framework auto-rolls.

TBR: @chinmaygarde
2019-04-22 10:28:54 -07:00
Matthew Dempsky
2107712b0f Replace ThreadLocal with ThreadLocalUniquePtr<T> (flutter/engine#8659)
Fixes https://github.com/flutter/flutter/issues/31292.
2019-04-19 17:33:46 -07:00
Chinmay Garde
dfaa1c9292 Only allow mappings for ICU initialization. (flutter/engine#8656)
If the mapping callback is not set or it the callback returns invalid data, ICU initialization will be embedder responsibility.

This affects all embedders and the following have been audited:
* Android: Via a symbol mapping.
* iOS: Via a file mapping.
* Embedder: Via a file mapping.
* Fuchsia: Via a VMO mapping
* Test shells and Flutter tester: Via file mapping with ICU data needing to be next to the executable.
2019-04-19 15:01:40 -07:00
Chinmay Garde
1133591eeb Add factory methods to FileMapping that make it easy to create common mappings. (flutter/engine#8652)
The GetMapping calls removed in this patch had the same code and had to be repeated across different test harnesses as well as in dart_snapshot.cc. Just make this a factory method so the code is less verbose.
2019-04-19 12:48:53 -07:00
Chinmay Garde
46f575eccb Reland "Remove DartSnapshotBuffer and dry up snapshot resolution logic". (flutter/engine#8645)
This reverts commit 1c06891c101f530c1f46337b457ba02e0f6c8633.
Windows depends on referencing the snapshot symbols directly instead of
via dlsym. Something in the way these symbolsa are generated in
bin_to_assembly.py is causing them to be inaccessible at runtime.
2019-04-18 18:54:43 -07:00
Chinmay Garde
1c06891c10 Revert "Remove DartSnapshotBuffer and dry up snapshot resolution logic. (#8640)" (flutter/engine#8644)
This reverts commit 29b322db9ecd6f8fad72b5f7ad91a64e01c89958.
2019-04-18 16:46:03 -07:00
Chinmay Garde
29b322db9e Remove DartSnapshotBuffer and dry up snapshot resolution logic. (flutter/engine#8640)
Fixes https://github.com/flutter/flutter/issues/26782.
2019-04-18 16:01:19 -07:00
Chinmay Garde
2b4e6ce82b Merge flutter/synchronization contents into fml. (flutter/engine#8525)
When flutter/synchronization was first authored, we did not own fml (it was called fxl then). Now we do, so use a single spot for such utilities. The pipeline was meant to be a general purpose utility that was only ever used by the animator (it even has animator specific tracing), so move that to shell instead (where the animator resides).
2019-04-09 19:18:51 -07:00
Chinmay Garde
2217a3a42d Support message loops whose tasks are executed concurrently. (flutter/engine#8419)
The number of workers depends on what the platform deem appropriate for the system at runtime.
2019-04-09 17:03:41 -07:00
David Worsham
0e76733763 Add Views V2 support for Fuchsia (flutter/engine#8115) 2019-04-07 01:18:59 -07:00
Chinmay Garde
20fe654ef3 Allow embedders to specify their own task runner interfaces. (flutter/engine#8273)
Currently, all Flutter threads are managed by the engine itself. This works for
all threads except the platform thread. On this thread, the engine cannot see
the underlying event multiplexing mechanism. Using the new task runner
interfaces, the engine can relinquish the task of setting up the event
multiplexing mechanism and instead have the embedder provide one for it during
setup.

This scheme is only wired up for the platform thread. But, the eventual goal
is to expose this message loop interoperability for all threads.
2019-03-27 16:16:59 -07:00
Zachary Anderson
610db85f04 [fuchsia] Disable FML_TRACE_COUNTER events to unblock roll (flutter/engine#8325) 2019-03-27 10:36:34 -07:00
Zachary Anderson
4a4a074914 [fuchsia] Add missing trace macros (flutter/engine#8297) 2019-03-25 16:03:41 -07:00
Chinmay Garde
16999258f7 Simplify the fallback waiter and add traces for vsync scheduling overhead. (flutter/engine#8185) 2019-03-18 15:49:16 -07:00
Chinmay Garde
9ada55b844 Add frame and target time metadata to vsync events and connect platform vsync events using flows. (flutter/engine#8172)
This will allow us to easily visualize the time the platform informed the engine of a vsync event, its arguments, and when the engine began its UI thread workload using this information.
2019-03-14 16:48:01 -07:00
Chinmay Garde
8fc02f5b1d Add an allocator specific check to ensure that strings passed to the timeline are not heap allocated. (flutter/engine#8168)
Verified that the tests fail on issues like https://github.com/flutter/engine/pull/8166. Unfortunately, there is no x-platform way to perform this check but this should gate incorrect traces being added to the engine.
2019-03-14 14:15:46 -07:00
Jason Simmons
4670858e8f Do not pass short-lived buffers as labels to Dart_TimelineEvent (flutter/engine#8166)
Dart no longer makes a copy of the label string when recording events.

See https://github.com/flutter/engine/pull/8152
2019-03-14 12:49:42 -07:00
Chinmay Garde
0809280550 Reland ""Add support for trace counters with variable arguments and instrument the raster cache." (flutter/engine#8145)
This reverts commit da6e460c67c34d34eef1e9ec87b8534a379fe1f5 and fixes the
discovered on Windows builds.
2019-03-13 13:53:22 -07:00
liyuqian
6b28290f44 Typo "fast an inline" to "fast and inline" (flutter/engine#8142) 2019-03-12 15:27:33 -07:00
Chinmay Garde
da6e460c67 Revert "Add support for trace counters with variable arguments and instrument the raster cache. (#8094)" (flutter/engine#8122)
This reverts commit 9f384e3e4cbfdf23381509a62c7023e77edcbfd8.
2019-03-11 15:09:24 -07:00
Chinmay Garde
9f384e3e4c Add support for trace counters with variable arguments and instrument the raster cache. (flutter/engine#8094) 2019-03-11 14:44:43 -07:00
Chinmay Garde
c20c3c47f4 Remove redundant thread checker in FML. (flutter/engine#8053)
There is already fml/memory/thread_checker.h
2019-03-05 20:07:10 -08:00