Changeset 43047 in webkit for trunk/JavaScriptCore/jsc.cpp


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/jsc.cpp

    r42989 r43047  
    7878static NO_RETURN JSValuePtr functionQuit(ExecState*, JSObject*, JSValuePtr, const ArgList&);
    7979
     80#if ENABLE(SAMPLING_FLAGS)
     81static JSValuePtr functionSetSamplingFlag(ExecState*, JSObject*, JSValuePtr, const ArgList&);
     82static JSValuePtr functionClearSamplingFlag(ExecState*, JSObject*, JSValuePtr, const ArgList&);
     83#endif
     84
    8085struct Script {
    8186    bool isFile;
     
    181186    putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "readline"), functionReadline));
    182187
     188#if ENABLE(SAMPLING_FLAGS)
     189    putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "setSamplingFlag"), functionSetSamplingFlag));
     190    putDirectFunction(globalExec(), new (globalExec()) PrototypeFunction(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "clearSamplingFlag"), functionClearSamplingFlag));
     191#endif
     192
    183193    JSObject* array = constructEmptyArray(globalExec());
    184194    for (size_t i = 0; i < arguments.size(); ++i)
     
    251261    return result.value();
    252262}
     263
     264#if ENABLE(SAMPLING_FLAGS)
     265JSValuePtr functionSetSamplingFlag(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
     266{
     267    unsigned flag = static_cast<unsigned>(args.at(0).toNumber(exec));
     268
     269    // Sanitize the input into the range 1..32.
     270    if (flag > 32)
     271        flag &= 31;
     272    if (!flag)
     273        flag = 32;
     274
     275    SamplingFlags::setFlag(flag);
     276
     277    return jsNull();
     278}
     279
     280JSValuePtr functionClearSamplingFlag(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
     281{
     282    unsigned flag = static_cast<unsigned>(args.at(0).toNumber(exec));
     283
     284    // Sanitize the input into the range 1..32.
     285    if (flag > 32)
     286        flag &= 31;
     287    if (!flag)
     288        flag = 32;
     289
     290    SamplingFlags::clearFlag(flag);
     291
     292    return jsNull();
     293}
     294#endif
    253295
    254296JSValuePtr functionReadline(ExecState* exec, JSObject*, JSValuePtr, const ArgList&)
     
    340382    Interpreter* interpreter = globalObject->globalData()->interpreter;
    341383    interpreter->setSampler(new SamplingTool(interpreter));
     384    interpreter->sampler()->setup();
     385#endif
     386#if ENABLE(SAMPLING_FLAGS)
     387    SamplingFlags::start();
    342388#endif
    343389
     
    354400        }
    355401
    356 #if ENABLE(OPCODE_SAMPLING)
    357         interpreter->sampler()->start();
    358 #endif
     402#if ENABLE(SAMPLING_THREAD)
     403        SamplingThread::start();
     404#endif
     405
    359406        Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script, fileName));
    360407        success = success && completion.complType() != Throw;
     
    366413        }
    367414
     415#if ENABLE(SAMPLING_THREAD)
     416        SamplingThread::stop();
     417#endif
     418
    368419        globalObject->globalExec()->clearException();
    369 
    370 #if ENABLE(OPCODE_SAMPLING)
    371         interpreter->sampler()->stop();
    372 #endif
    373     }
    374 
     420    }
     421
     422#if ENABLE(SAMPLING_FLAGS)
     423    SamplingFlags::stop();
     424#endif
    375425#if ENABLE(OPCODE_SAMPLING)
    376426    interpreter->sampler()->dump(globalObject->globalExec());
Note: See TracChangeset for help on using the changeset viewer.