1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.experiment
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
22 * <b><u>TmfExperimentContext</u></b>
24 * The experiment keeps track of the next event from each of its traces so
25 * it 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: LTTng works like
32 * The last trace refers to the trace from which the last event was
33 * "consumed" at the experiment level.
35 public class TmfExperimentContext
extends TmfContext
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 public static final int NO_TRACE
= -1;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 private ITmfTrace
<?
>[] fTraces
= new ITmfTrace
[0];
48 private TmfContext
[] fContexts
;
49 private ITmfEvent
[] fEvents
;
50 private int lastTraceRead
;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 public TmfExperimentContext(ITmfTrace
<?
>[] traces
, TmfContext
[] contexts
) {
60 fEvents
= new ITmfEvent
[fTraces
.length
];
62 ITmfLocation
<?
>[] locations
= new ITmfLocation
[fTraces
.length
];
63 long[] ranks
= new long[fTraces
.length
];
65 for (int i
= 0; i
< fTraces
.length
; i
++) {
66 if (contexts
[i
] != null) {
67 locations
[i
] = contexts
[i
].getLocation();
68 ranks
[i
] = contexts
[i
].getRank();
69 rank
+= contexts
[i
].getRank();
73 setLocation(new TmfExperimentLocation(new TmfLocationArray(locations
), ranks
));
75 lastTraceRead
= NO_TRACE
;
78 public TmfExperimentContext(ITmfTrace
<?
>[] traces
) {
79 this(traces
, new TmfContext
[traces
.length
]);
82 public TmfExperimentContext(TmfExperimentContext other
) {
83 this(other
.fTraces
, other
.cloneContexts());
84 fEvents
= other
.fEvents
;
85 if (other
.getLocation() != null)
86 setLocation(other
.getLocation().clone());
87 setRank(other
.getRank());
88 setLastTrace(other
.lastTraceRead
);
91 private TmfContext
[] cloneContexts() {
92 TmfContext
[] contexts
= new TmfContext
[fContexts
.length
];
93 for (int i
= 0; i
< fContexts
.length
; i
++)
94 contexts
[i
] = fContexts
[i
].clone();
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
102 public ITmfTrace
<?
>[] getTraces() {
106 public ITmfContext
[] getContexts() {
110 public ITmfEvent
[] getEvents() {
114 public int getLastTrace() {
115 return lastTraceRead
;
118 public void setLastTrace(int newIndex
) {
119 lastTraceRead
= newIndex
;
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 public int hashCode() {
129 for (int i
= 0; i
< fTraces
.length
; i
++) {
130 result
= 37 * result
+ fTraces
[i
].hashCode();
131 result
= 37 * result
+ fContexts
[i
].hashCode();
137 public boolean equals(Object other
) {
140 if (!super.equals(other
))
142 if (!(other
instanceof TmfExperimentContext
)) {
145 TmfExperimentContext o
= (TmfExperimentContext
) other
;
146 boolean isEqual
= true;
148 while (isEqual
&& i
< fTraces
.length
) {
149 isEqual
&= fTraces
[i
].equals(o
.fTraces
[i
]);
150 isEqual
&= fContexts
[i
].equals(o
.fContexts
[i
]);