Skip to content

Commit

Permalink
ftrace: fix trace entry size computation when header len is 0
Browse files Browse the repository at this point in the history
In a trace.dat files, trace entries have a 32 bit header that contains
the payload len (in 32 bit words) in the lower 5 bits.

A len of 0 is a special case: the actual entry length is in the next
32 bit word, and that length includes the length field itself, so:

- the event data starts after the length fields
- the event data is len_in_next_word - 4

For documentation see:
https://elixir.bootlin.com/linux/latest/source/include/linux/ring_buffer.h#L51

Change-Id: I91a459deb11c63f606406b6a1dac9b2b4fcf9130
Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/197834
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Hoang Thuan Pham <hoangpham.eclipse@gmail.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
fabrizioiannetti authored and bhufmann committed Dec 23, 2022
1 parent 57af22c commit 5f6ec6a
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -178,10 +178,14 @@ private void readNextEventTimeStamp() throws IOException {
// Now we have a data event, we store the event type length, we save
// the event type length and delta time
// to load the event lazily later
fEventDef = new BinaryFTraceEventDefinition(fCurrentOffset, getCurrentEventPayloadSize());
int payloadSize = getCurrentEventPayloadSize();

// fCurrentOffset may have been modified by getCurrentEventPayloadSize(), pass it
// after calling the function above
fEventDef = new BinaryFTraceEventDefinition(fCurrentOffset, payloadSize);

// Move the pointer to the next event
skip(fEventDef.getPayloadSize());
skip(payloadSize);

// We peek the next event, to see if the event is an time extended
// event
Expand Down Expand Up @@ -297,7 +301,8 @@ private int getCurrentEventPayloadSize() throws IOException {
// length
BinaryFTraceByteBuffer buffer = fBuffer;
if (buffer != null) {
payloadSize = buffer.getNextInt();
// the size includes the size field itself, subtract it to get the actual event length
payloadSize = buffer.getNextInt() - 4;
this.fCurrentOffset += 4;
}
} else if (fCurrentTypeLen <= fFileHeader.getHeaderEventInfo().getDataMaxTypeLen()) {
Expand Down

0 comments on commit 5f6ec6a

Please sign in to comment.