Skip to content

Commit 36bedef

Browse files
committed
fix: correct cost attribution of inline frames in disassembly view
Previously, we put the cost of an inline frame into a container indexed by the inline symbol. But during disassembly, we never get to query that data again, since we cannot disassemble an inline frame. Instead, we need to be able to query the cost for arbitrary binary offsets, independent of their originating symbol. The patch here achieves this by lifting the OffsetLocationCostMap out of the CallerCalleeEntryMap into CallerCalleeResults, but mapped by the binary name. This way we can efficiently store and lookup the data of a given offset within a specific binary during disassembly, which allows us to show the cost for inlined code in the disassembly view. Fixes: #671
1 parent f326ef0 commit 36bedef

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

src/models/data.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -683,18 +683,6 @@ struct CallerCalleeEntry
683683
return *it;
684684
}
685685

686-
LocationCost& offset(quint64 addr, int numTypes)
687-
{
688-
auto it = offsetMap.find(addr);
689-
if (it == offsetMap.end()) {
690-
it = offsetMap.insert(addr, {numTypes});
691-
} else if (it->inclusiveCost.size() < static_cast<size_t>(numTypes)) {
692-
it->inclusiveCost.resize(numTypes);
693-
it->selfCost.resize(numTypes);
694-
}
695-
return *it;
696-
}
697-
698686
ItemCost& callee(const Symbol& symbol, int numTypes)
699687
{
700688
auto it = callees.find(symbol);
@@ -719,14 +707,14 @@ struct CallerCalleeEntry
719707
CalleeMap callees;
720708
// source map for this symbol, i.e. locations mapped to associated costs
721709
SourceLocationCostMap sourceMap;
722-
// per-IP map for this symbol for disassembly
723-
OffsetLocationCostMap offsetMap;
724710
};
725711

726712
using CallerCalleeEntryMap = QHash<Symbol, CallerCalleeEntry>;
727713
struct CallerCalleeResults
728714
{
729715
CallerCalleeEntryMap entries;
716+
// per-binary map of per-IP (relAddr) map for disassembly
717+
QHash<QString, OffsetLocationCostMap> binaryOffsetMap;
730718
Costs selfCosts;
731719
Costs inclusiveCosts;
732720

@@ -739,6 +727,23 @@ struct CallerCalleeResults
739727
}
740728
return *it;
741729
}
730+
731+
LocationCost& binaryOffset(const QString& binary, quint64 addr, int numTypes)
732+
{
733+
auto binaryIt = binaryOffsetMap.find(binary);
734+
if (binaryIt == binaryOffsetMap.end()) {
735+
binaryIt = binaryOffsetMap.insert(binary, {});
736+
}
737+
738+
auto it = binaryIt->find(addr);
739+
if (it == binaryIt->end()) {
740+
it = binaryIt->insert(addr, {numTypes});
741+
} else if (it->inclusiveCost.size() < static_cast<size_t>(numTypes)) {
742+
it->inclusiveCost.resize(numTypes);
743+
it->selfCost.resize(numTypes);
744+
}
745+
return *it;
746+
}
742747
};
743748

744749
void callerCalleesFromBottomUpData(const BottomUpResults& data, CallerCalleeResults* results);

src/models/disassemblymodel.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void DisassemblyModel::clear()
2323
{
2424
beginResetModel();
2525
m_data = {};
26+
m_offsetMap = {};
2627
endResetModel();
2728
}
2829

@@ -47,6 +48,7 @@ void DisassemblyModel::setDisassembly(const DisassemblyOutput& disassemblyOutput
4748

4849
m_data = disassemblyOutput;
4950
m_results = results;
51+
m_offsetMap = m_results.binaryOffsetMap[m_data.symbol.binary];
5052
m_numTypes = results.selfCosts.numTypes();
5153

5254
QStringList assemblyLines;
@@ -128,9 +130,8 @@ QVariant DisassemblyModel::data(const QModelIndex& index, int role) const
128130
return {};
129131
}
130132

131-
const auto entry = m_results.entries.value(m_data.symbol);
132-
auto it = entry.offsetMap.find(data.addr);
133-
if (it != entry.offsetMap.end()) {
133+
auto it = m_offsetMap.find(data.addr);
134+
if (it != m_offsetMap.end()) {
134135
const auto event = index.column() - COLUMN_COUNT;
135136
const auto& locationCost = it.value();
136137

@@ -223,8 +224,8 @@ QModelIndex DisassemblyModel::indexForFileLine(const Data::FileLine& fileLine) c
223224
bestMatch = i;
224225
}
225226

226-
auto it = entry.offsetMap.find(line.addr);
227-
if (it != entry.offsetMap.end()) {
227+
auto it = m_offsetMap.find(line.addr);
228+
if (it != m_offsetMap.end()) {
228229
const auto& locationCost = it.value();
229230

230231
if (!bestCost || bestCost < locationCost.selfCost[0]) {

src/models/disassemblymodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public slots:
8383
HighlightedText m_highlightedText;
8484
DisassemblyOutput m_data;
8585
Data::CallerCalleeResults m_results;
86+
Data::OffsetLocationCostMap m_offsetMap;
8687
int m_numTypes = 0;
8788
int m_highlightLine = 0;
8889
};

src/parsers/perf/perfparser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ void addCallerCalleeEvent(const Data::Symbol& symbol, const Data::Location& loca
543543
auto& entry = callerCalleeResult->entry(symbol);
544544
auto& sourceCost = entry.source(location.fileLine, numCosts);
545545
// relAddr can be 0 for symbols in the main executable
546-
auto& addrCost = entry.offset(location.relAddr ? location.relAddr : location.address, numCosts);
546+
auto& addrCost = callerCalleeResult->binaryOffset(
547+
symbol.binary, location.relAddr ? location.relAddr : location.address, numCosts);
547548

548549
sourceCost.inclusiveCost[type] += cost;
549550
addrCost.inclusiveCost[type] += cost;

tests/modeltests/tst_models.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ private slots:
348348
Data::CallerCalleeResults results;
349349
Data::callerCalleesFromBottomUpData(tree, &results);
350350

351-
auto entry = results.entry(symbol);
352-
auto& locationCost = entry.offset(4294563, results.selfCosts.numTypes());
351+
auto& locationCost = results.binaryOffset(symbol.binary, 4294563, results.selfCosts.numTypes());
353352
locationCost.inclusiveCost[0] += 200;
354353
locationCost.selfCost[0] += 200;
355354

0 commit comments

Comments
 (0)