void CVCDlg::InitDeviceComboBox() { ProfileNode* pRoot = ProfileMgr::GetInstance()->GetRootProfile(); int nChildCount = ((pRoot == NULL) ? 0 : pRoot->GetChildCount()); std::string szText; AttribMap* pAttribMap = NULL; for(int i = 0; i < nChildCount; i++) { ProfileNode* pProfile = (ProfileNode*)pRoot->GetChild(i); pAttribMap = (AttribMap*)pProfile->GetData(); if(!pAttribMap->Get(PF_ATTRIB_DESC, szText)) { pAttribMap->Get(PF_ATTRIB_NAME, szText); } LIST_ITEM item; item.strText = CFL_A2T(szText.c_str()); item.vpItemData = pProfile; m_deviceComboBox.AddItem(&item); } if(nChildCount > 0) { m_deviceComboBox.SetCurSel(0); OnCategorySelChanged(); } }
static JSValueRef getLineNumber(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) { if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass())) return JSValueMakeUndefined(ctx); ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject)); return JSValueMakeNumber(ctx, profileNode->lineNumber()); }
static JSValueRef getURL(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) { if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass())) return JSValueMakeUndefined(ctx); ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject)); JSRetainPtr<JSStringRef> urlString(Adopt, JSStringCreateWithCharacters(profileNode->url().data(), profileNode->url().size())); return JSValueMakeString(ctx, urlString.get()); }
ProfileNode* ProfileNode::traverseNextNodePostOrder() const { ProfileNode* next = m_nextSibling; if (!next) return m_parent; while (ProfileNode* firstChild = next->firstChild()) next = firstChild; return next; }
static JSValueRef getSelfTime(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) { KJS::JSLock lock(false); if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass())) return JSValueMakeUndefined(ctx); ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject)); return JSValueMakeNumber(ctx, profileNode->selfTime()); }
// The console.profile that started this ProfileGenerator will be the first child. void ProfileGenerator::removeProfileStart() { ProfileNode* currentNode = nullptr; for (ProfileNode* next = m_rootNode.get(); next; next = next->firstChild()) currentNode = next; if (currentNode->callIdentifier().functionName() != "profile") return; currentNode->parent()->removeChild(currentNode); }
void Profile::focus(const ProfileNode* profileNode) { if (!profileNode || !m_head) return; bool processChildren; const CallIdentifier& callIdentifier = profileNode->callIdentifier(); for (ProfileNode* currentNode = m_head.get(); currentNode; currentNode = currentNode->traverseNextNodePreOrder(processChildren)) processChildren = currentNode->focus(callIdentifier); // Set the visible time of all nodes so that the %s display correctly. forEach(&ProfileNode::calculateVisibleTotalTime); }
void ProfileNode::setTreeVisible(ProfileNode* node, bool visible) { ProfileNode* nodeParent = node->parent(); ProfileNode* nodeSibling = node->nextSibling(); node->setParent(0); node->setNextSibling(0); for (ProfileNode* currentNode = node; currentNode; currentNode = currentNode->traverseNextNodePreOrder()) currentNode->setVisible(visible); node->setParent(nodeParent); node->setNextSibling(nodeSibling); }
void Profile::beginNode(const char* name) { ProfileNode* parent = m_stack.back(); ProfileNode* node = parent->findChild(name); if (!node) { parent->m_children.push_back(ProfileNode(name)); node = &(parent->m_children.back()); } beginNode(*node); }
void Profile::exclude(const ProfileNode* profileNode) { if (!profileNode || !m_head) return; const CallIdentifier& callIdentifier = profileNode->callIdentifier(); for (ProfileNode* currentNode = m_head.get(); currentNode; currentNode = currentNode->traverseNextNodePreOrder()) currentNode->exclude(callIdentifier); // Set the visible time of the head so the %s display correctly. m_head->setVisibleTotalTime(m_head->totalTime() - m_head->selfTime()); m_head->setVisibleSelfTime(0.0); }
bool ProfileNode::focus(const CallIdentifier& callIdentifier) { if (!m_visible) return false; if (m_callIdentifier != callIdentifier) { m_visible = false; return true; } for (ProfileNode* currentParent = m_parent; currentParent; currentParent = currentParent->parent()) currentParent->setVisible(true); return false; }
void Profile::forEach(void (ProfileNode::*function)()) { ProfileNode* currentNode = m_head->firstChild(); for (ProfileNode* nextNode = currentNode; nextNode; nextNode = nextNode->firstChild()) currentNode = nextNode; if (!currentNode) currentNode = m_head.get(); ProfileNode* endNode = m_head->traverseNextNodePostOrder(); while (currentNode && currentNode != endNode) { (currentNode->*function)(); currentNode = currentNode->traverseNextNodePostOrder(); } }
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) { KJS::JSLock lock(false); if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass())) return JSValueMakeUndefined(ctx); ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject)); const Vector<RefPtr<ProfileNode> >& children = profileNode->children(); JSObjectRef global = JSContextGetGlobalObject(ctx); JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array")); JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push")); JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) { JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() )); JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); } return result; }
const ProfileNode* ProfileNode::findNextInTree(void) const { if (firstChild) { return firstChild; } else if (nextSibling) { return nextSibling; } else { ProfileNode* pParent = parent; while (!pParent->isRoot()) { if (pParent->nextSibling) return pParent->nextSibling; else pParent = pParent->parent; } return NULL; } }
// The console.profileEnd that stopped this ProfileGenerator will be the last child. void ProfileGenerator::removeProfileEnd() { ProfileNode* currentNode = nullptr; for (ProfileNode* next = m_rootNode.get(); next; next = next->lastChild()) currentNode = next; if (currentNode->callIdentifier().functionName() != "profileEnd") return; ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[currentNode->parent()->children().size() - 1])->callIdentifier()); currentNode->parent()->removeChild(currentNode); }
// The console.ProfileGenerator that started this ProfileGenerator will be the first child. void ProfileGenerator::removeProfileStart() { ProfileNode* currentNode = 0; for (ProfileNode* next = m_head.get(); next; next = next->firstChild()) currentNode = next; if (currentNode->callIdentifier().m_name != "profile") return; // Attribute the time of the node aobut to be removed to the self time of its parent currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime()); currentNode->parent()->removeChild(currentNode); }
bool DataHandler::addDatabase(const std::string& databaseString) { if (currentFile != pProfile) throw StringException("Profile isn't loaded."); ProfileNode pn; // Utilize ProfileNode's validator if (!pn.setString(databaseString)) throw StringException("Invalid databaseString."); for (unsigned int i=0; i < res->size(); i++) { // Utilize ProfileNode's parsing of the database name. if ( ((ProfileNode*)res->getNode(i))->getDatabase() == pn.getDatabase() ) throw StringException("That database already exists.\n"); } return writeLineToFile(databaseString, pProfile, MAX_LINE_IN_FILE); }
ProfileNode* ProfileNode::traverseNextNodePreOrder(bool processChildren) const { if (processChildren && m_children.size()) return m_children[0].get(); if (m_nextSibling) return m_nextSibling; ProfileNode* nextParent = m_parent; if (!nextParent) return 0; ProfileNode* next; for (next = m_parent->nextSibling(); !next; next = nextParent->nextSibling()) { nextParent = nextParent->parent(); if (!nextParent) return 0; } return next; }
void CVCDlg::OnCategorySelChanged() { m_profileComboBox.DeleteAllItems(); int nCurSel = m_deviceComboBox.GetCurSel(); if(nCurSel >= 0) { ProfileNode* pParent = (ProfileNode*)m_deviceComboBox.GetItemDataPtr(nCurSel); int nChildCount = ((pParent == NULL) ? 0 : pParent->GetChildCount()); for(int i = 0; i < nChildCount; i++) { ProfileNode* pProfile = (ProfileNode*)pParent->GetChild(i); AddProfile(pProfile, NULL); } if(nChildCount > 0) { m_profileComboBox.SetCurSel(0); OnProfileSelChanged(); } } }
void CVCDlg::OnProfileSelChanged() { int nCurSel = m_profileComboBox.GetCurSel(); if(nCurSel >= 0) { ProfileNode* pProfile = (ProfileNode*)m_profileComboBox.GetItemDataPtr(nCurSel); AttribMap* pAttribMap = NULL; std::string szProfileFile; if(pProfile != NULL) { pAttribMap = (AttribMap*)pProfile->GetData(); if(pAttribMap->Get(PF_ATTRIB_FILE, szProfileFile)) { //Initialize the profile tree firstly CString szPath; if(SysUtils::GetProfile(szPath, CFL_A2T(szProfileFile.c_str()))) { m_propListMgr.Init(CFL_T2A((LPCTSTR)szPath)); } } } } }
void ProfileGenerator::stopProfiling() { for (ProfileNode* node = m_currentNode.get(); node != m_profile->rootNode(); node = node->parent()) endCallEntry(node); if (m_foundConsoleStartParent) { removeProfileStart(); removeProfileEnd(); } ASSERT(m_currentNode); // Set the current node to the parent, because we are in a call that // will not get didExecute call. m_currentNode = m_currentNode->parent(); }
// The console.profileEnd that stopped this ProfileGenerator will be the last child. void ProfileGenerator::removeProfileEnd() { ProfileNode* currentNode = 0; for (ProfileNode* next = m_head.get(); next; next = next->lastChild()) currentNode = next; if (currentNode->callIdentifier().functionName() != "profileEnd") return; // Attribute the time of the node aobut to be removed to the self time of its parent currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime()); ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[currentNode->parent()->children().size() - 1])->callIdentifier()); currentNode->parent()->removeChild(currentNode); }
static void finalize(JSObjectRef object) { ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(object)); ProfileNodeCache().remove(profileNode); profileNode->deref(); }