• Gabriel Charette's avatar
    [base] Add a master-toplevel trace event while a ThreadController is active · 0597d656
    Gabriel Charette authored
    The trace event will be called "ThreadController active" and be in the
    "base" tracing category. It will be activated for each active nested
    loop ThreadController is involved in (i.e. all loops but purely native
    nested loops -- undetectable).
    
    The implementation uses a stack of active run-levels (replacing some
    existing run-levels counters). This is is simpler than the alternatives
    as the amount of conditions to enter/exit a run-level are too many to
    hope to get manual accounting right:
    Enter:
     - DoWork() coming from Run()
     - DoWork() coming from native HandleWorkMessage
     - BeforeDoInternalWork() coming from Run() or native as well
     - DoIdleWork coming from a native nested loop (this one is surprising
       but happens on Mac because the |idle_work_source_| gets invoked
       first when the |work_source_| isn't signaled and a native nested
       loop starts..!)
    Exit:
     - DoIdleWork()
     - Quit() (was it already idle or not?)
     - Exit nested loop (was it already idle or not?)
     - Exit native task (was there a native nested loop within that native
       task that we need to "end" now?)
    
    Two tricky cases:
      Nested native task : Native task => native nested loop => native task
     vs
      Subsequent native tasks: Native task A (returns), Native task B
    
    BeforeDoInternalWork() was refactored as a scoped object because we
    need to be able to observe when a native task is done to capture
    Native Task => Nested native loop => End native task (needs to end
    the native loop, we aren't otherwise notified about it). We need to
    capture begin/end to be able to differentiate nested native tasks
    from subsequent native tasks (e.g. in a nested RunLoop without
    application tasks).
    
    The stack-based approach + scoped native work handles all of these
    cases across both ThreadController impls.
    
    R=altimin@chromium.org, fdoray@chromium.org
    
          and regular runtime. Example trace @ goto.google.com/oasrn
    
    Test: Locally with startup trace, nested loops (tab drag-out-of-window),
    Bug: 899897, 1074019
    Change-Id: I68831ce92a66da8b91a523d931846262182b5de5
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226216
    Commit-Queue: Gabriel Charette <gab@chromium.org>
    Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
    Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
    Reviewed-by: default avatarOliver Li <olivierli@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#825082}
    0597d656
thread_controller.cc 4.91 KB