Skip to content

Commit d5aa5cf

Browse files
committed
Record maps per process rather than globally, attempt #2
Rather than reading the PID off the bitcasted structure pointer, we need to use the NewE parsed event instead to avoid struct offsets being incorrect in case some fields are not present. Also refactor the readEvent method to have less variable shadowing and get rid of the pointless definition of E from the PERF_RECORD_SAMPLE case. Change-Id: I2cbaf91d5096acdb156ca83291626f134273cb91
1 parent 60129c2 commit d5aa5cf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,8 @@ void PerfReader::registerNewMapping(unsigned char *Buf, const char *Filename) {
855855
}
856856

857857
unsigned char *PerfReader::readEvent(unsigned char *Buf) {
858-
perf_event_header *E = (perf_event_header *)Buf;
859-
switch (E->type) {
858+
perf_event_header *Header = (perf_event_header *)Buf;
859+
switch (Header->type) {
860860
case PERF_RECORD_MMAP:
861861
{
862862
perf_event_mmap *E = (perf_event_mmap *)Buf;
@@ -873,16 +873,15 @@ unsigned char *PerfReader::readEvent(unsigned char *Buf) {
873873
break;
874874
case PERF_RECORD_SAMPLE:
875875
{
876-
perf_event_sample* E = (perf_event_sample*)Buf;
877-
auto NewE = parseEvent(((unsigned char*)E) + sizeof(perf_event_header),
876+
auto NewE = parseEvent(Buf + sizeof(perf_event_header),
878877
EventLayouts.begin()->second);
879878
auto EventID = NewE.id;
880879
auto PC = NewE.ip;
881880

882881
// Search for the map corresponding to this sample. Search backwards through
883882
// time, discarding any maps created after our timestamp.
884883
uint64_t MapID = ~0ULL;
885-
auto &MapsForPid = CurrentMaps[E->pid];
884+
auto &MapsForPid = CurrentMaps[NewE.pid];
886885
for (auto I = MapsForPid.rbegin(), E = MapsForPid.rend(); I != E; ++I) {
887886
if (I->first > NewE.time)
888887
continue;
@@ -907,7 +906,7 @@ unsigned char *PerfReader::readEvent(unsigned char *Buf) {
907906
}
908907
break;
909908
}
910-
return &Buf[E->size];
909+
return &Buf[Header->size];
911910
}
912911

913912
perf_event_sample PerfReader::parseEvent(unsigned char *Buf, uint64_t Layout) {

0 commit comments

Comments
 (0)