Ignore:
Timestamp:
Nov 6, 2011, 3:39:12 AM (14 years ago)
Author:
[email protected]
Message:

JSC should be able to sample itself in a more flexible way than just sampling flags
https://bugs.webkit.org/show_bug.cgi?id=71522

Source/JavaScriptCore:

Reviewed by Gavin Barraclough.

Added a construct that looks like SamplingRegion samplingRegion("name").

(JSC::SamplingRegion::Locker::Locker):
(JSC::SamplingRegion::Locker::~Locker):
(JSC::SamplingRegion::sample):
(JSC::SamplingRegion::dump):
(JSC::SamplingRegion::dumpInternal):
(JSC::SamplingThread::threadStartFunc):

  • bytecode/SamplingTool.h:

(JSC::SamplingRegion::SamplingRegion):
(JSC::SamplingRegion::~SamplingRegion):
(JSC::SamplingRegion::exchangeCurrent):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):

  • dfg/DFGDriver.cpp:

(JSC::DFG::compile):

  • heap/Heap.cpp:

(JSC::Heap::markRoots):
(JSC::Heap::collect):

  • heap/VTableSpectrum.cpp:

(JSC::VTableSpectrum::countVPtr):
(JSC::VTableSpectrum::dump):

  • heap/VTableSpectrum.h:
  • jsc.cpp:

(main):
(runWithScripts):

  • parser/Parser.h:

(JSC::parse):

  • runtime/Executable.cpp:

(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):

  • wtf/Atomics.h:

(WTF::weakCompareAndSwap):

  • wtf/Platform.h:
  • wtf/Spectrum.h: Added.

(WTF::Spectrum::Spectrum):
(WTF::Spectrum::add):
(WTF::Spectrum::get):
(WTF::Spectrum::begin):
(WTF::Spectrum::end):
(WTF::Spectrum::KeyAndCount::KeyAndCount):
(WTF::Spectrum::KeyAndCount::operator<):
(WTF::Spectrum::buildList):

  • wtf/wtf.pri:

Source/JavaScriptGlue:

Reviewed by Gavin Barraclough.

  • ForwardingHeaders/wtf/Spectrum.h: Added.

Source/WebCore:

Reviewed by Gavin Barraclough.

No new tests, since no functionality changed.

  • ForwardingHeaders/wtf/Spectrum.h: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/VTableSpectrum.cpp

    r95901 r99374  
    5050void VTableSpectrum::countVPtr(void* vTablePointer)
    5151{
    52     std::pair<HashMap<void*, unsigned long>::iterator, bool> result = m_map.add(vTablePointer, 1);
    53     if (!result.second)
    54         result.first->second++;
     52    add(vTablePointer);
    5553}
    5654
     
    6058}
    6159
    62 struct VTableAndCount {
    63     void* vtable;
    64     unsigned long count;
    65    
    66     VTableAndCount() { }
    67    
    68     VTableAndCount(void* vtable, unsigned long count)
    69         : vtable(vtable)
    70         , count(count)
    71     {
    72     }
    73    
    74     bool operator<(const VTableAndCount& other) const
    75     {
    76         if (count != other.count)
    77             return count < other.count;
    78         return vtable > other.vtable; // this results in lower-addressed vtables being printed first
    79     }
    80 };
    81 
    8260void VTableSpectrum::dump(FILE* output, const char* comment)
    8361{
    8462    fprintf(output, "%s:\n", comment);
    8563   
    86     HashMap<void*, unsigned long>::iterator begin = m_map.begin();
    87     HashMap<void*, unsigned long>::iterator end = m_map.end();
    88    
    89     Vector<VTableAndCount, 0> list;
    90    
    91     for (HashMap<void*, unsigned long>::iterator iter = begin; iter != end; ++iter)
    92         list.append(VTableAndCount(iter->first, iter->second));
    93    
    94     std::sort(list.begin(), list.end());
     64    Vector<KeyAndCount> list = buildList();
    9565   
    9666    for (size_t index = list.size(); index-- > 0;) {
    97         VTableAndCount item = list.at(index);
     67        KeyAndCount item = list.at(index);
    9868#if PLATFORM(MAC)
    9969        Dl_info info;
    100         if (dladdr(item.vtable, &info)) {
     70        if (dladdr(item.key, &info)) {
    10171            char* findResult = strrchr(info.dli_fname, '/');
    10272            const char* strippedFileName;
     
    10777                strippedFileName = info.dli_fname;
    10878           
    109             fprintf(output, "    %s:%s(%p): %lu\n", strippedFileName, info.dli_sname, item.vtable, item.count);
     79            fprintf(output, "    %s:%s(%p): %lu\n", strippedFileName, info.dli_sname, item.key, item.count);
    11080            continue;
    11181        }
    11282#endif
    113         fprintf(output, "    %p: %lu\n", item.vtable, item.count);
     83        fprintf(output, "    %p: %lu\n", item.key, item.count);
    11484    }
    11585   
Note: See TracChangeset for help on using the changeset viewer.