https://bugs.webkit.org/show_bug.cgi?id=193796
<rdar://problem/
47532910>
Patch by Joseph Pecoraro <pecoraro@apple.com> 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.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240522
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2019-01-25 Joseph Pecoraro <pecoraro@apple.com>
+
+ Web Inspector: Exclude Debugger Threads from CPU Usage values in Web Inspector
+ https://bugs.webkit.org/show_bug.cgi?id=193796
+ <rdar://problem/47532910>
+
+ Reviewed by Devin Rousso.
+
+ * 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.
+
2019-01-25 Alex Christensen <achristensen@webkit.org>
Fix Windows build after r240511
}
}
+#if OS(DARWIN)
+mach_port_t SamplingProfiler::machThread()
+{
+ if (!m_thread)
+ return MACH_PORT_NULL;
+
+ return m_thread->machThread();
+}
+#endif
+
} // namespace JSC
namespace WTF {
JS_EXPORT_PRIVATE void reportTopBytecodes();
JS_EXPORT_PRIVATE void reportTopBytecodes(PrintStream&);
+#if OS(DARWIN)
+ JS_EXPORT_PRIVATE mach_port_t machThread();
+#endif
+
private:
void createThreadIfNecessary(const AbstractLocker&);
void timerLoop();
+2019-01-25 Joseph Pecoraro <pecoraro@apple.com>
+
+ Web Inspector: Exclude Debugger Threads from CPU Usage values in Web Inspector
+ https://bugs.webkit.org/show_bug.cgi?id=193796
+ <rdar://problem/47532910>
+
+ Reviewed by Devin Rousso.
+
+ * 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.
+
2019-01-25 Zalan Bujtas <zalan@apple.com>
Remove FrameView::m_significantRenderedTextMilestonePending
{
auto event = Protocol::CPUProfiler::Event::create()
.setTimestamp(m_environment.executionStopwatch()->elapsedTimeSince(data.timestamp).seconds())
- .setUsage(data.cpu)
+ .setUsage(data.cpuExcludingDebuggerThreads)
.release();
m_frontendDispatcher->trackingUpdate(WTFMove(event));
constexpr ResourceUsageData() = default;
float cpu { 0 };
+ float cpuExcludingDebuggerThreads { 0 };
size_t totalDirtySize { 0 };
size_t totalExternalSize { 0 };
std::array<MemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories { {
#include <wtf/Noncopyable.h>
#include <wtf/Threading.h>
+#if OS(DARWIN)
+#include <mach/mach.h>
+#endif
+
namespace JSC {
class VM;
}
void createThreadIfNeeded();
void threadBody();
+ void platformSaveStateBeforeStarting();
void platformCollectCPUData(JSC::VM*, ResourceUsageData&);
void platformCollectMemoryData(JSC::VM*, ResourceUsageData&);
// Platforms may need to access some data from the common VM.
// They should ensure their use of the VM is thread safe.
JSC::VM* m_vm { nullptr };
+
+#if ENABLE(SAMPLING_PROFILER) && OS(DARWIN)
+ mach_port_t m_samplingProfilerMachThread { MACH_PORT_NULL };
+#endif
+
};
#if PLATFORM(COCOA)
#include <JavaScriptCore/GCActivityCallback.h>
#include <JavaScriptCore/Heap.h>
+#include <JavaScriptCore/SamplingProfiler.h>
#include <JavaScriptCore/VM.h>
#include <mach/mach.h>
#include <mach/vm_statistics.h>
return machThreads;
}
-static float cpuUsage()
+static float cpuUsage(Vector<MachSendRight>& machThreads)
{
- auto machThreads = threadSendRights();
-
float usage = 0;
for (auto& machThread : machThreads) {
}
}
+void ResourceUsageThread::platformSaveStateBeforeStarting()
+{
+#if ENABLE(SAMPLING_PROFILER)
+ m_samplingProfilerMachThread = m_vm->samplingProfiler() ? m_vm->samplingProfiler()->machThread() : MACH_PORT_NULL;
+#endif
+}
+
void ResourceUsageThread::platformCollectCPUData(JSC::VM*, ResourceUsageData& data)
{
- data.cpu = cpuUsage();
+ Vector<MachSendRight> threads = threadSendRights();
+ data.cpu = cpuUsage(threads);
+
+ // Remove debugger threads.
+ mach_port_t resourceUsageMachThread = mach_thread_self();
+ threads.removeAllMatching([&] (MachSendRight& thread) {
+ mach_port_t machThread = thread.sendRight();
+ if (machThread == resourceUsageMachThread)
+ return true;
+#if ENABLE(SAMPLING_PROFILER)
+ if (machThread == m_samplingProfilerMachThread)
+ return true;
+#endif
+ return false;
+ });
+
+ data.cpuExcludingDebuggerThreads = cpuUsage(threads);
}
void ResourceUsageThread::platformCollectMemoryData(JSC::VM* vm, ResourceUsageData& data)
return clampTo<float>(usage, 0, 100);
}
+void ResourceUsageThread::platformSaveStateBeforeStarting()
+{
+}
+
void ResourceUsageThread::platformCollectCPUData(JSC::VM*, ResourceUsageData& data)
{
data.cpu = cpuUsage();
+
+ // FIXME: Exclude the ResourceUsage thread.
+ // FIXME: Exclude the SamplingProfiler thread.
+ data.cpuExcludingDebuggerThreads = data.cpu;
}
void ResourceUsageThread::platformCollectMemoryData(JSC::VM* vm, ResourceUsageData& data)