Ignore:
Timestamp:
Apr 30, 2009, 12:52:27 AM (16 years ago)
Author:
[email protected]
Message:

2009-04-30 Gavin Barraclough <[email protected]>

Reviewed by Maciej Stachowiak.

Add SamplingFlags mechanism.

This mechanism allows fine-grained JSC and JavaScript program aware
performance measurement. The mechanism provides a set of 32 flags,
numbered #1..#32. Flag #16 is initially set, and all other flags
are cleared. Flags may be set and cleared from within

Enable by setting ENABLE_SAMPLING_FLAGS to 1 in wtf/Platform.h.
Disabled by default, no performance impact. Flags may be modified
by calling SamplingFlags::setFlag() and SamplingFlags::clearFlag()
from within JSC implementation, or by calling setSamplingFlag() and
clearSamplingFlag() from JavaScript.

The flags are sampled with a frequency of 10000Hz, and the highest
set flag in recorded, allowing multiple events to be measured (with
the highest flag number representing the highest priority).

Disabled by default; no performance impact.

  • JavaScriptCore.exp:
  • bytecode/SamplingTool.cpp: (JSC::SamplingFlags::sample): (JSC::SamplingFlags::start): (JSC::SamplingFlags::stop): (JSC::SamplingThread::threadStartFunc): (JSC::SamplingThread::start): (JSC::SamplingThread::stop): (JSC::ScopeSampleRecord::sample): (JSC::SamplingTool::doRun): (JSC::SamplingTool::sample): (JSC::SamplingTool::start): (JSC::SamplingTool::stop):
  • bytecode/SamplingTool.h: (JSC::SamplingFlags::setFlag): (JSC::SamplingFlags::clearFlag): (JSC::SamplingTool::SamplingTool):
  • jsc.cpp: (GlobalObject::GlobalObject): (functionSetSamplingFlag): (functionClearSamplingFlag): (runWithScripts):
  • wtf/Platform.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/bytecode/SamplingTool.h

    r39993 r43047  
    3939namespace JSC {
    4040
     41    class SamplingFlags {
     42    public:
     43        static void start();
     44        static void stop();
     45
     46#if ENABLE(SAMPLING_FLAGS)
     47        static void setFlag(unsigned flag)
     48        {
     49            ASSERT(flag >= 1);
     50            ASSERT(flag <= 32);
     51            s_flags |= 1u << (flag - 1);
     52        }
     53
     54        static void clearFlag(unsigned flag)
     55        {
     56            ASSERT(flag >= 1);
     57            ASSERT(flag <= 32);
     58            s_flags &= ~(1u << (flag - 1));
     59        }
     60
     61        static void sample();
     62#endif
     63    private:
     64        static uint32_t s_flags;
     65#if ENABLE(SAMPLING_FLAGS)
     66        static uint64_t s_flagCounts[33];
     67#endif
     68    };
     69
    4170    class CodeBlock;
    4271    class ExecState;
     
    74103    typedef WTF::HashMap<ScopeNode*, ScopeSampleRecord*> ScopeSampleRecordMap;
    75104
     105    class SamplingThread {
     106    public:
     107        // Sampling thread state.
     108        static bool s_running;
     109        static unsigned s_hertz;
     110        static ThreadIdentifier s_samplingThread;
     111
     112        static void start(unsigned hertz=10000);
     113        static void stop();
     114
     115        static void* threadStartFunc(void*);
     116    };
     117
    76118    class SamplingTool {
    77119    public:
     
    128170        SamplingTool(Interpreter* interpreter)
    129171            : m_interpreter(interpreter)
    130             , m_running(false)
    131172            , m_codeBlock(0)
    132173            , m_sample(0)
     
    144185        }
    145186
    146         void start(unsigned hertz=10000);
    147         void stop();
     187        void setup();
    148188        void dump(ExecState*);
    149189
     
    165205            return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(vPC) | (static_cast<intptr_t>(inCTIFunction) << 1) | static_cast<intptr_t>(inHostFunction));
    166206        }
     207
     208        static void sample();
    167209
    168210    private:
     
    185227            CodeBlock* m_codeBlock;
    186228        };
    187        
    188         static void* threadStartFunc(void*);
    189         void run();
     229
     230        void doRun();
     231        static SamplingTool* s_samplingTool;
    190232       
    191233        Interpreter* m_interpreter;
    192234       
    193         // Sampling thread state.
    194         bool m_running;
    195         unsigned m_hertz;
    196         ThreadIdentifier m_samplingThread;
    197 
    198235        // State tracked by the main thread, used by the sampling thread.
    199236        CodeBlock* m_codeBlock;
Note: See TracChangeset for help on using the changeset viewer.