*******************************************************************************/
package org.eclipse.tracecompass.ctf.core.trace;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+
/**
* CTF Packet descriptor, can come from a packet header or an index file, this
* will show certain information about the packet such as the size and
* timerange.
*
- * @since 1.0
+ * @since 2.0
*/
public interface ICTFPacketDescriptor {
long getOffsetBits();
/**
- * Gets the size of the packet in bits. If you have a 1mb packet that is 499kb
- * used and the header is 1kb, this will return 1mb
+ * Gets the size of the packet in bits. If you have a 1mb packet that is
+ * 499kb used and the header is 1kb, this will return 1mb
*
* @return the packetSizeBits
*/
long getPacketSizeBits();
/**
- * Get the content size of the packet in bits. If you have a 1mb packet that is 499kb
- * used and the header is 1kb, this will return 500kb (used data + header
+ * Get the content size of the packet in bits. If you have a 1mb packet that
+ * is 499kb used and the header is 1kb, this will return 500kb (used data +
+ * header
*
* @return the contentSizeBits
*/
long getContentSizeBits();
/**
- * Gets the beginning timestamp of the packet, all events within the packet will have timestamps after or at this time
+ * Gets the beginning timestamp of the packet, all events within the packet
+ * will have timestamps after or at this time
*
* @return the timestampBegin
*/
long getTimestampBegin();
/**
- * Gets the ending timestamp of the packet, all events within the packet will have timestamps before or at this time
+ * Gets the ending timestamp of the packet, all events within the packet
+ * will have timestamps before or at this time
*
* @return the timestampEnd
*/
long getLostEvents();
/**
- * Retrieve the value of an existing attribute
+ * Retrieve the map of the packet attributes
*
- * @param field
- * The name of the attribute
- * @return The value that was stored, or null if it wasn't found
+ * @return The map of attributes stored. Example keys are "device" or
+ * "timestamp_begin"
+ * @since 2.0
*/
- Object lookupAttribute(String field);
+ @NonNull Map<String, Object> getAttributes();
/**
* Get the target of the packet (what device generated this packet)
package org.eclipse.tracecompass.internal.ctf.core.trace;
import java.util.AbstractMap;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.common.core.NonNullUtils;
import org.eclipse.tracecompass.ctf.core.CTFStrings;
import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
import org.eclipse.tracecompass.ctf.core.trace.IPacketReader;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+
/**
* <b><u>StreamInputPacketIndexEntry</u></b>
* <p>
/**
* Attributes of this index entry
*/
- private final Map<String, Object> fAttributes = new HashMap<>();
+ private final @NonNull Map<String, Object> fAttributes;
private final long fEndPacketHeaderBits;
*/
public StreamInputPacketIndexEntry(long dataOffsetBits, long fileSizeBytes) {
+ fAttributes = Collections.EMPTY_MAP;
fContentSizeBits = (fileSizeBytes * Byte.SIZE);
fPacketSizeBits = (fileSizeBytes * Byte.SIZE);
fOffsetBits = dataOffsetBits;
*/
public StreamInputPacketIndexEntry(long dataOffsetBits, StructDefinition streamPacketContextDef, long fileSizeBytes, long lostSoFar, long endPacketHeaderBits) {
fEndPacketHeaderBits = endPacketHeaderBits;
- for (String field : streamPacketContextDef.getDeclaration().getFieldsList()) {
- IDefinition id = streamPacketContextDef.lookupDefinition(field);
- if (id instanceof IntegerDefinition) {
- fAttributes.put(field, ((IntegerDefinition) id).getValue());
- } else if (id instanceof FloatDefinition) {
- fAttributes.put(field, ((FloatDefinition) id).getValue());
- } else if (id instanceof EnumDefinition) {
- final EnumDefinition enumDec = (EnumDefinition) id;
- fAttributes.put(field, new AbstractMap.SimpleImmutableEntry<>(
- NonNullUtils.checkNotNull(enumDec.getStringValue()),
- NonNullUtils.checkNotNull(enumDec.getIntegerValue())));
- } else if (id instanceof StringDefinition) {
- fAttributes.put(field, ((StringDefinition) id).getValue());
- }
- }
-
+ fAttributes = computeAttributeMap(streamPacketContextDef);
fContentSizeBits = computeContentSize(fileSizeBytes);
fPacketSizeBits = computePacketSize(fileSizeBytes);
fTimestampBegin = computeTsBegin();
fLostEvents = computeLostEvents(lostSoFar);
}
+ private @NonNull static ImmutableMap<String, Object> computeAttributeMap(StructDefinition streamPacketContextDef) {
+ Builder<String, Object> attributeBuilder = ImmutableMap.<String, Object> builder();
+ for (String field : streamPacketContextDef.getDeclaration().getFieldsList()) {
+ IDefinition id = streamPacketContextDef.lookupDefinition(field);
+ if (id instanceof IntegerDefinition) {
+ attributeBuilder.put(field, ((IntegerDefinition) id).getValue());
+ } else if (id instanceof FloatDefinition) {
+ attributeBuilder.put(field, ((FloatDefinition) id).getValue());
+ } else if (id instanceof EnumDefinition) {
+ final EnumDefinition enumDec = (EnumDefinition) id;
+ attributeBuilder.put(field, new AbstractMap.SimpleImmutableEntry<>(
+ NonNullUtils.checkNotNull(enumDec.getStringValue()),
+ NonNullUtils.checkNotNull(enumDec.getIntegerValue())));
+ } else if (id instanceof StringDefinition) {
+ attributeBuilder.put(field, ((StringDefinition) id).getValue());
+ }
+ }
+ return attributeBuilder.build();
+ }
+
private Long getPacketSize() {
return (Long) fAttributes.get(CTFStrings.PACKET_SIZE);
}
return fLostEvents;
}
- /**
- * Add an attribute to this index entry
- *
- * @param field
- * The name of the attribute
- * @param value
- * The value to insert
- */
- public void addAttribute(String field, Object value) {
- fAttributes.put(field, value);
- }
-
@Override
- public Object lookupAttribute(String field) {
- return fAttributes.get(field);
+ public Map<String, Object> getAttributes() {
+ return fAttributes;
}
@Override