Skip to content

On Android, consider tracing significant operations with Android Trace APIs #18178

Closed

Description

@ChrisCraik

From the Android platform side, it's often very useful to see what an app is doing from within Systrace, which shows tracing data from all the processes and services on the device: https://developer.android.com/studio/command-line/systrace

I know Flutter has its own tracing, but it's nice for platform/system-health folks to broadly know what's going on from just Systrace, especially in the context of graphics pipeline.

Note, there are now NDK APIs so you don't have to call up to Java: https://developer.android.com/ndk/guides/tracing

The tracing infrastructure on Android is optimized to be near zero cost when tracing isn't enabled, so it's just a single easily predicted branch in practice. It's somewhat expensive when tracing is on though (roughly 10us per begin/end pair), since it immediately serializes the data to a per-core trace buffer in Kernel owned memory.

Because they're expensive, we generally recommend starting with something minimal, like blocks for UI portion of frame, GPU portion of frame, and any expensive blocks of code like image decode, upload, or compositing operations. Typically want to have a couple dozen events per frame, more than that we've found to be too intrusive.

Activity

  1. added
    platform-androidAndroid applications specifically
    engineflutter/engine related. See also e: labels.
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    on Jun 4, 2018
  2. eseidelGoogle commented on Jun 4, 2018

    @eseidelGoogle
    Contributor

    I believe Flutter just sits on top of Dart's tracing: https://github.com/flutter/engine/blob/master/fml/trace_event.cc. Maybe the Dart SDK should know how to plumb trace events down to systrace on Android?

    Depends I guess on if the expectations of "expensive" are compatible or not. Flutter's tracing by default may be too chatty.

  3. Hixie commented on Jun 4, 2018

    @Hixie
    Contributor
  4. Hixie commented on Jun 4, 2018

    @Hixie
    Contributor
  5. added this to the milestone on Jun 4, 2018
  6. rmacnak-google commented on Jun 4, 2018

    @rmacnak-google
    Contributor

    The VM already supports this. The engine can direct timeline events to Android systrace by setting --timeline_recorder=systrace in the VM flags.

  7. chinmaygarde commented on Jun 5, 2018

    @chinmaygarde
    Contributor

    @rmacnak-google: I can turn this on by default on Android. Will this also trace to observatory UI?

  8. rmacnak-google commented on Jun 5, 2018

    @rmacnak-google
    Contributor

    As discussed offline, this pushes events to systrace instead of the VM's trace buffer, so it would make Observatory show an empty timeline. A flag seems preferable, and would also make it easier to switch to the "startup" recorder when needed.

  9. Hixie commented on Jun 5, 2018

    @Hixie
    Contributor

    Can we just always send to both?

  10. Hixie commented on Jun 5, 2018

    @Hixie
    Contributor

    (Or have the Observatory fetch the systrace?)

  11. github-actions commented on Aug 15, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.platform-androidAndroid applications specifically

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions