1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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
);
110 * @see java.lang.Object#toString()
113 public String
toString() {
114 return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes
//$NON-NLS-1$
115 + ", timestampBegin=" + timestampBegin
+ ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
116 + timestampEnd
+ "]"; //$NON-NLS-1$
119 // ------------------------------------------------------------------------
120 // Getters and Setters
121 // ------------------------------------------------------------------------
124 * @return the offsetBytes
126 public long getOffsetBytes() {
131 * @return the dataOffsetBits
133 public int getDataOffsetBits() {
134 return dataOffsetBits
;
138 * @param dataOffsetBits
139 * the dataOffsetBits to set
141 public void setDataOffsetBits(int dataOffsetBits
) {
142 this.dataOffsetBits
= dataOffsetBits
;
146 * @return the packetSizeBits
148 public int getPacketSizeBits() {
149 return packetSizeBits
;
153 * @param packetSizeBits
154 * the packetSizeBits to set
156 public void setPacketSizeBits(int packetSizeBits
) {
157 this.packetSizeBits
= packetSizeBits
;
161 * @return the contentSizeBits
163 public int getContentSizeBits() {
164 return contentSizeBits
;
168 * @param contentSizeBits
169 * the contentSizeBits to set
171 public void setContentSizeBits(int contentSizeBits
) {
172 this.contentSizeBits
= contentSizeBits
;
176 * @return the timestampBegin
178 public long getTimestampBegin() {
179 return timestampBegin
;
183 * @param timestampBegin
184 * the timestampBegin to set
186 public void setTimestampBegin(long timestampBegin
) {
187 this.timestampBegin
= timestampBegin
;
191 * @return the timestampEnd
193 public long getTimestampEnd() {
198 * @param timestampEnd
199 * the timestampEnd to set
201 public void setTimestampEnd(long timestampEnd
) {
202 this.timestampEnd
= timestampEnd
;
206 * @return the lostEvents
208 public long getLostEvents() {
213 * @param lostEvents the lostEvents to set
215 public void setLostEvents(long lostEvents
) {
216 this.lostEvents
= lostEvents
;
220 * Add an attribute to this index entry
223 * The name of the atrribute
225 * The value to insert
227 public void addAttribute(String field
, Object value
) {
228 attributes
.put(field
, value
);
232 * Retrieve the value of an existing attribute
235 * The name of the attribute
236 * @return The value that was stored, or null if it wasn't found
238 public Object
lookupAttribute(String field
){
239 return attributes
.get(field
);
243 * @return The target that is being traced
245 public String
getTarget() {
250 * Assign a target to this index entry
253 * The target to assign
255 public void setTarget(String target
) {
256 this.target
= target
;
257 this.targetID
= Integer
.parseInt(target
.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
261 * @return The ID of the target
263 public long getTargetId(){