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
.TmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
21 * <b><u>TmfExperimentContext</u></b>
23 * The experiment keeps track of the next event from each of its traces so
24 * it can pick the next one in chronological order.
26 * This implies that the "next" event from each trace has already been
27 * read and that we at least know its timestamp. This doesn't imply that a
28 * full parse of the event content was performed (read: LTTng works like
31 * The last trace refers to the trace from which the last event was
32 * "consumed" at the experiment level.
34 public class TmfExperimentContext
extends TmfContext
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 public static final int NO_TRACE
= -1;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 private ITmfTrace
[] fTraces
= new ITmfTrace
[0];
47 private TmfContext
[] fContexts
;
48 private TmfEvent
[] fEvents
;
49 private int lastTraceRead
;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 public TmfExperimentContext(ITmfTrace
[] traces
, TmfContext
[] contexts
) {
59 fEvents
= new TmfEvent
[fTraces
.length
];
61 ITmfLocation
<?
>[] locations
= new ITmfLocation
[fTraces
.length
];
62 long[] ranks
= new long[fTraces
.length
];
64 for (int i
= 0; i
< fTraces
.length
; i
++) {
65 if (contexts
[i
] != null) {
66 locations
[i
] = contexts
[i
].getLocation();
67 ranks
[i
] = contexts
[i
].getRank();
68 rank
+= contexts
[i
].getRank();
72 setLocation(new TmfExperimentLocation(new TmfLocationArray(locations
), ranks
));
74 lastTraceRead
= NO_TRACE
;
77 public TmfExperimentContext(ITmfTrace
[] traces
) {
78 this(traces
, new TmfContext
[traces
.length
]);
81 public TmfExperimentContext(TmfExperimentContext other
) {
82 this(other
.fTraces
, other
.cloneContexts());
83 fEvents
= other
.fEvents
;
84 if (other
.getLocation() != null)
85 setLocation(other
.getLocation().clone());
86 setRank(other
.getRank());
87 setLastTrace(other
.lastTraceRead
);
90 private TmfContext
[] cloneContexts() {
91 TmfContext
[] contexts
= new TmfContext
[fContexts
.length
];
92 for (int i
= 0; i
< fContexts
.length
; i
++)
93 contexts
[i
] = fContexts
[i
].clone();
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
101 public ITmfTrace
[] getTraces() {
105 public TmfContext
[] getContexts() {
109 public TmfEvent
[] getEvents() {
113 public int getLastTrace() {
114 return lastTraceRead
;
117 public void setLastTrace(int newIndex
) {
118 lastTraceRead
= newIndex
;
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
126 public int hashCode() {
128 for (int i
= 0; i
< fTraces
.length
; i
++) {
129 result
= 37 * result
+ fTraces
[i
].hashCode();
130 result
= 37 * result
+ fContexts
[i
].hashCode();
136 public boolean equals(Object other
) {
137 if (!(other
instanceof TmfExperimentContext
)) {
140 TmfExperimentContext o
= (TmfExperimentContext
) other
;
141 boolean isEqual
= true;
143 while (isEqual
&& i
< fTraces
.length
) {
144 isEqual
&= fTraces
[i
].equals(o
.fTraces
[i
]);
145 isEqual
&= fContexts
[i
].equals(o
.fContexts
[i
]);