Changeset 42808 in webkit for trunk/JavaScriptCore/profiler/HeavyProfile.cpp
- Timestamp:
- Apr 23, 2009, 8:47:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/profiler/HeavyProfile.cpp
r36263 r42808 1 /*2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions6 * are met:7 * 1. Redistributions of source code must retain the above copyright8 * notice, this list of conditions and the following disclaimer.9 * 2. Redistributions in binary form must reproduce the above copyright10 * notice, this list of conditions and the following disclaimer in the11 * documentation and/or other materials provided with the distribution.12 *13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24 */25 26 #include "config.h"27 #include "HeavyProfile.h"28 29 #include "TreeProfile.h"30 31 namespace JSC {32 33 HeavyProfile::HeavyProfile(TreeProfile* treeProfile)34 : Profile(treeProfile->title(), treeProfile->uid())35 {36 m_treeProfile = treeProfile;37 head()->setTotalTime(m_treeProfile->head()->actualTotalTime());38 head()->setSelfTime(m_treeProfile->head()->actualSelfTime());39 generateHeavyStructure();40 }41 42 void HeavyProfile::generateHeavyStructure()43 {44 ProfileNode* treeHead = m_treeProfile->head();45 ProfileNode* currentNode = treeHead->firstChild();46 for (ProfileNode* nextNode = currentNode; nextNode; nextNode = nextNode->firstChild())47 currentNode = nextNode;48 49 // For each node50 HashMap<CallIdentifier, ProfileNode*> foundChildren;51 while (currentNode && currentNode != treeHead) {52 ProfileNode* child = foundChildren.get(currentNode->callIdentifier());53 if (child) // currentNode is in the set already54 mergeProfiles(child, currentNode);55 else { // currentNode is not in the set56 child = addNode(currentNode);57 foundChildren.set(currentNode->callIdentifier(), child);58 }59 60 currentNode = currentNode->traverseNextNodePostOrder();61 }62 }63 64 ProfileNode* HeavyProfile::addNode(ProfileNode* currentNode)65 {66 RefPtr<ProfileNode> node = ProfileNode::create(head(), currentNode);67 head()->addChild(node);68 69 addAncestorsAsChildren(currentNode->parent(), node.get());70 return node.get();71 }72 73 void HeavyProfile::mergeProfiles(ProfileNode* heavyProfileHead, ProfileNode* treeProfileHead)74 {75 ASSERT_ARG(heavyProfileHead, heavyProfileHead);76 ASSERT_ARG(treeProfileHead, treeProfileHead);77 78 ProfileNode* currentTreeNode = treeProfileHead;79 ProfileNode* currentHeavyNode = heavyProfileHead;80 ProfileNode* previousHeavyNode = 0;81 82 while (currentHeavyNode) {83 previousHeavyNode = currentHeavyNode;84 85 currentHeavyNode->setTotalTime(currentHeavyNode->actualTotalTime() + currentTreeNode->actualTotalTime());86 currentHeavyNode->setSelfTime(currentHeavyNode->actualSelfTime() + currentTreeNode->actualSelfTime());87 currentHeavyNode->setNumberOfCalls(currentHeavyNode->numberOfCalls() + currentTreeNode->numberOfCalls());88 89 currentTreeNode = currentTreeNode->parent();90 currentHeavyNode = currentHeavyNode->findChild(currentTreeNode);91 }92 93 // If currentTreeNode is null then we already have the whole tree we wanted to copy.94 // If not we need to copy the subset of the tree that remains different between the two.95 if (currentTreeNode)96 addAncestorsAsChildren(currentTreeNode, previousHeavyNode);97 }98 99 void HeavyProfile::addAncestorsAsChildren(ProfileNode* getFrom, ProfileNode* addTo)100 {101 ASSERT_ARG(getFrom, getFrom);102 ASSERT_ARG(addTo, addTo);103 104 if (!getFrom->head())105 return;106 107 RefPtr<ProfileNode> currentNode = addTo;108 for (ProfileNode* treeAncestor = getFrom; treeAncestor && treeAncestor != getFrom->head(); treeAncestor = treeAncestor->parent()) {109 RefPtr<ProfileNode> newChild = ProfileNode::create(currentNode->head(), treeAncestor);110 currentNode->addChild(newChild);111 currentNode = newChild.release();112 }113 }114 115 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.