⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181625 in webkit


Ignore:
Timestamp:
Mar 17, 2015, 1:41:19 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Show rendering frames (and FPS) in Layout and Rendering timeline
https://bugs.webkit.org/show_bug.cgi?id=142029

Patch by Matt Baker <Matt Baker> on 2015-03-17
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

  • inspector/protocol/Timeline.json:

Added new event type for runloop timeline records.

Source/WebCore:

Add new functionality to the Inspector timelines backend to add runloop data to timeline recordings.

  • inspector/InspectorTimelineAgent.cpp:

(WebCore::currentRunLoop):
(WebCore::InspectorTimelineAgent::internalStart):
(WebCore::InspectorTimelineAgent::internalStop):
(WebCore::toProtocol):
(WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
Install observers for the begining and end of the runloop when recording begins. All other
instrumented timeline events get added as children of the current runloop record, which is
sent to the frontend once the runloop completes.

  • inspector/InspectorTimelineAgent.h:
  • platform/cf/RunLoopObserver.cpp:

(WebCore::RunLoopObserver::schedule):
Wrapper changed to allow observing arbitrary runloop activities.

  • platform/cf/RunLoopObserver.h:
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r181618 r181625  
     12015-03-17  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Show rendering frames (and FPS) in Layout and Rendering timeline
     4        https://bugs.webkit.org/show_bug.cgi?id=142029
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * inspector/protocol/Timeline.json:
     9        Added new event type for runloop timeline records.
     10
    1112015-03-16  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/Source/JavaScriptCore/inspector/protocol/Timeline.json

    r178371 r181625  
    1414                "Layout",
    1515                "Paint",
     16                "RunLoop",
    1617                "ScrollLayer",
    1718                "ParseHTML",
  • trunk/Source/WebCore/ChangeLog

    r181624 r181625  
     12015-03-17  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Show rendering frames (and FPS) in Layout and Rendering timeline
     4        https://bugs.webkit.org/show_bug.cgi?id=142029
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Add new functionality to the Inspector timelines backend to add runloop data to timeline recordings.
     9
     10        * inspector/InspectorTimelineAgent.cpp:
     11        (WebCore::currentRunLoop):
     12        (WebCore::InspectorTimelineAgent::internalStart):
     13        (WebCore::InspectorTimelineAgent::internalStop):
     14        (WebCore::toProtocol):
     15        (WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
     16        Install observers for the begining and end of the runloop when recording begins. All other
     17        instrumented timeline events get added as children of the current runloop record, which is
     18        sent to the frontend once the runloop completes.
     19
     20        * inspector/InspectorTimelineAgent.h:
     21
     22        * platform/cf/RunLoopObserver.cpp:
     23        (WebCore::RunLoopObserver::schedule):
     24        Wrapper changed to allow observing arbitrary runloop activities.
     25
     26        * platform/cf/RunLoopObserver.h:
     27
    1282015-03-17  Philippe Normand  <pnormand@igalia.com>
    229
  • trunk/Source/WebCore/inspector/InspectorTimelineAgent.cpp

    r180901 r181625  
    5555#include <wtf/CurrentTime.h>
    5656
     57#if PLATFORM(IOS)
     58#include "RuntimeApplicationChecksIOS.h"
     59#include <WebCore/WebCoreThread.h>
     60#endif
     61
     62#if PLATFORM(COCOA)
     63#include <WebCore/RunLoopObserver.h>
     64#endif
     65
    5766using namespace Inspector;
    5867
    5968namespace WebCore {
     69
     70#if PLATFORM(COCOA)
     71static const CFIndex frameStopRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit + 1;
     72
     73static CFRunLoopRef currentRunLoop()
     74{
     75#if PLATFORM(IOS)
     76    // A race condition during WebView deallocation can lead to a crash if the layer sync run loop
     77    // observer is added to the main run loop <rdar://problem/9798550>. However, for responsiveness,
     78    // we still allow this, see <rdar://problem/7403328>. Since the race condition and subsequent
     79    // crash are especially troublesome for iBooks, we never allow the observer to be added to the
     80    // main run loop in iBooks.
     81    if (applicationIsIBooksOnIOS())
     82        return WebThreadRunLoop();
     83#endif
     84    return CFRunLoopGetCurrent();
     85}
     86#endif
    6087
    6188InspectorTimelineAgent::~InspectorTimelineAgent()
     
    123150    m_enabled = true;
    124151
     152    // FIXME: Abstract away platform-specific code once https://bugs.webkit.org/show_bug.cgi?id=142748 is fixed.
     153
     154#if PLATFORM(COCOA)
     155    m_frameStartObserver = RunLoopObserver::create(0, [this]() {
     156        if (!m_enabled || m_didStartRecordingRunLoop)
     157            return;
     158
     159        pushCurrentRecord(InspectorObject::create(), TimelineRecordType::RunLoop, false, nullptr);
     160        m_didStartRecordingRunLoop = true;
     161    });
     162
     163    m_frameStopObserver = RunLoopObserver::create(frameStopRunLoopOrder, [this]() {
     164        if (!m_enabled || !m_didStartRecordingRunLoop)
     165            return;
     166
     167        didCompleteCurrentRecord(TimelineRecordType::RunLoop);
     168        m_didStartRecordingRunLoop = false;
     169    });
     170
     171    m_frameStartObserver->schedule(currentRunLoop(), kCFRunLoopAfterWaiting | kCFRunLoopBeforeTimers);
     172    m_frameStopObserver->schedule(currentRunLoop(), kCFRunLoopBeforeWaiting | kCFRunLoopExit);
     173
     174    // Create a runloop record immediately in order to capture the rest of the current runloop.
     175    pushCurrentRecord(InspectorObject::create(), TimelineRecordType::RunLoop, false, nullptr);
     176    m_didStartRecordingRunLoop = true;
     177#endif
     178
    125179    if (m_frontendDispatcher)
    126180        m_frontendDispatcher->recordingStarted();
     
    141195    if (m_scriptDebugServer)
    142196        m_scriptDebugServer->removeListener(this, true);
     197
     198#if PLATFORM(COCOA)
     199    m_frameStartObserver = nullptr;
     200    m_frameStopObserver = nullptr;
     201#endif
    143202
    144203    clearRecordStack();
     
    540599    case TimelineRecordType::Paint:
    541600        return Inspector::Protocol::Timeline::EventType::Paint;
     601    case TimelineRecordType::RunLoop:
     602        return Inspector::Protocol::Timeline::EventType::RunLoop;
    542603    case TimelineRecordType::ScrollLayer:
    543604        return Inspector::Protocol::Timeline::EventType::ScrollLayer;
     
    655716    , m_enabled(false)
    656717    , m_enabledFromFrontend(false)
     718    , m_didStartRecordingRunLoop(false)
    657719{
    658720}
  • trunk/Source/WebCore/inspector/InspectorTimelineAgent.h

    r180116 r181625  
    6262class ResourceRequest;
    6363class ResourceResponse;
     64class RunLoopObserver;
    6465
    6566typedef String ErrorString;
     
    7273    Layout,
    7374    Paint,
     75    RunLoop,
    7476    ScrollLayer,
    7577
     
    245247    bool m_enabled;
    246248    bool m_enabledFromFrontend;
     249
     250#if PLATFORM(COCOA)
     251    std::unique_ptr<WebCore::RunLoopObserver> m_frameStartObserver;
     252    std::unique_ptr<WebCore::RunLoopObserver> m_frameStopObserver;
     253#endif
     254    bool m_didStartRecordingRunLoop;
    247255};
    248256
  • trunk/Source/WebCore/platform/cf/RunLoopObserver.cpp

    r169775 r181625  
    5050}
    5151
    52 void RunLoopObserver::schedule(CFRunLoopRef runLoop)
     52void RunLoopObserver::schedule(CFRunLoopRef runLoop, CFRunLoopActivity activity)
    5353{
    5454    if (!runLoop)
     
    6262
    6363    CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
    64     m_runLoopObserver = adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, m_order, runLoopObserverFired, &context));
     64    m_runLoopObserver = adoptCF(CFRunLoopObserverCreate(0, activity, true, m_order, runLoopObserverFired, &context));
    6565
    6666    CFRunLoopAddObserver(runLoop, m_runLoopObserver.get(), kCFRunLoopCommonModes);
  • trunk/Source/WebCore/platform/cf/RunLoopObserver.h

    r172849 r181625  
    4343    WEBCORE_EXPORT ~RunLoopObserver();
    4444
    45     WEBCORE_EXPORT void schedule(CFRunLoopRef = nullptr);
     45    WEBCORE_EXPORT void schedule(CFRunLoopRef = nullptr, CFRunLoopActivity = kCFRunLoopBeforeWaiting | kCFRunLoopExit);
    4646    WEBCORE_EXPORT void invalidate();
    4747
Note: See TracChangeset for help on using the changeset viewer.