Ignore:
Timestamp:
May 15, 2008, 7:51:33 PM (17 years ago)
Author:
[email protected]
Message:

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

Reviewed by Tim.

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

  • Cache some values to save on computing them repetitively. This will be a big savings when we sort since we won't have to walk the tree for every comparison!
  • We cache these values when we end profiling because otherwise we won't know which profile to get the totalTime for the whole profile from without retaining a reference to the head profile or looking up the profile from the list of all profiles.
  • Also it's safe to assume we won't be asked for these values while we are still profiling since the WebInspector only get's profileNodes from profiles that are in the allProfiles() list and a profile is only added to that list after it has finished and these values will no longer change.
  • JavaScriptCore.exp:
  • profiler/ProfileNode.cpp: (KJS::ProfileNode::ProfileNode): (KJS::ProfileNode::stopProfiling): (KJS::ProfileNode::printDataInspectorStyle): (KJS::ProfileNode::printDataSampleStyle): (KJS::ProfileNode::endAndRecordCall):
  • profiler/ProfileNode.h: (KJS::ProfileNode::totalTime): (KJS::ProfileNode::selfTime): (KJS::ProfileNode::totalPercent): (KJS::ProfileNode::selfPercent):
  • profiler/Profiler.cpp: (KJS::Profiler::stopProfiling):
File:
1 edited

Legend:

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

    r33470 r33507  
    3939ProfileNode::ProfileNode(const UString& name)
    4040    : m_functionName(name)
    41     , m_timeSum(0)
     41    , m_totalTime (0.0)
     42    , m_selfTime (0.0)
     43    , m_totalPercent (0.0)
     44    , m_selfPercent (0.0)
    4245    , m_numberOfCalls(0)
    4346{
     
    97100    for (StackIterator it = m_children.begin(); it != endOfChildren; ++it)
    98101        (*it)->stopProfiling();
    99 }
    100102
    101 double ProfileNode::selfTime() const
    102 {
    103     double sumChildrenTime = 0.0;
     103    // Calculate Self time and the percentages once we stop profiling.
     104    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
     105        m_selfTime += (*currentChild)->totalTime();
     106    ASSERT(m_selfTime <= m_totalTime);
     107    m_selfTime = m_totalTime - m_selfTime;
    104108
    105     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    106         sumChildrenTime += (*currentChild)->totalTime();
    107 
    108     ASSERT(sumChildrenTime <= m_timeSum);
    109 
    110     return m_timeSum - sumChildrenTime;
    111 }
    112 
    113 double ProfileNode::totalPercent() const
    114 {
    115     return (m_timeSum / Profiler::profiler()->currentProfile()->totalTime()) * 100.0;
    116 }
    117 
    118 double ProfileNode::selfPercent() const
    119 {
    120     return (selfTime() / Profiler::profiler()->currentProfile()->totalTime()) * 100.0;
     109    m_totalPercent = (m_totalTime / Profiler::profiler()->currentProfile()->totalTime()) * 100.0;
     110    m_selfPercent = (selfTime() / Profiler::profiler()->currentProfile()->totalTime()) * 100.0;
    121111}
    122112
     
    128118            printf("  ");
    129119
    130         printf("%.3fms %s\n", m_timeSum, m_functionName.UTF8String().c_str());
     120        printf("%d SelfTime %.3fms %.3f%% TotalTime %.3fms%.3f%% FunctionName %s\n", m_numberOfCalls, m_selfTime, selfPercent(), m_totalTime, totalPercent(), m_functionName.UTF8String().c_str());
    131121    } else
    132122        printf("%s\n", m_functionName.UTF8String().c_str());
     
    146136    // Print function names
    147137    const char* name = m_functionName.UTF8String().c_str();
    148     double sampleCount = m_timeSum * 1000;
     138    double sampleCount = m_totalTime * 1000;
    149139    if (indentLevel) {
    150140        for (int i = 0; i < indentLevel; ++i)
     
    174164    }
    175165
    176     return m_timeSum;
     166    return m_totalTime;
    177167}
    178168
    179169void ProfileNode::endAndRecordCall()
    180170{
    181     m_timeSum += getCurrentUTCTime() - m_startTime;
     171    m_totalTime += getCurrentUTCTime() - m_startTime;
    182172    m_startTime = 0.0;
    183173
Note: See TracChangeset for help on using the changeset viewer.