1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.trace
;
15 import java
.util
.HashMap
;
19 * <b><u>StreamInputPacketIndexEntry</u></b>
21 * Represents an entry in the index of event packets.
23 public class StreamInputPacketIndexEntry
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
30 * Offset of the packet in the file, in bytes
32 private final long fOffsetBytes
;
35 * Offset of the data in the packet, in bits
37 private long fDataOffsetBits
= 0;
40 * Packet size, in bits
42 private long fPacketSizeBits
= 0;
45 * Content size, in bits
47 private long fContentSizeBits
= 0;
52 private long fTimestampBegin
= 0;
57 private long fTimestampEnd
= 0;
60 * How many lost events are there?
62 private long fLostEvents
= 0;
65 * Which target is being traced
67 private String fTarget
;
68 private long fTargetID
;
71 * Attributes of this index entry
73 private final Map
<String
, Object
> fAttributes
= new HashMap
<>();
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * Constructs an index entry.
83 * The offset of the packet in the file, in bytes.
86 public StreamInputPacketIndexEntry(long offset
) {
87 fOffsetBytes
= offset
;
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 * Returns whether the packet includes (inclusively) the given timestamp in
96 * the begin-end timestamp range.
99 * The timestamp to check.
100 * @return True if the packet includes the timestamp.
102 boolean includes(long ts
) {
103 return (ts
>= fTimestampBegin
) && (ts
<= fTimestampEnd
);
107 public String
toString() {
108 return "StreamInputPacketIndexEntry [offsetBytes=" + fOffsetBytes
//$NON-NLS-1$
109 + ", timestampBegin=" + fTimestampBegin
+ ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
110 + fTimestampEnd
+ "]"; //$NON-NLS-1$
113 // ------------------------------------------------------------------------
114 // Getters and Setters
115 // ------------------------------------------------------------------------
118 * @return the offsetBytes
120 public long getOffsetBytes() {
125 * @return the dataOffsetBits
127 public long getDataOffsetBits() {
128 return fDataOffsetBits
;
132 * @param dataOffsetBits
133 * the dataOffsetBits to set
135 public void setDataOffsetBits(long dataOffsetBits
) {
136 fDataOffsetBits
= dataOffsetBits
;
140 * @return the packetSizeBits
142 public long getPacketSizeBits() {
143 return fPacketSizeBits
;
147 * @param packetSizeBits
148 * the packetSizeBits to set
150 public void setPacketSizeBits(long packetSizeBits
) {
151 fPacketSizeBits
= packetSizeBits
;
155 * @return the contentSizeBits
157 public long getContentSizeBits() {
158 return fContentSizeBits
;
162 * @param contentSizeBits
163 * the contentSizeBits to set
165 public void setContentSizeBits(long contentSizeBits
) {
166 fContentSizeBits
= contentSizeBits
;
170 * @return the timestampBegin
172 public long getTimestampBegin() {
173 return fTimestampBegin
;
177 * @param timestampBegin
178 * the timestampBegin to set
180 public void setTimestampBegin(long timestampBegin
) {
181 fTimestampBegin
= timestampBegin
;
185 * @return the timestampEnd
187 public long getTimestampEnd() {
188 return fTimestampEnd
;
192 * @param timestampEnd
193 * the timestampEnd to set
195 public void setTimestampEnd(long timestampEnd
) {
196 fTimestampEnd
= timestampEnd
;
200 * @return the lostEvents in this packet
202 public long getLostEvents() {
208 * the lostEvents to set
210 public void setLostEvents(long lostEvents
) {
211 fLostEvents
= lostEvents
;
215 * Add an attribute to this index entry
218 * The name of the attribute
220 * The value to insert
222 public void addAttribute(String field
, Object value
) {
223 fAttributes
.put(field
, value
);
227 * Retrieve the value of an existing attribute
230 * The name of the attribute
231 * @return The value that was stored, or null if it wasn't found
233 public Object
lookupAttribute(String field
) {
234 return fAttributes
.get(field
);
238 * @return The target that is being traced
240 public String
getTarget() {
245 * Assign a target to this index entry
248 * The target to assign
250 public void setTarget(String target
) {
252 fTargetID
= Integer
.parseInt(target
.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
256 * @return The ID of the target
258 public long getTargetId() {