diff options
Diffstat (limited to 'Source/JavaScriptCore/tools/CodeProfiling.cpp')
-rw-r--r-- | Source/JavaScriptCore/tools/CodeProfiling.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Source/JavaScriptCore/tools/CodeProfiling.cpp b/Source/JavaScriptCore/tools/CodeProfiling.cpp index d927a49f6..f11603854 100644 --- a/Source/JavaScriptCore/tools/CodeProfiling.cpp +++ b/Source/JavaScriptCore/tools/CodeProfiling.cpp @@ -33,6 +33,10 @@ #include <signal.h> #endif +#if OS(LINUX) +#include <sys/time.h> +#endif + namespace JSC { volatile CodeProfile* CodeProfiling::s_profileStack = 0; @@ -44,7 +48,7 @@ WTF::MetaAllocatorTracker* CodeProfiling::s_tracker = 0; #pragma clang diagnostic ignored "-Wmissing-noreturn" #endif -#if PLATFORM(MAC) && CPU(X86_64) +#if (PLATFORM(MAC) && CPU(X86_64)) || (OS(LINUX) && CPU(X86)) // Helper function to start & stop the timer. // Presently we're using the wall-clock timer, since this seems to give the best results. static void setProfileTimer(unsigned usec) @@ -69,6 +73,13 @@ static void profilingTimer(int, siginfo_t*, void* uap) CodeProfiling::sample(reinterpret_cast<void*>(context->__ss.__rip), reinterpret_cast<void**>(context->__ss.__rbp)); } +#elif OS(LINUX) && CPU(X86) +static void profilingTimer(int, siginfo_t*, void* uap) +{ + mcontext_t context = static_cast<ucontext_t*>(uap)->uc_mcontext; + CodeProfiling::sample(reinterpret_cast<void*>(context.gregs[REG_EIP]), + reinterpret_cast<void**>(context.gregs[REG_EBP])); +} #endif // Callback triggered when the timer is fired. @@ -132,10 +143,10 @@ void CodeProfiling::begin(const SourceCode& source) if (alreadyProfiling) return; -#if PLATFORM(MAC) && CPU(X86_64) +#if (PLATFORM(MAC) && CPU(X86_64)) || (OS(LINUX) && CPU(X86)) // Regsiter a signal handler & itimer. struct sigaction action; - action.sa_sigaction = reinterpret_cast<void (*)(int, struct __siginfo *, void *)>(profilingTimer); + action.sa_sigaction = reinterpret_cast<void (*)(int, siginfo_t *, void *)>(profilingTimer); sigfillset(&action.sa_mask); action.sa_flags = SA_SIGINFO; sigaction(SIGALRM, &action, 0); @@ -156,7 +167,7 @@ void CodeProfiling::end() if (s_profileStack) return; -#if PLATFORM(MAC) && CPU(X86_64) +#if (PLATFORM(MAC) && CPU(X86_64)) || (OS(LINUX) && CPU(X86)) // Stop profiling setProfileTimer(0); #endif |