Reworked control variable lookup profiling. Should practically be free, and is now enabled for relwithdebinfo. Use dumpcalls for output.

This commit is contained in:
Shyotl
2013-03-14 14:37:20 -05:00
parent d27b329afb
commit 1dbaa19e99
3 changed files with 54 additions and 33 deletions

View File

@@ -174,7 +174,8 @@ LLControlVariable::LLControlVariable(const std::string& name, eControlType type,
mValidateSignal(new validate_signal_t), mValidateSignal(new validate_signal_t),
mIsCOA(IsCOA), mIsCOA(IsCOA),
mIsCOAParent(false), mIsCOAParent(false),
mCOAConnectedVar(NULL) mCOAConnectedVar(NULL),
mLookupCount(0)
{ {
if (mPersist && mComment.empty()) if (mPersist && mComment.empty())
{ {
@@ -343,25 +344,12 @@ LLSD LLControlVariable::getSaveValue() const
return mValues[0]; return mValues[0];
} }
#if PROF_CTRL_CALLS #ifdef PROF_CTRL_CALLS
std::vector<std::pair<std::string, U32>> gSettingsCallMap; void LLControlGroup::updateLookupMap(ctrl_name_table_t::const_iterator iter) const
static update_gSettingsCallMap(ctrl_name_table_t::const_iterator const& iter)
{ {
if(iter != mNameTable.end()) if(iter != mNameTable.end() && iter->second.notNull())
{ {
std::vector<std::pair<std::string, U32>>::iterator iter2 = gSettingsCallMap.begin(); iter->second.get()->mLookupCount++;
std::vector<std::pair<std::string, U32>>::iterator end = gSettingsCallMap.end();
for(;iter2!=end;iter2++)
{
if(iter2->first==name)
{
iter2->second = iter2->second + 1;
break;
}
}
if(iter2 == gSettingsCallMap.end())
gSettingsCallMap.push_back(std::pair<std::string, U32>(name.c_str(),1));
} }
} }
#endif //PROF_CTRL_CALLS #endif //PROF_CTRL_CALLS
@@ -369,8 +357,8 @@ static update_gSettingsCallMap(ctrl_name_table_t::const_iterator const& iter)
LLControlVariable* LLControlGroup::getControl(std::string const& name) LLControlVariable* LLControlGroup::getControl(std::string const& name)
{ {
ctrl_name_table_t::iterator iter = mNameTable.find(name); ctrl_name_table_t::iterator iter = mNameTable.find(name);
#if PROF_CTRL_CALLS #ifdef PROF_CTRL_CALLS
update_gSettingsCallMap(iter); updateLookupMap(iter);
#endif //PROF_CTRL_CALLS #endif //PROF_CTRL_CALLS
if(iter != mNameTable.end()) if(iter != mNameTable.end())
return iter->second->getCOAActive(); return iter->second->getCOAActive();
@@ -381,8 +369,8 @@ LLControlVariable* LLControlGroup::getControl(std::string const& name)
LLControlVariable const* LLControlGroup::getControl(std::string const& name) const LLControlVariable const* LLControlGroup::getControl(std::string const& name) const
{ {
ctrl_name_table_t::const_iterator iter = mNameTable.find(name); ctrl_name_table_t::const_iterator iter = mNameTable.find(name);
#if PROF_CTRL_CALLS #ifdef PROF_CTRL_CALLS
update_gSettingsCallMap(iter); updateLookupMap(iter);
#endif //PROF_CTRL_CALLS #endif //PROF_CTRL_CALLS
if(iter != mNameTable.end()) if(iter != mNameTable.end())
return iter->second->getCOAActive(); return iter->second->getCOAActive();

View File

@@ -69,6 +69,10 @@
# endif # endif
#endif #endif
#if LL_RELEASE_WITH_DEBUG_INFO
#define PROF_CTRL_CALLS
#endif //LL_RELEASE_WITH_DEBUG_INFO
class LLVector3; class LLVector3;
class LLVector3d; class LLVector3d;
class LLColor3; class LLColor3;
@@ -179,6 +183,10 @@ public:
mValidateSignal = pConnect->mValidateSignal; mValidateSignal = pConnect->mValidateSignal;
} }
} }
#ifdef PROF_CTRL_CALLS
public:
U32 mLookupCount;
#endif //PROF_CTRL_CALLS
private: private:
LLSD getComparableValue(const LLSD& value); LLSD getComparableValue(const LLSD& value);
bool llsd_compare(const LLSD& a, const LLSD & b); bool llsd_compare(const LLSD& a, const LLSD & b);
@@ -347,6 +355,10 @@ public:
void connectCOAVars(LLControlGroup &OtherGroup); void connectCOAVars(LLControlGroup &OtherGroup);
void updateCOASetting(bool coa_enabled); void updateCOASetting(bool coa_enabled);
bool handleCOASettingChange(const LLSD& newvalue); bool handleCOASettingChange(const LLSD& newvalue);
#ifdef PROF_CTRL_CALLS
void updateLookupMap(ctrl_name_table_t::const_iterator iter) const;
#endif //PROF_CTRL_CALLS
}; };

View File

@@ -200,13 +200,24 @@ void invrepair()
gInventory.collectDescendents(gInventory.getRootFolderID(),cats,items,FALSE);//,objectnamematches); gInventory.collectDescendents(gInventory.getRootFolderID(),cats,items,FALSE);//,objectnamematches);
} }
#ifdef PROF_CTRL_CALLS
#if PROF_CTRL_CALLS bool sort_calls(const std::pair<std::string, U32>& left, const std::pair<std::string, U32>& right)
extern std::vector<std::pair<std::string, U32>> gSettingsCallMap;
bool stort_calls(const std::pair<std::string, U32>& left, const std::pair<std::string, U32>& right)
{ {
return left.second < right.second; return left.second > right.second;
} }
//Structure to be passed into LLControlGroup::applyToAll.
// Doesn't actually modify control group, but rather uses the 'apply'
// vfn to add each variable in the group to a list. This essentially
// allows us to copy the private variable list without touching the controlgroup
// class.
struct ProfCtrlListAccum : public LLControlGroup::ApplyFunctor
{
virtual void apply(const std::string& name, LLControlVariable* control)
{
mVariableList.push_back(std::make_pair(name,control->mLookupCount));
}
std::vector<std::pair<std::string, U32> > mVariableList;
};
#endif //PROF_CTRL_CALLS #endif //PROF_CTRL_CALLS
bool cmd_line_chat(std::string revised_text, EChatType type) bool cmd_line_chat(std::string revised_text, EChatType type)
{ {
@@ -446,13 +457,23 @@ bool cmd_line_chat(std::string revised_text, EChatType type)
{ {
invrepair(); invrepair();
} }
#if PROF_CTRL_CALLS #ifdef PROF_CTRL_CALLS
else if(command == "dumpcalls") else if(command == "dumpcalls")
{ {
llinfos << "gSavedSettings lookup count (" << gFrameCount << "frames)" << llendl; LLControlGroup::key_iter it = LLControlGroup::beginKeys();
std::sort(gSettingsCallMap.begin(),gSettingsCallMap.end(),stort_calls); LLControlGroup::key_iter end = LLControlGroup::endKeys();
for(U32 i = 0;i<gSettingsCallMap.size();i++) for(;it!=end;++it)
llinfos << gSettingsCallMap[i].first << " : " << gSettingsCallMap[i].second << " " << ((float)gSettingsCallMap[i].second / (float)gFrameCount) << "c/f" << llendl; {
ProfCtrlListAccum list;
LLControlGroup::getInstance(*it)->applyToAll(&list);
std::sort(list.mVariableList.begin(),list.mVariableList.end(),sort_calls);
LL_INFOS("") << *it << ": lookup count (" << gFrameCount << "frames)" << LL_ENDL;
for(U32 i = 0;i<list.mVariableList.size();i++)
{
if(list.mVariableList[i].second)
LL_INFOS("") << " " << list.mVariableList[i].first << ": " << list.mVariableList[i].second << " lookups, " << ((float)list.mVariableList[i].second / (float)gFrameCount) << "l/f\n" << LL_ENDL;
}
}
return false; return false;
} }
#endif //PROF_CTRL_CALLS #endif //PROF_CTRL_CALLS