Ignore:
Timestamp:
May 1, 2008, 9:32:32 AM (17 years ago)
Author:
[email protected]
Message:

2008-05-01 Kevin McCullough <[email protected]>

Reviewed by Darin.

<rdar://problem/5770054> JavaScript profiler (10928)

  • Fix "sample" output so that it can be imported into Instruments
  • Also keep track of number of times a function is profiled.
  • JavaScriptCore.xcodeproj/project.pbxproj: Add StrHash.h which needed to be pulled out of identifier.cpp so that it could be used by the profiler and identifiers.
  • kjs/identifier.cpp: Ditto.
  • profiler/FunctionCallProfile.cpp: (KJS::FunctionCallProfile::printDataInspectorStyle): Inspector style printing should show microseconds. (KJS::FunctionCallProfile::printDataSampleStyle): Sample style printing now counts the number of times a function is in the stack tree and does not print microseconds since that does not make sense for a sampler.
  • profiler/FunctionCallProfile.h: Keep track of number of times a function is profiled. (KJS::FunctionCallProfile::numberOfCalls):
  • profiler/Profiler.cpp: (KJS::functionNameCountPairComparator): Comparator for sort function in printDataSampleStyle. (KJS::Profiler::printDataSampleStyle): Print the number of times that a function is listed in the stack tree in order of most times listed.
  • wtf/HashCountedSet.h: Added copyToVector since it didn't exist and is a more standard way to copy a HashSet to a Vector. I added on variant that takes a pair as the Vector's type and so the HashCountedSet simply fills in that pair with its internal pair, and another variant that takes a Vector of the type of the HashCountedSet and only fills in the Vector with the first element of the pair. (WTF::copyToVector):
  • wtf/StrHash.h: Added. (WTF::):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/profiler/Profiler.cpp

    r32495 r32760  
    178178}
    179179
     180typedef pair<UString::Rep*, unsigned> NameCountPair;
     181
     182static inline bool functionNameCountPairComparator(const NameCountPair a, const NameCountPair b)
     183{
     184    return a.second > b.second;
     185}
     186
    180187void Profiler::printDataSampleStyle() const
    181188{
     189    typedef Vector<NameCountPair> NameCountPairVector;
     190
     191    FunctionCallHashCount countedFunctions;
    182192    printf("Call graph:\n");
    183     m_callTree->printDataSampleStyle(0);
    184 
    185     // FIXME: Since no one seems to understand this part of sample's output I will implement it when I have a better idea of what it's meant to be doing.
    186     printf("\nTotal number in stack (recursive counted multiple, when >=5):\n");
     193    m_callTree->printDataSampleStyle(0, countedFunctions);
     194
     195    printf("\nTotal number in stack:\n");
     196    NameCountPairVector sortedFunctions(countedFunctions.size());
     197    copyToVector(countedFunctions, sortedFunctions);
     198
     199    std::sort(sortedFunctions.begin(), sortedFunctions.end(), functionNameCountPairComparator);
     200    for (NameCountPairVector::iterator it = sortedFunctions.begin(); it != sortedFunctions.end(); ++it)
     201        printf("        %-12d%s\n", (*it).second, UString((*it).first).UTF8String().c_str());
     202
    187203    printf("\nSort by top of stack, same collapsed (when >= 5):\n");
    188204}
Note: See TracChangeset for help on using the changeset viewer.