From 6b8f960db5d8f31b6aa646610cbf8ac42db0db08 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Wed, 2 Dec 2015 16:01:14 -0500 Subject: [PATCH] ctf: Make packet descriptor information available to event This allows the event to know what the packet context is for its parent packet. This is especially useful if one puts non- LTTng information in the packet such as the source gpu. Change-Id: I21ff283c1032e5a3157408b304b2611d1113d4f7 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/61816 Reviewed-by: Hudson CI Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse --- .../tests/event/CTFEventDefinitionTest.java | 32 +++++++++---------- .../tests/trace/CTFStreamInputReaderTest.java | 17 ++++++---- .../ctf/core/event/EventDefinition.java | 26 +++++++++++++-- .../ctf/core/event/EventDeclaration.java | 6 ++-- .../ctf/core/trace/CTFPacketReader.java | 3 +- 5 files changed, 56 insertions(+), 28 deletions(-) diff --git a/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java b/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java index 67fdb0df9f..62c5e6201a 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java +++ b/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java @@ -80,22 +80,22 @@ public class CTFEventDefinitionTest { int cpu = EventDefinition.UNKNOWN_CPU; - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, null, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, null, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, pContext, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, pContext, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, null, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, null, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, pContext, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, pContext, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, null, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, null, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, pContext, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, pContext, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, null, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, null, fields)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, pContext, null)); - fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, pContext, fields)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, null, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, null, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, pContext, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, null, pContext, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, null, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, null, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, pContext, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, null, eContext, pContext, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, null, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, null, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, pContext, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, null, pContext, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, null, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, null, fields, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, pContext, null, null)); + fixture.add(new EventDefinition(eventDeclaration, cpu, 100, null, sContext, eContext, pContext, fields, null)); } /** diff --git a/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputReaderTest.java b/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputReaderTest.java index ccfab8e985..01b501b6ac 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputReaderTest.java +++ b/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputReaderTest.java @@ -63,13 +63,13 @@ public class CTFStreamInputReaderTest { fixture = getStreamInputReader(); fixture.setName(1); fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(), - getStreamInputReader().getCPU(), 0, null, null, null, + fixture.getCPU(), 0, null, null, null, new StructDefinition( new StructDeclaration(0), null, "packet", new Definition[] { new StringDefinition(StringDeclaration.getStringDeclaration(Encoding.UTF8), null, "field", "test") }), - null)); + null, fixture.getCurrentPacketReader().getCurrentPacket())); } private static CTFStreamInputReader getStreamInputReader() throws CTFException { @@ -218,11 +218,16 @@ public class CTFStreamInputReaderTest { * given the timestamp we want. * * @throws CTFException + * error + * @throws IOException + * file not there */ @Test - public void testSeek_eventDefinition() throws CTFException { - EventDefinition eventDefinition = new EventDefinition( - new EventDeclaration(), getStreamInputReader().getCPU(), 1L, null, null, null, null, null); - fixture.setCurrentEvent(eventDefinition); + public void testSeek_eventDefinition() throws CTFException, IOException { + try (CTFStreamInputReader streamInputReader = getStreamInputReader()) { + EventDefinition eventDefinition = new EventDefinition( + new EventDeclaration(), streamInputReader.getCPU(), 1L, null, null, null, null, null, streamInputReader.getCurrentPacketReader().getCurrentPacket()); + fixture.setCurrentEvent(eventDefinition); + } } } diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java index 2f1003cf45..5b90a63392 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java @@ -13,9 +13,12 @@ package org.eclipse.tracecompass.ctf.core.event; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; @@ -24,6 +27,7 @@ import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition; import org.eclipse.tracecompass.ctf.core.event.types.IDefinition; import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition; +import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor; import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration; /** @@ -45,7 +49,7 @@ public final class EventDefinition implements IDefinitionScope { /** * A null event, can be used for testing or poison pilling */ - public static final @NonNull EventDefinition NULL_EVENT = new EventDefinition(new EventDeclaration(), UNKNOWN_CPU, -1L, null, null, null, null, null); + public static final @NonNull EventDefinition NULL_EVENT = new EventDefinition(new EventDeclaration(), UNKNOWN_CPU, -1L, null, null, null, null, null, null); /** * The corresponding event declaration. @@ -78,6 +82,8 @@ public final class EventDefinition implements IDefinitionScope { */ private final int fCpu; + private final @NonNull Map fPacketAttributes; + // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ @@ -98,11 +104,14 @@ public final class EventDefinition implements IDefinitionScope { * @param eventContext * The event context * @param packetContext - * the packet context (the one with content size, not magic number) + * the packet context (the one with content size, not magic + * number) * @param streamContext * the stream context * @param fields * The event fields + * @param packetDescriptor + * descriptor of the packet containing this event * @since 2.0 */ public EventDefinition(IEventDeclaration declaration, @@ -112,7 +121,8 @@ public final class EventDefinition implements IDefinitionScope { ICompositeDefinition streamContext, ICompositeDefinition eventContext, ICompositeDefinition packetContext, - ICompositeDefinition fields) { + ICompositeDefinition fields, + @Nullable ICTFPacketDescriptor packetDescriptor) { fDeclaration = declaration; fEventHeaderDefinition = eventHeaderDefinition; fCpu = cpu; @@ -121,6 +131,7 @@ public final class EventDefinition implements IDefinitionScope { fEventContext = eventContext; fPacketContext = packetContext; fStreamContext = streamContext; + fPacketAttributes = packetDescriptor != null ? packetDescriptor.getAttributes() : Collections.EMPTY_MAP; } // ------------------------------------------------------------------------ @@ -258,6 +269,15 @@ public final class EventDefinition implements IDefinitionScope { return fTimestamp; } + /** + * Get the packet attributes. + * + * @return the packet attributes, such as "device" and "timestamp_begin" + * @since 2.0 + */ + public @NonNull Map getPacketAttributes() { + return fPacketAttributes; + } // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java index 3172b9daa2..e10cfd1d03 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java @@ -126,7 +126,8 @@ public class EventDeclaration implements IEventDeclaration { streamEventContext, eventContext, packetContext, - eventPayload); + eventPayload, + packetDescriptor); } private static long calculateTimestamp(@Nullable ICompositeDefinition eventHeaderDef, long prevTimestamp, StructDefinition eventPayload, StructDefinition eventContext) throws CTFIOException { @@ -176,7 +177,8 @@ public class EventDeclaration implements IEventDeclaration { streamEventContext, eventContext, packetContext, - eventPayload); + eventPayload, + streamInputReader.getCurrentPacketReader().getCurrentPacket()); } // ------------------------------------------------------------------------ diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/CTFPacketReader.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/CTFPacketReader.java index 36e73697c5..c04ecf6096 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/CTFPacketReader.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/CTFPacketReader.java @@ -223,7 +223,8 @@ public final class CTFPacketReader implements IPacketReader, IDefinitionScope { new StructDefinition( lostFields, this, "fields", //$NON-NLS-1$ - fields)); + fields), + fPacketContext); } @Override -- 2.34.1