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),
mIsCOA(IsCOA),
mIsCOAParent(false),
mCOAConnectedVar(NULL)
mCOAConnectedVar(NULL),
mLookupCount(0)
{
if (mPersist && mComment.empty())
{
@@ -339,29 +340,16 @@ LLSD LLControlVariable::getSaveValue() const
{
//The first level of the stack is default
//We assume that the second level is user preferences that should be saved
if(mValues.size() > 1) return mValues[1];
if(mValues.size() > 1) return mValues[1];
return mValues[0];
}
#if PROF_CTRL_CALLS
std::vector<std::pair<std::string, U32>> gSettingsCallMap;
static update_gSettingsCallMap(ctrl_name_table_t::const_iterator const& iter)
#ifdef PROF_CTRL_CALLS
void LLControlGroup::updateLookupMap(ctrl_name_table_t::const_iterator iter) const
{
if(iter != mNameTable.end())
if(iter != mNameTable.end() && iter->second.notNull())
{
std::vector<std::pair<std::string, U32>>::iterator iter2 = gSettingsCallMap.begin();
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));
iter->second.get()->mLookupCount++;
}
}
#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)
{
ctrl_name_table_t::iterator iter = mNameTable.find(name);
#if PROF_CTRL_CALLS
update_gSettingsCallMap(iter);
#ifdef PROF_CTRL_CALLS
updateLookupMap(iter);
#endif //PROF_CTRL_CALLS
if(iter != mNameTable.end())
return iter->second->getCOAActive();
@@ -381,8 +369,8 @@ LLControlVariable* LLControlGroup::getControl(std::string const& name)
LLControlVariable const* LLControlGroup::getControl(std::string const& name) const
{
ctrl_name_table_t::const_iterator iter = mNameTable.find(name);
#if PROF_CTRL_CALLS
update_gSettingsCallMap(iter);
#ifdef PROF_CTRL_CALLS
updateLookupMap(iter);
#endif //PROF_CTRL_CALLS
if(iter != mNameTable.end())
return iter->second->getCOAActive();

View File

@@ -69,6 +69,10 @@
# endif
#endif
#if LL_RELEASE_WITH_DEBUG_INFO
#define PROF_CTRL_CALLS
#endif //LL_RELEASE_WITH_DEBUG_INFO
class LLVector3;
class LLVector3d;
class LLColor3;
@@ -179,6 +183,10 @@ public:
mValidateSignal = pConnect->mValidateSignal;
}
}
#ifdef PROF_CTRL_CALLS
public:
U32 mLookupCount;
#endif //PROF_CTRL_CALLS
private:
LLSD getComparableValue(const LLSD& value);
bool llsd_compare(const LLSD& a, const LLSD & b);
@@ -347,6 +355,10 @@ public:
void connectCOAVars(LLControlGroup &OtherGroup);
void updateCOASetting(bool coa_enabled);
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);
}
#if PROF_CTRL_CALLS
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)
#ifdef PROF_CTRL_CALLS
bool sort_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
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();
}
#if PROF_CTRL_CALLS
#ifdef PROF_CTRL_CALLS
else if(command == "dumpcalls")
{
llinfos << "gSavedSettings lookup count (" << gFrameCount << "frames)" << llendl;
std::sort(gSettingsCallMap.begin(),gSettingsCallMap.end(),stort_calls);
for(U32 i = 0;i<gSettingsCallMap.size();i++)
llinfos << gSettingsCallMap[i].first << " : " << gSettingsCallMap[i].second << " " << ((float)gSettingsCallMap[i].second / (float)gFrameCount) << "c/f" << llendl;
LLControlGroup::key_iter it = LLControlGroup::beginKeys();
LLControlGroup::key_iter end = LLControlGroup::endKeys();
for(;it!=end;++it)
{
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;
}
#endif //PROF_CTRL_CALLS