1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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
.linuxtools
.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 final private long offsetBytes
;
35 * Offset of the data in the packet, in bits
37 private int dataOffsetBits
= 0;
40 * Packet size, in bits
42 private int packetSizeBits
= 0;
45 * Content size, in bits
47 private int contentSizeBits
= 0;
52 private long timestampBegin
= 0;
57 private long timestampEnd
= 0;
60 * How many lost events are there?
62 private long lostEvents
= 0;
65 * Which target is being traced
67 private String target
;
68 private long targetID
;
71 * Attributes of this index entry
73 private final Map
<String
, Object
> attributes
= new HashMap
<String
, Object
>();
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * Constructs an index entry.
84 * The offset of the packet in the file, in bytes.
87 public StreamInputPacketIndexEntry(long offset
) {
88 this.offsetBytes
= offset
;
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
96 * Returns whether the packet includes (inclusively) the given timestamp in
97 * the begin-end timestamp range.
100 * The timestamp to check.
101 * @return True if the packet includes the timestamp.
103 boolean includes(long ts
) {
104 return (ts
>= timestampBegin
) && (ts
<= timestampEnd
);
108 public String
toString() {
109 return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes
//$NON-NLS-1$
110 + ", timestampBegin=" + timestampBegin
+ ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
111 + timestampEnd
+ "]"; //$NON-NLS-1$
114 // ------------------------------------------------------------------------
115 // Getters and Setters
116 // ------------------------------------------------------------------------
119 * @return the offsetBytes
121 public long getOffsetBytes() {
126 * @return the dataOffsetBits
128 public int getDataOffsetBits() {
129 return dataOffsetBits
;
133 * @param dataOffsetBits
134 * the dataOffsetBits to set
136 public void setDataOffsetBits(int dataOffsetBits
) {
137 this.dataOffsetBits
= dataOffsetBits
;
141 * @return the packetSizeBits
143 public int getPacketSizeBits() {
144 return packetSizeBits
;
148 * @param packetSizeBits
149 * the packetSizeBits to set
151 public void setPacketSizeBits(int packetSizeBits
) {
152 this.packetSizeBits
= packetSizeBits
;
156 * @return the contentSizeBits
158 public int getContentSizeBits() {
159 return contentSizeBits
;
163 * @param contentSizeBits
164 * the contentSizeBits to set
166 public void setContentSizeBits(int contentSizeBits
) {
167 this.contentSizeBits
= contentSizeBits
;
171 * @return the timestampBegin
173 public long getTimestampBegin() {
174 return timestampBegin
;
178 * @param timestampBegin
179 * the timestampBegin to set
181 public void setTimestampBegin(long timestampBegin
) {
182 this.timestampBegin
= timestampBegin
;
186 * @return the timestampEnd
188 public long getTimestampEnd() {
193 * @param timestampEnd
194 * the timestampEnd to set
196 public void setTimestampEnd(long timestampEnd
) {
197 this.timestampEnd
= timestampEnd
;
201 * @return the lostEvents in this packet
203 public long getLostEvents() {
208 * @param lostEvents the lostEvents to set
210 public void setLostEvents(long lostEvents
) {
211 this.lostEvents
= 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 attributes
.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 attributes
.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
) {
251 this.target
= target
;
252 this.targetID
= Integer
.parseInt(target
.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
256 * @return The ID of the target
258 public long getTargetId(){