Commit 2b000fd8 by Jim Stichnoth

Subzero: Fix -timing-focus .

The problem is that the default timer is renamed to be the current function name, instead of "Total across all functions", but this causes an assertion failure during the final merge of thread-local timers into the global timers, because the names don't match. The solution is to temporarily rename the timer to be the function name, until the timer is dumped, and then restore it to its original value. BUG= none R=jpp@chromium.org Review URL: https://codereview.chromium.org/1867473002 .
parent a91c3411
......@@ -204,7 +204,6 @@ void Cfg::translate() {
if (TimingFocusOn == "*" || TimingFocusOn == Name) {
setFocusedTiming();
getContext()->resetTimer(GlobalContext::TSK_Default);
getContext()->setTimerName(GlobalContext::TSK_Default, Name);
}
}
}
......@@ -240,8 +239,7 @@ void Cfg::translate() {
dump("Final output");
if (getFocusedTiming()) {
getContext()->mergeTimersFromTLS();
getContext()->dumpTimers();
getContext()->dumpLocalTimers(getFunctionName().toString());
}
}
......
......@@ -887,32 +887,38 @@ TimerStackIdT GlobalContext::newTimerStackID(const std::string &Name) {
TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID,
const std::string &Name) {
auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(StackID < Timers->size());
return Timers->at(StackID).getTimerID(Name);
}
void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) {
auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(StackID < Timers->size());
Timers->at(StackID).push(ID);
}
void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) {
auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(StackID < Timers->size());
Timers->at(StackID).pop(ID);
}
void GlobalContext::resetTimer(TimerStackIdT StackID) {
auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(StackID < Timers->size());
Timers->at(StackID).reset();
}
std::string GlobalContext::getTimerName(TimerStackIdT StackID) {
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(StackID < Timers->size());
return Timers->at(StackID).getName();
}
void GlobalContext::setTimerName(TimerStackIdT StackID,
const std::string &NewName) {
auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(StackID < Timers->size());
Timers->at(StackID).setName(NewName);
}
......@@ -962,10 +968,6 @@ void GlobalContext::dumpStats(const Cfg *Func) {
}
}
void GlobalContext::mergeTimersFromTLS() {
getTimers()->mergeFrom(ICE_TLS_GET_FIELD(TLS)->Timers);
}
void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
if (!BuildDefs::timers())
return;
......@@ -975,6 +977,25 @@ void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
Timers->at(StackID).dump(getStrDump(), DumpCumulative);
}
void GlobalContext::dumpLocalTimers(const std::string &TimerNameOverride,
TimerStackIdT StackID,
bool DumpCumulative) {
if (!BuildDefs::timers())
return;
auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
assert(Timers->size() > StackID);
// Temporarily override the thread-local timer name with the given name.
// Don't do it permanently because the final timer merge at the end expects
// the thread-local timer names to be the same as the global timer name.
auto OrigName = getTimerName(StackID);
setTimerName(StackID, TimerNameOverride);
{
OstreamLocker _(this);
Timers->at(StackID).dump(getStrDump(), DumpCumulative);
}
setTimerName(StackID, OrigName);
}
LockedPtr<StringPool>
GlobalStringPoolTraits::getStrings(const GlobalContext *PoolOwner) {
return PoolOwner->getStrings();
......
......@@ -356,13 +356,15 @@ public:
/// data.
void dumpTimers(TimerStackIdT StackID = TSK_Default,
bool DumpCumulative = true);
/// Merges the current thread's copy of timer data into the global timer data.
void mergeTimersFromTLS();
void dumpLocalTimers(const std::string &TimerNameOverride,
TimerStackIdT StackID = TSK_Default,
bool DumpCumulative = true);
/// The following methods affect only the calling thread's TLS timer data.
TimerIdT getTimerID(TimerStackIdT StackID, const std::string &Name);
void pushTimer(TimerIdT ID, TimerStackIdT StackID);
void popTimer(TimerIdT ID, TimerStackIdT StackID);
void resetTimer(TimerStackIdT StackID);
std::string getTimerName(TimerStackIdT StackID);
void setTimerName(TimerStackIdT StackID, const std::string &NewName);
/// This is the first work item sequence number that the parser produces, and
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment