Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.experiment; |
8c8bf09f | 14 | |
72f1e62a | 15 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
34ccf9a9 | 16 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
6c13869b FC |
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; | |
8c8bf09f ASL |
20 | |
21 | /** | |
22 | * <b><u>TmfExperimentContext</u></b> | |
23 | * <p> | |
8f50c396 FC |
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. | |
26 | * <p> | |
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 | |
30 | * this). | |
31 | * <p> | |
32 | * The last trace refers to the trace from which the last event was | |
33 | * "consumed" at the experiment level. | |
8c8bf09f | 34 | */ |
9f584e4c FC |
35 | public class TmfExperimentContext extends TmfContext { |
36 | ||
8f50c396 FC |
37 | // ------------------------------------------------------------------------ |
38 | // Constants | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
41 | public static final int NO_TRACE = -1; | |
42 | ||
43 | // ------------------------------------------------------------------------ | |
44 | // Attributes | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
4df4581d | 47 | private ITmfTrace<?>[] fTraces = new ITmfTrace[0]; |
8636b448 | 48 | private ITmfContext[] fContexts; |
72f1e62a | 49 | private ITmfEvent[] fEvents; |
9b635e61 | 50 | private int lastTraceRead; |
8c8bf09f | 51 | |
9f584e4c FC |
52 | // ------------------------------------------------------------------------ |
53 | // Constructors | |
54 | // ------------------------------------------------------------------------ | |
8c8bf09f | 55 | |
8636b448 | 56 | public TmfExperimentContext(ITmfTrace<?>[] traces, ITmfContext[] contexts) { |
9f584e4c FC |
57 | super(); |
58 | fTraces = traces; | |
59 | fContexts = contexts; | |
72f1e62a | 60 | fEvents = new ITmfEvent[fTraces.length]; |
8c8bf09f | 61 | |
452ad365 | 62 | ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length]; |
8f50c396 | 63 | long[] ranks = new long[fTraces.length]; |
9f584e4c FC |
64 | long rank = 0; |
65 | for (int i = 0; i < fTraces.length; i++) { | |
66 | if (contexts[i] != null) { | |
67 | locations[i] = contexts[i].getLocation(); | |
8f50c396 | 68 | ranks[i] = contexts[i].getRank(); |
9f584e4c FC |
69 | rank += contexts[i].getRank(); |
70 | } | |
8c8bf09f | 71 | } |
9f584e4c | 72 | |
a79913eb | 73 | setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks)); |
9f584e4c | 74 | setRank(rank); |
9b635e61 | 75 | lastTraceRead = NO_TRACE; |
8c8bf09f ASL |
76 | } |
77 | ||
4df4581d | 78 | public TmfExperimentContext(ITmfTrace<?>[] traces) { |
9f584e4c | 79 | this(traces, new TmfContext[traces.length]); |
8c8bf09f ASL |
80 | } |
81 | ||
9f584e4c FC |
82 | public TmfExperimentContext(TmfExperimentContext other) { |
83 | this(other.fTraces, other.cloneContexts()); | |
84 | fEvents = other.fEvents; | |
9b635e61 FC |
85 | if (other.getLocation() != null) |
86 | setLocation(other.getLocation().clone()); | |
9f584e4c | 87 | setRank(other.getRank()); |
9b635e61 | 88 | setLastTrace(other.lastTraceRead); |
8c8bf09f ASL |
89 | } |
90 | ||
8636b448 FC |
91 | private ITmfContext[] cloneContexts() { |
92 | ITmfContext[] contexts = new TmfContext[fContexts.length]; | |
8c8bf09f ASL |
93 | for (int i = 0; i < fContexts.length; i++) |
94 | contexts[i] = fContexts[i].clone(); | |
95 | return contexts; | |
96 | } | |
97 | ||
9f584e4c FC |
98 | // ------------------------------------------------------------------------ |
99 | // Accessors | |
100 | // ------------------------------------------------------------------------ | |
101 | ||
4df4581d | 102 | public ITmfTrace<?>[] getTraces() { |
9f584e4c FC |
103 | return fTraces; |
104 | } | |
105 | ||
34ccf9a9 | 106 | public ITmfContext[] getContexts() { |
9f584e4c FC |
107 | return fContexts; |
108 | } | |
109 | ||
72f1e62a | 110 | public ITmfEvent[] getEvents() { |
8c8bf09f ASL |
111 | return fEvents; |
112 | } | |
113 | ||
7f407ead | 114 | public int getLastTrace() { |
9b635e61 | 115 | return lastTraceRead; |
7f407ead FC |
116 | } |
117 | ||
118 | public void setLastTrace(int newIndex) { | |
9b635e61 | 119 | lastTraceRead = newIndex; |
7f407ead FC |
120 | } |
121 | ||
550d787e FC |
122 | // ------------------------------------------------------------------------ |
123 | // Object | |
124 | // ------------------------------------------------------------------------ | |
125 | ||
126 | @Override | |
127 | public int hashCode() { | |
128 | int result = 17; | |
129 | for (int i = 0; i < fTraces.length; i++) { | |
130 | result = 37 * result + fTraces[i].hashCode(); | |
131 | result = 37 * result + fContexts[i].hashCode(); | |
132 | } | |
133 | return result; | |
134 | } | |
135 | ||
136 | @Override | |
137 | public boolean equals(Object other) { | |
6e85c58d FC |
138 | if (this == other) |
139 | return true; | |
140 | if (!super.equals(other)) | |
141 | return false; | |
550d787e FC |
142 | if (!(other instanceof TmfExperimentContext)) { |
143 | return false; | |
144 | } | |
145 | TmfExperimentContext o = (TmfExperimentContext) other; | |
146 | boolean isEqual = true; | |
147 | int i = 0; | |
148 | while (isEqual && i < fTraces.length) { | |
149 | isEqual &= fTraces[i].equals(o.fTraces[i]); | |
150 | isEqual &= fContexts[i].equals(o.fContexts[i]); | |
9b635e61 | 151 | i++; |
550d787e FC |
152 | } |
153 | return isEqual; | |
154 | } | |
155 | ||
8c8bf09f | 156 | } |