Skip to content

Commit

Permalink
Update the tail only after we've finished reading the packet.
Browse files Browse the repository at this point in the history
Currently the kernel might overwrite the packet data we're reading.
  • Loading branch information
rocallahan committed Aug 4, 2024
1 parent fad9da3 commit 87e3849
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/PerfCounters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,6 @@ size_t PerfCounters::PTState::flush() {
mmap_header->data_size - start_offset);
memcpy(packet.data(), const_cast<perf_event_header*>(header), first_chunk_size);
memcpy(packet.data() + first_chunk_size, const_cast<char*>(data_buf), header->size - first_chunk_size);
mmap_header->data_tail += header->size;

switch (header->type) {
case PERF_RECORD_LOST:
Expand Down Expand Up @@ -857,6 +856,8 @@ size_t PerfCounters::PTState::flush() {
FATAL() << "Unknown record " << header->type;
break;
}

mmap_header->data_tail += header->size;
}
return ret;
}
Expand Down

0 comments on commit 87e3849

Please sign in to comment.