Ignore:
Timestamp:
May 9, 2008, 1:18:08 PM (17 years ago)
Author:
[email protected]
Message:

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

Reviewed by Tim.

-<rdar://problem/5770054> JavaScript profiler (10928)
-Add Profile class so that all profiles can be stored and retrieved by
the WebInspector when that time comes.

  • JavaScriptCore.exp: Export the new function signatures.
  • JavaScriptCore.xcodeproj/project.pbxproj: Add the new files to the project
  • profiler/Profile.cpp: Added. This class represents a single run of the profiler. (KJS::Profile::Profile): (KJS::Profile::willExecute): (KJS::Profile::didExecute): (KJS::Profile::printDataInspectorStyle): (KJS::functionNameCountPairComparator): (KJS::Profile::printDataSampleStyle):
  • profiler/Profile.h: Added. Ditto (KJS::Profile::stopProfiling):
  • profiler/Profiler.cpp: Now the profiler keeps track of many profiles but only runs one at a time. (KJS::Profiler::startProfiling): (KJS::Profiler::stopProfiling): (KJS::Profiler::willExecute): (KJS::Profiler::didExecute): (KJS::Profiler::printDataInspectorStyle): (KJS::Profiler::printDataSampleStyle):
  • profiler/Profiler.h: Ditto. (KJS::Profiler::~Profiler): (KJS::Profiler::allProfiles): (KJS::Profiler::clearProfiles):
File:
1 edited

Legend:

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

    r32760 r33007  
    3030#include "Profiler.h"
    3131
     32#include "ExecState.h"
     33#include "function.h"
    3234#include "FunctionCallProfile.h"
    3335#include "JSGlobalObject.h"
    34 #include "ExecState.h"
    35 #include "function.h"
     36#include "Profile.h"
    3637
    3738#include <stdio.h>
     
    5455}
    5556
    56 void Profiler::startProfiling(unsigned pageGroupIdentifier)
     57void Profiler::startProfiling(unsigned pageGroupIdentifier, const UString& title)
    5758{
    5859    if (m_profiling)
     
    6162    m_pageGroupIdentifier = pageGroupIdentifier;
    6263
    63     // FIXME: When multi-threading is supported this will be a vector and calls
    64     // into the profiler will need to know which thread it is executing on.
    65     m_callTree.set(new FunctionCallProfile("Thread_1"));
     64    m_currentProfile.set(new Profile(title));
    6665    m_profiling = true;
    6766}
     
    7069{
    7170    m_profiling = false;
    72     m_callTree->stopProfiling();
     71
     72    if (!m_currentProfile)
     73        return;
     74
     75    m_currentProfile->stopProfiling();
     76    m_allProfiles.append(m_currentProfile.release());
    7377}
    7478
     
    8084    Vector<UString> callStackNames;
    8185    getStackNames(callStackNames, exec, calledFunction);
    82     insertStackNamesInTree(callStackNames);
     86    m_currentProfile->willExecute(callStackNames);
    8387}
    8488
     
    9094    Vector<UString> callStackNames;
    9195    getStackNames(callStackNames, exec, sourceURL, startingLineNumber);
    92     insertStackNamesInTree(callStackNames);
     96    m_currentProfile->willExecute(callStackNames);
    9397}
    9498
     
    100104    Vector<UString> callStackNames;
    101105    getStackNames(callStackNames, exec, calledFunction);
    102     m_callTree->didExecute(callStackNames, 0);
     106    m_currentProfile->didExecute(callStackNames);
    103107}
    104108
     
    110114    Vector<UString> callStackNames;
    111115    getStackNames(callStackNames, exec, sourceURL, startingLineNumber);
    112     m_callTree->didExecute(callStackNames, 0);
    113 }
    114 
    115 void Profiler::insertStackNamesInTree(const Vector<UString>& callStackNames)
    116 {
    117     FunctionCallProfile* callTreeInsertionPoint = 0;
    118     FunctionCallProfile* foundNameInTree = m_callTree.get();
    119     NameIterator callStackLocation = callStackNames.begin();
    120 
    121     while (callStackLocation != callStackNames.end() && foundNameInTree) {
    122         callTreeInsertionPoint = foundNameInTree;
    123         foundNameInTree = callTreeInsertionPoint->findChild(*callStackLocation);
    124         ++callStackLocation;
    125     }
    126 
    127     if (!foundNameInTree) {   // Insert remains of the stack into the call tree.
    128         --callStackLocation;
    129         for (FunctionCallProfile* next; callStackLocation != callStackNames.end(); ++callStackLocation) {
    130             next = new FunctionCallProfile(*callStackLocation);
    131             callTreeInsertionPoint->addChild(next);
    132             callTreeInsertionPoint = next;
    133         }
    134     } else    // We are calling a function that is already in the call tree.
    135         foundNameInTree->willExecute();
     116    m_currentProfile->didExecute(callStackNames);
    136117}
    137118
     
    172153}
    173154
    174 void Profiler::printDataInspectorStyle() const
     155void Profiler::printDataInspectorStyle(unsigned whichProfile) const
    175156{
    176     printf("Profiler Call graph:\n");
    177     m_callTree->printDataInspectorStyle(0);
     157    m_allProfiles[whichProfile]->printDataInspectorStyle();
    178158}
    179159
    180 typedef pair<UString::Rep*, unsigned> NameCountPair;
    181 
    182 static inline bool functionNameCountPairComparator(const NameCountPair a, const NameCountPair b)
     160void Profiler::printDataSampleStyle(unsigned whichProfile) const
    183161{
    184     return a.second > b.second;
    185 }
    186 
    187 void Profiler::printDataSampleStyle() const
    188 {
    189     typedef Vector<NameCountPair> NameCountPairVector;
    190 
    191     FunctionCallHashCount countedFunctions;
    192     printf("Call graph:\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 
    203     printf("\nSort by top of stack, same collapsed (when >= 5):\n");
     162    m_allProfiles[whichProfile]->printDataSampleStyle();
    204163}
    205164
Note: See TracChangeset for help on using the changeset viewer.