• Sami Kyostila's avatar
    Reland: Redesign ATrace integration · 7c1a1d49
    Sami Kyostila authored
    (Reland of https://chromium-review.googlesource.com/c/chromium/src/+/2332664)
    
    Chrome and WebView have supported basic Android ATrace tracing, but the
    current approach has some shortcomings:
    
    1) Android R changes the way atrace session activations are broadcast,
       breaking the code in WebView listening for activations
       (OnTraceEnabledChangeListener). This means you can't trace a running
       WebView app with atrace.
    
    2) Neither Chrome nor WebView record early startup events to atrace,
       which means all events before the native library has loaded are
       lost.
    
    3) It's not possible to specify trace categories via atrace, which means
       we need more cumbersome alternative solutions (i.e., command line
       flags) for startup tracing.
    
    4) Writing ATrace events is only supported in WebView.
    
    This patch reworks the ATrace integration to resolve these problems and
    to align the Chrome and WebView implementations. In short, ATrace
    session management is moved to the common (TraceEvent) layer, and Chrome
    and WebView only differ by which trace tags they listen to (APP vs.
    WEBVIEW).
    
    We also add a way to declare trace categories through per-app tags:
    
    $ atrace -a org.chromium.chrome,org.chromium.chrome/<category_filter>
    
    (Note that the plain package name without any category filters must
    always appear in the list on its own.)
    
    Multiple categories can be separated with a double colon:
    
    $ atrace -a org.chromium.chrome,org.chromium.chrome/cat1:cat2
    
    Or by specifying the the app several times to get around the 91
    character limit for each entry:
    
    $ atrace -a org.chromium.chrome,\
                org.chromium.chrome/cat1,\
                org.chromium.chrome/cat2
    
    Finally, to capture Java startup events into a tracing session
    controlled by the system's Perfetto service instead of atrace, a
    special "-atrace" category can be used to only write events into
    Chrome's own tracing service instead of atrace. This way when we
    connect to Perfetto later in the startup sequence and establish
    the real tracing session, startup-related events can be flushed
    into that session without emitting duplicate events into ATrace.
    
    TEST=atrace -a org.chromium.chrome
    
    TEST=atrace webview
    
    TEST=atrace -a org.chromium.chrome
    
    TEST=atrace webview
    
    TEST=atrace -a org.chromium.chrome,org.chromium.chrome/-*:cc
    
    TEST=atrace -a com.google.android.gm,com.google.android.gm/-*:cc webview
    
    TEST=atrace -a org.chromium.chrome,org.chromium.chrome/-atrace
    
    Bug: 1095587, b/160768681
    Change-Id: Ifc1488cc1a045bb79a804f13596935234fc7a163
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364635
    Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
    Reviewed-by: default avatarBo <boliu@chromium.org>
    Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
    Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#800611}
    7c1a1d49
trace_event_android.cc 6.26 KB