Changeset 240522 in webkit


Ignore:
Timestamp:
Jan 25, 2019 3:45:04 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Exclude Debugger Threads from CPU Usage values in Web Inspector
https://bugs.webkit.org/show_bug.cgi?id=193796
<rdar://problem/47532910>

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2019-01-25
Reviewed by Devin Rousso.

Source/JavaScriptCore:

  • runtime/SamplingProfiler.cpp:

(JSC::SamplingProfiler::machThread):

  • runtime/SamplingProfiler.h:

Expose the mach_port_t of the SamplingProfiler thread
so it can be tested against later.

Source/WebCore:

  • page/ResourceUsageData.h:
  • inspector/agents/InspectorCPUProfilerAgent.cpp:

(WebCore::InspectorCPUProfilerAgent::collectSample):
Show the CPU usage without debugger threads in the Web Inspector's timeline.

  • page/ResourceUsageThread.h:
  • page/cocoa/ResourceUsageThreadCocoa.mm:

(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting):
For OS(DARWIN) ports, when starting to observe resource usage,
we grab the mach_port_t of SamplingProfiler on the main thread
in a thread safe way. For our purposes (Web Inspector timelines),
this will be good enough to identify the SamplingProfiler thread
during timeline recording. The SamplingProfiler thread won't change
during a timeline recording and recording start/stops will never
miss the SamplingProfiler changing.

(WebCore::filterThreads):
(WebCore::threadSendRights):
(WebCore::threadSendRightsExcludingDebuggerThreads):
(WebCore::cpuUsage):
(WebCore::ResourceUsageThread::platformCollectCPUData):
Calculate CPU usage twice, the second time excluding some threads.

  • page/linux/ResourceUsageThreadLinux.cpp:

(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting):
(WebCore::ResourceUsageThread::platformCollectCPUData):
Stubs for linux ports.

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r240521 r240522  
     12019-01-25  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Exclude Debugger Threads from CPU Usage values in Web Inspector
     4        https://bugs.webkit.org/show_bug.cgi?id=193796
     5        <rdar://problem/47532910>
     6
     7        Reviewed by Devin Rousso.
     8
     9        * runtime/SamplingProfiler.cpp:
     10        (JSC::SamplingProfiler::machThread):
     11        * runtime/SamplingProfiler.h:
     12        Expose the mach_port_t of the SamplingProfiler thread
     13        so it can be tested against later.
     14
    1152019-01-25  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp

    r239427 r240522  
    10801080}
    10811081
     1082#if OS(DARWIN)
     1083mach_port_t SamplingProfiler::machThread()
     1084{
     1085    if (!m_thread)
     1086        return MACH_PORT_NULL;
     1087
     1088    return m_thread->machThread();
     1089}
     1090#endif
     1091
    10821092} // namespace JSC
    10831093
  • trunk/Source/JavaScriptCore/runtime/SamplingProfiler.h

    r239427 r240522  
    183183    JS_EXPORT_PRIVATE void reportTopBytecodes(PrintStream&);
    184184
     185#if OS(DARWIN)
     186    JS_EXPORT_PRIVATE mach_port_t machThread();
     187#endif
     188
    185189private:
    186190    void createThreadIfNecessary(const AbstractLocker&);
  • trunk/Source/WebCore/ChangeLog

    r240519 r240522  
     12019-01-25  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Exclude Debugger Threads from CPU Usage values in Web Inspector
     4        https://bugs.webkit.org/show_bug.cgi?id=193796
     5        <rdar://problem/47532910>
     6
     7        Reviewed by Devin Rousso.
     8
     9        * page/ResourceUsageData.h:
     10        * inspector/agents/InspectorCPUProfilerAgent.cpp:
     11        (WebCore::InspectorCPUProfilerAgent::collectSample):
     12        Show the CPU usage without debugger threads in the Web Inspector's timeline.
     13
     14        * page/ResourceUsageThread.h:
     15        * page/cocoa/ResourceUsageThreadCocoa.mm:
     16        (WebCore::ResourceUsageThread::platformSaveStateBeforeStarting):
     17        For OS(DARWIN) ports, when starting to observe resource usage,
     18        we grab the mach_port_t of SamplingProfiler on the main thread
     19        in a thread safe way. For our purposes (Web Inspector timelines),
     20        this will be good enough to identify the SamplingProfiler thread
     21        during timeline recording. The SamplingProfiler thread won't change
     22        during a timeline recording and recording start/stops will never
     23        miss the SamplingProfiler changing.
     24
     25        (WebCore::filterThreads):
     26        (WebCore::threadSendRights):
     27        (WebCore::threadSendRightsExcludingDebuggerThreads):
     28        (WebCore::cpuUsage):
     29        (WebCore::ResourceUsageThread::platformCollectCPUData):
     30        Calculate CPU usage twice, the second time excluding some threads.
     31
     32        * page/linux/ResourceUsageThreadLinux.cpp:
     33        (WebCore::ResourceUsageThread::platformSaveStateBeforeStarting):
     34        (WebCore::ResourceUsageThread::platformCollectCPUData):
     35        Stubs for linux ports.
     36
    1372019-01-25  Zalan Bujtas  <zalan@apple.com>
    238
  • trunk/Source/WebCore/inspector/agents/InspectorCPUProfilerAgent.cpp

    r240457 r240522  
    8585    auto event = Protocol::CPUProfiler::Event::create()
    8686        .setTimestamp(m_environment.executionStopwatch()->elapsedTimeSince(data.timestamp).seconds())
    87         .setUsage(data.cpu)
     87        .setUsage(data.cpuExcludingDebuggerThreads)
    8888        .release();
    8989
  • trunk/Source/WebCore/page/ResourceUsageData.h

    r240457 r240522  
    7676
    7777    float cpu { 0 };
     78    float cpuExcludingDebuggerThreads { 0 };
    7879    size_t totalDirtySize { 0 };
    7980    size_t totalExternalSize { 0 };
  • trunk/Source/WebCore/page/ResourceUsageThread.h

    r240457 r240522  
    3838#include <wtf/Threading.h>
    3939
     40#if OS(DARWIN)
     41#include <mach/mach.h>
     42#endif
     43
    4044namespace JSC {
    4145class VM;
     
    7175    void threadBody();
    7276
     77    void platformSaveStateBeforeStarting();
    7378    void platformCollectCPUData(JSC::VM*, ResourceUsageData&);
    7479    void platformCollectMemoryData(JSC::VM*, ResourceUsageData&);
     
    8388    // They should ensure their use of the VM is thread safe.
    8489    JSC::VM* m_vm { nullptr };
     90
     91#if ENABLE(SAMPLING_PROFILER) && OS(DARWIN)
     92    mach_port_t m_samplingProfilerMachThread { MACH_PORT_NULL };
     93#endif
     94
    8595};
    8696
  • trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm

    r240457 r240522  
    3131#include <JavaScriptCore/GCActivityCallback.h>
    3232#include <JavaScriptCore/Heap.h>
     33#include <JavaScriptCore/SamplingProfiler.h>
    3334#include <JavaScriptCore/VM.h>
    3435#include <mach/mach.h>
     
    158159}
    159160
    160 static float cpuUsage()
    161 {
    162     auto machThreads = threadSendRights();
    163 
     161static float cpuUsage(Vector<MachSendRight>& machThreads)
     162{
    164163    float usage = 0;
    165164
     
    206205}
    207206
     207void ResourceUsageThread::platformSaveStateBeforeStarting()
     208{
     209#if ENABLE(SAMPLING_PROFILER)
     210    m_samplingProfilerMachThread = m_vm->samplingProfiler() ? m_vm->samplingProfiler()->machThread() : MACH_PORT_NULL;
     211#endif
     212}
     213
    208214void ResourceUsageThread::platformCollectCPUData(JSC::VM*, ResourceUsageData& data)
    209215{
    210     data.cpu = cpuUsage();
     216    Vector<MachSendRight> threads = threadSendRights();
     217    data.cpu = cpuUsage(threads);
     218
     219    // Remove debugger threads.
     220    mach_port_t resourceUsageMachThread = mach_thread_self();
     221    threads.removeAllMatching([&] (MachSendRight& thread) {
     222        mach_port_t machThread = thread.sendRight();
     223        if (machThread == resourceUsageMachThread)
     224            return true;
     225#if ENABLE(SAMPLING_PROFILER)
     226        if (machThread == m_samplingProfilerMachThread)
     227            return true;
     228#endif
     229        return false;
     230    });
     231
     232    data.cpuExcludingDebuggerThreads = cpuUsage(threads);
    211233}
    212234
  • trunk/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp

    r240457 r240522  
    151151}
    152152
     153void ResourceUsageThread::platformSaveStateBeforeStarting()
     154{
     155}
     156
    153157void ResourceUsageThread::platformCollectCPUData(JSC::VM*, ResourceUsageData& data)
    154158{
    155159    data.cpu = cpuUsage();
     160
     161    // FIXME: Exclude the ResourceUsage thread.
     162    // FIXME: Exclude the SamplingProfiler thread.
     163    data.cpuExcludingDebuggerThreads = data.cpu;
    156164}
    157165
Note: See TracChangeset for help on using the changeset viewer.