From ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 24 Feb 2012 16:36:50 +0100 Subject: Imported WebKit commit bb52bf3c0119e8a128cd93afe5572413a8617de9 (http://svn.webkit.org/repository/webkit/trunk@108790) --- Source/JavaScriptCore/tools/CodeProfiling.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'Source/JavaScriptCore/tools/CodeProfiling.cpp') 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 #endif +#if OS(LINUX) +#include +#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(context->__ss.__rip), reinterpret_cast(context->__ss.__rbp)); } +#elif OS(LINUX) && CPU(X86) +static void profilingTimer(int, siginfo_t*, void* uap) +{ + mcontext_t context = static_cast(uap)->uc_mcontext; + CodeProfiling::sample(reinterpret_cast(context.gregs[REG_EIP]), + reinterpret_cast(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(profilingTimer); + action.sa_sigaction = reinterpret_cast(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 -- cgit v1.2.1