Skip to content

Commit

Permalink
Merge r266388 - [Linux] Web Inspector: show per thread cpu usage
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=215883

Reviewed by Adrian Perez de Castro.

Source/JavaScriptCore:

Remove platform specific getter machThread() and add thread() to return the Thread instead. The caller knows how
to get the machThread or id from a Thread.

* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::reportTopBytecodes):
(JSC::SamplingProfiler::machThread): Deleted.
* runtime/SamplingProfiler.h:
(JSC::SamplingProfiler::thread):

Source/WebCore:

Get per thread CPU usage and information to fill ResourceUsageData in Linux.

* page/ResourceUsageThread.h:
* page/cocoa/ResourceUsageThreadCocoa.mm:
(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting): Update to new API in SamplingProfiler.
* page/linux/ResourceUsageThreadLinux.cpp:
(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting): Initialize m_samplingProfilerThreadID.
(WebCore::threadInfoMap):
(WebCore::threadCPUUsage):
(WebCore::collectCPUUsage):
(WebCore::ResourceUsageThread::platformCollectCPUData):
(WebCore::cpuUsage): Deleted.

Source/WTF:

Add API to get the thread ID in Linux platform.

* wtf/Threading.cpp:
(WTF::Thread::initializeInThread):
* wtf/Threading.h:
(WTF::Thread::id const):
* wtf/ThreadingPrimitives.h:
* wtf/posix/ThreadingPOSIX.cpp:
(WTF::Thread::currentID):
  • Loading branch information
carlosgcampos committed Sep 4, 2020
1 parent 4b72b4e commit 3e3e9cd
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 35 deletions.
16 changes: 16 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,19 @@
2020-09-01 Carlos Garcia Campos <cgarcia@igalia.com>

[Linux] Web Inspector: show per thread cpu usage
https://bugs.webkit.org/show_bug.cgi?id=215883

Reviewed by Adrian Perez de Castro.

Remove platform specific getter machThread() and add thread() to return the Thread instead. The caller knows how
to get the machThread or id from a Thread.

* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::reportTopBytecodes):
(JSC::SamplingProfiler::machThread): Deleted.
* runtime/SamplingProfiler.h:
(JSC::SamplingProfiler::thread):

2020-08-14 Caio Lima <ticaiolima@gmail.com>

[ARMv7][JSC] Conservative GC is not considering `r7` as a root
Expand Down
9 changes: 2 additions & 7 deletions Source/JavaScriptCore/runtime/SamplingProfiler.cpp
Expand Up @@ -1141,15 +1141,10 @@ void SamplingProfiler::reportTopBytecodes(PrintStream& out)
}
}

#if OS(DARWIN)
mach_port_t SamplingProfiler::machThread()
Thread* SamplingProfiler::thread() const
{
if (!m_thread)
return MACH_PORT_NULL;

return m_thread->machThread();
return m_thread.get();
}
#endif

} // namespace JSC

Expand Down
4 changes: 1 addition & 3 deletions Source/JavaScriptCore/runtime/SamplingProfiler.h
Expand Up @@ -193,9 +193,7 @@ class SamplingProfiler : public ThreadSafeRefCounted<SamplingProfiler> {
JS_EXPORT_PRIVATE void reportTopBytecodes();
JS_EXPORT_PRIVATE void reportTopBytecodes(PrintStream&);

#if OS(DARWIN)
JS_EXPORT_PRIVATE mach_port_t machThread();
#endif
JS_EXPORT_PRIVATE Thread* thread() const;

private:
void createThreadIfNecessary(const AbstractLocker&);
Expand Down
17 changes: 17 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,20 @@
2020-09-01 Carlos Garcia Campos <cgarcia@igalia.com>

[Linux] Web Inspector: show per thread cpu usage
https://bugs.webkit.org/show_bug.cgi?id=215883

Reviewed by Adrian Perez de Castro.

Add API to get the thread ID in Linux platform.

* wtf/Threading.cpp:
(WTF::Thread::initializeInThread):
* wtf/Threading.h:
(WTF::Thread::id const):
* wtf/ThreadingPrimitives.h:
* wtf/posix/ThreadingPOSIX.cpp:
(WTF::Thread::currentID):

2020-08-27 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Include the run loop source name in frame rendering timeline
Expand Down
4 changes: 4 additions & 0 deletions Source/WTF/wtf/Threading.cpp
Expand Up @@ -138,6 +138,10 @@ void Thread::initializeInThread()
m_currentAtomStringTable = &sharedStringTable.get();
}
#endif

#if OS(LINUX)
m_id = currentID();
#endif
}

void Thread::entryPoint(NewThreadContext* newThreadContext)
Expand Down
7 changes: 7 additions & 0 deletions Source/WTF/wtf/Threading.h
Expand Up @@ -157,6 +157,10 @@ class Thread : public ThreadSafeRefCounted<Thread> {
WTF_EXPORT_PRIVATE size_t getRegisters(PlatformRegisters&);

#if USE(PTHREADS)
#if OS(LINUX)
WTF_EXPORT_PRIVATE static ThreadIdentifier currentID();
ThreadIdentifier id() const { return m_id; }
#endif
WTF_EXPORT_PRIVATE bool signal(int signalNumber);
#endif

Expand Down Expand Up @@ -329,6 +333,9 @@ class Thread : public ThreadSafeRefCounted<Thread> {
#elif OS(DARWIN)
mach_port_t m_platformThread { MACH_PORT_NULL };
#elif USE(PTHREADS)
#if OS(LINUX)
ThreadIdentifier m_id { 0 };
#endif
PlatformRegisters* m_platformRegisters { nullptr };
unsigned m_suspendCount { 0 };
#endif
Expand Down
3 changes: 3 additions & 0 deletions Source/WTF/wtf/ThreadingPrimitives.h
Expand Up @@ -57,6 +57,9 @@ using PlatformThreadHandle = pthread_t;
using PlatformMutex = pthread_mutex_t;
using PlatformCondition = pthread_cond_t;
using ThreadSpecificKey = pthread_key_t;
#if OS(LINUX)
using ThreadIdentifier = pid_t;
#endif
#elif OS(WINDOWS)
using ThreadIdentifier = uint32_t;
using PlatformThreadHandle = HANDLE;
Expand Down
11 changes: 11 additions & 0 deletions Source/WTF/wtf/posix/ThreadingPOSIX.cpp
Expand Up @@ -68,6 +68,10 @@
#include <mach/thread_switch.h>
#endif

#if OS(LINUX)
#include <sys/syscall.h>
#endif

namespace WTF {

static Lock globalSuspendLock;
Expand Down Expand Up @@ -187,6 +191,13 @@ void Thread::initializePlatformThreading()
#endif
}

#if OS(LINUX)
ThreadIdentifier Thread::currentID()
{
return static_cast<ThreadIdentifier>(syscall(SYS_gettid));
}
#endif

void Thread::initializeCurrentThreadEvenIfNonWTFCreated()
{
#if !OS(DARWIN)
Expand Down
20 changes: 20 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
2020-09-01 Carlos Garcia Campos <cgarcia@igalia.com>

[Linux] Web Inspector: show per thread cpu usage
https://bugs.webkit.org/show_bug.cgi?id=215883

Reviewed by Adrian Perez de Castro.

Get per thread CPU usage and information to fill ResourceUsageData in Linux.

* page/ResourceUsageThread.h:
* page/cocoa/ResourceUsageThreadCocoa.mm:
(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting): Update to new API in SamplingProfiler.
* page/linux/ResourceUsageThreadLinux.cpp:
(WebCore::ResourceUsageThread::platformSaveStateBeforeStarting): Initialize m_samplingProfilerThreadID.
(WebCore::threadInfoMap):
(WebCore::threadCPUUsage):
(WebCore::collectCPUUsage):
(WebCore::ResourceUsageThread::platformCollectCPUData):
(WebCore::cpuUsage): Deleted.

2020-08-27 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Include the run loop source name in frame rendering timeline
Expand Down
6 changes: 5 additions & 1 deletion Source/WebCore/page/ResourceUsageThread.h
Expand Up @@ -88,8 +88,12 @@ class ResourceUsageThread {
// They should ensure their use of the VM is thread safe.
JSC::VM* m_vm { nullptr };

#if ENABLE(SAMPLING_PROFILER) && OS(DARWIN)
#if ENABLE(SAMPLING_PROFILER)
#if OS(DARWIN)
mach_port_t m_samplingProfilerMachThread { MACH_PORT_NULL };
#elif OS(LINUX)
pid_t m_samplingProfilerThreadID { 0 };
#endif
#endif

};
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm
Expand Up @@ -136,7 +136,12 @@ static unsigned categoryForVMTag(unsigned tag)
void ResourceUsageThread::platformSaveStateBeforeStarting()
{
#if ENABLE(SAMPLING_PROFILER)
m_samplingProfilerMachThread = m_vm->samplingProfiler() ? m_vm->samplingProfiler()->machThread() : MACH_PORT_NULL;
m_samplingProfilerMachThread = MACH_PORT_NULL;

if (auto* profiler = m_vm->samplingProfiler()) {
if (auto* thread = profiler->thread())
m_samplingProfilerMachThread = thread->machThread();
}
#endif
}

Expand Down

0 comments on commit 3e3e9cd

Please sign in to comment.