Skip to content

Commit 872e1c9

Browse files
committed
Record maps per process rather than globally
If a perf.data file is coming from whole-system or multi-process profiling then the MMAP(2) events may have overlapping address ranges. This can cause samples to be incorrectly attributed to whatever the most recent process to start was rather than the actual process from which the sample came from. To get around this, simply keep track of a separate set of maps per process instead. Change-Id: I671bc3f281d192d5ee4dcdfe9b0f13a865126a23
1 parent cfc8483 commit 872e1c9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ class PerfReader {
679679
std::map<const char *, uint64_t> TotalEvents;
680680
std::map<uint64_t, std::map<const char *, uint64_t>> TotalEventsPerMap;
681681
std::vector<Map> Maps;
682-
std::map<uint64_t, std::map<uint64_t, EventDesc>> CurrentMaps;
682+
std::map<uint64_t, std::map<uint64_t, std::map<uint64_t, EventDesc>>> CurrentMaps;
683683

684684
PyObject *Functions, *TopLevelCounters;
685685
std::vector<PyObject*> Lines;
@@ -850,7 +850,7 @@ void PerfReader::registerNewMapping(unsigned char *Buf, const char *Filename) {
850850
// FIXME: The first EventID is used for every event.
851851
// FIXME: The code assumes perf_event_attr.sample_id_all is set.
852852
uint64_t Time = getTimeFromSampleId(EndOfEvent, EventLayouts.begin()->second);
853-
auto &CurrentMap = CurrentMaps[Time];
853+
auto &CurrentMap = CurrentMaps[E->pid][Time];
854854
CurrentMap.insert({E->start, { E->start, End, MapID}});
855855
}
856856

@@ -882,8 +882,8 @@ unsigned char *PerfReader::readEvent(unsigned char *Buf) {
882882
// Search for the map corresponding to this sample. Search backwards through
883883
// time, discarding any maps created after our timestamp.
884884
uint64_t MapID = ~0ULL;
885-
for (auto I = CurrentMaps.rbegin(), E = CurrentMaps.rend();
886-
I != E; ++I) {
885+
auto &MapsForPid = CurrentMaps[E->pid];
886+
for (auto I = MapsForPid.rbegin(), E = MapsForPid.rend(); I != E; ++I) {
887887
if (I->first > NewE.time)
888888
continue;
889889

0 commit comments

Comments
 (0)