1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made 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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Put in shape for 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
22 * The experiment context in TMF.
24 * The experiment keeps track of the next event from each of its traces so it
25 * can pick the next one in chronological order.
27 * This implies that the "next" event from each trace has already been
28 * read and that we at least know its timestamp. This doesn't imply that a
29 * full parse of the event content was performed (read: the legacy LTTng works
32 * The last trace refers to the trace from which the last event was "consumed"
33 * at the experiment level.
35 public class TmfExperimentContext
extends TmfContext
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 * No last trace read indicator
44 public static final int NO_TRACE
= -1;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 // private ITmfTrace<?>[] fTraces = new ITmfTrace[0];
51 private final ITmfContext
[] fContexts
;
52 private ITmfEvent
[] fEvents
;
53 private int lastTraceRead
;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 public TmfExperimentContext(final ITmfContext
[] contexts
) {
63 fEvents
= new ITmfEvent
[fContexts
.length
];
64 final ITmfLocation
<?
>[] locations
= new ITmfLocation
[fContexts
.length
];
65 final long[] ranks
= new long[fContexts
.length
];
67 for (int i
= 0; i
< fContexts
.length
; i
++)
68 if (contexts
[i
] != null) {
69 locations
[i
] = contexts
[i
].getLocation();
70 ranks
[i
] = contexts
[i
].getRank();
71 rank
+= contexts
[i
].getRank();
74 setLocation(new TmfExperimentLocation(new TmfLocationArray(locations
)));
76 lastTraceRead
= NO_TRACE
;
79 public TmfExperimentContext(final TmfExperimentContext other
) {
80 this(other
.cloneContexts());
81 fEvents
= other
.fEvents
;
82 if (other
.getLocation() != null)
83 setLocation(other
.getLocation().clone());
84 setRank(other
.getRank());
85 setLastTrace(other
.lastTraceRead
);
88 // public TmfExperimentContext(final ITmfTrace<?>[] traces) {
89 // this(traces, new TmfContext[traces.length]);
92 private ITmfContext
[] cloneContexts() {
93 final ITmfContext
[] contexts
= new ITmfContext
[fContexts
.length
];
94 for (int i
= 0; i
< fContexts
.length
; i
++)
95 contexts
[i
] = fContexts
[i
].clone();
100 // public TmfExperimentContext(TmfExperimentContext other) {
101 // this(other.fTraces, other.cloneContexts());
102 // fEvents = other.fEvents;
103 // if (other.getLocation() != null)
104 // setLocation(other.getLocation().clone());
105 // setRank(other.getRank());
106 // setLastTrace(other.lastTraceRead);
109 // private ITmfContext[] cloneContexts() {
110 // ITmfContext[] contexts = new TmfContext[fContexts.length];
111 // for (int i = 0; i < fContexts.length; i++)
112 // contexts[i] = fContexts[i].clone();
116 // ------------------------------------------------------------------------
118 // ------------------------------------------------------------------------
120 // public ITmfTrace<?>[] getTraces() {
124 public ITmfContext
[] getContexts() {
128 public ITmfEvent
[] getEvents() {
132 public int getLastTrace() {
133 return lastTraceRead
;
136 public void setLastTrace(final int newIndex
) {
137 lastTraceRead
= newIndex
;
140 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
145 public int hashCode() {
147 for (int i
= 0; i
< fContexts
.length
; i
++) {
148 // result = 37 * result + fTraces[i].hashCode();
149 result
= 37 * result
+ fContexts
[i
].hashCode();
155 public boolean equals(final Object other
) {
158 if (!super.equals(other
))
160 if (!(other
instanceof TmfExperimentContext
))
162 final TmfExperimentContext o
= (TmfExperimentContext
) other
;
163 boolean isEqual
= true;
165 while (isEqual
&& (i
< fContexts
.length
)) {
166 // isEqual &= fTraces[i].equals(o.fTraces[i]);
167 isEqual
&= fContexts
[i
].equals(o
.fContexts
[i
]);