Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
ce2388e0 | 3 | * |
8c8bf09f ASL |
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 | |
ce2388e0 | 8 | * |
8c8bf09f ASL |
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> | |
cbdacf03 FC |
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. | |
8f50c396 | 26 | * <p> |
ce2388e0 | 27 | <<<<<<< HEAD |
cbdacf03 FC |
28 | * This implies that the "next" event from each trace has already been read and |
29 | * that we at least know its timestamp. This doesn't imply that a full parse of | |
30 | * the event content was performed (read: LTTng works like this). | |
ce2388e0 FC |
31 | ======= |
32 | * This implies that the "next" event from each trace has already been | |
33 | * read and that we at least know its timestamp. This doesn't imply that a | |
34 | * full parse of the event content was performed (read: LTTng works like | |
35 | * this). | |
36 | >>>>>>> refs/heads/master | |
8f50c396 | 37 | * <p> |
cbdacf03 FC |
38 | * The last trace refers to the trace from which the last event was "consumed" |
39 | * at the experiment level. | |
8c8bf09f | 40 | */ |
9f584e4c FC |
41 | public class TmfExperimentContext extends TmfContext { |
42 | ||
cbdacf03 FC |
43 | // ------------------------------------------------------------------------ |
44 | // Constants | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
47 | public static final int NO_TRACE = -1; | |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // Attributes | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
53 | private ITmfTrace<?>[] fTraces = new ITmfTrace[0]; | |
54 | private final ITmfContext[] fContexts; | |
ce2388e0 | 55 | private ITmfEvent[] fEvents; |
cbdacf03 FC |
56 | private int lastTraceRead; |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // Constructors | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
62 | public TmfExperimentContext(final ITmfTrace<?>[] traces, final ITmfContext[] contexts) { | |
63 | super(); | |
64 | fTraces = traces; | |
65 | fContexts = contexts; | |
66 | fEvents = new ITmfEvent[fTraces.length]; | |
67 | ||
68 | final ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length]; | |
69 | final long[] ranks = new long[fTraces.length]; | |
70 | long rank = 0; | |
71 | for (int i = 0; i < fTraces.length; i++) | |
72 | if (contexts[i] != null) { | |
73 | locations[i] = contexts[i].getLocation(); | |
74 | ranks[i] = contexts[i].getRank(); | |
75 | rank += contexts[i].getRank(); | |
76 | } | |
77 | ||
78 | setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks)); | |
79 | setRank(rank); | |
80 | lastTraceRead = NO_TRACE; | |
81 | } | |
82 | ||
ce2388e0 FC |
83 | public TmfExperimentContext(final TmfExperimentContext other) { |
84 | this(other.fTraces, other.cloneContexts()); | |
85 | fEvents = other.fEvents; | |
86 | if (other.getLocation() != null) | |
87 | setLocation(other.getLocation().clone()); | |
88 | setRank(other.getRank()); | |
89 | setLastTrace(other.lastTraceRead); | |
90 | } | |
91 | ||
cbdacf03 FC |
92 | public TmfExperimentContext(final ITmfTrace<?>[] traces) { |
93 | this(traces, new TmfContext[traces.length]); | |
94 | } | |
95 | ||
ce2388e0 FC |
96 | private ITmfContext[] cloneContexts() { |
97 | final ITmfContext[] contexts = new ITmfContext[fContexts.length]; | |
98 | for (int i = 0; i < fContexts.length; i++) | |
99 | contexts[i] = fContexts[i].clone(); | |
100 | return contexts; | |
101 | } | |
102 | ||
103 | ||
104 | // public TmfExperimentContext(TmfExperimentContext other) { | |
105 | // this(other.fTraces, other.cloneContexts()); | |
106 | // fEvents = other.fEvents; | |
107 | // if (other.getLocation() != null) | |
108 | // setLocation(other.getLocation().clone()); | |
109 | // setRank(other.getRank()); | |
110 | // setLastTrace(other.lastTraceRead); | |
111 | // } | |
112 | ||
113 | // private ITmfContext[] cloneContexts() { | |
114 | // ITmfContext[] contexts = new TmfContext[fContexts.length]; | |
115 | // for (int i = 0; i < fContexts.length; i++) | |
116 | // contexts[i] = fContexts[i].clone(); | |
117 | // return contexts; | |
118 | // } | |
cbdacf03 FC |
119 | |
120 | // ------------------------------------------------------------------------ | |
121 | // Accessors | |
122 | // ------------------------------------------------------------------------ | |
123 | ||
124 | public ITmfTrace<?>[] getTraces() { | |
125 | return fTraces; | |
126 | } | |
127 | ||
128 | public ITmfContext[] getContexts() { | |
129 | return fContexts; | |
130 | } | |
131 | ||
132 | public ITmfEvent[] getEvents() { | |
133 | return fEvents; | |
134 | } | |
135 | ||
136 | public int getLastTrace() { | |
137 | return lastTraceRead; | |
138 | } | |
139 | ||
140 | public void setLastTrace(final int newIndex) { | |
141 | lastTraceRead = newIndex; | |
142 | } | |
143 | ||
144 | // ------------------------------------------------------------------------ | |
145 | // Object | |
146 | // ------------------------------------------------------------------------ | |
550d787e FC |
147 | |
148 | @Override | |
149 | public int hashCode() { | |
cbdacf03 FC |
150 | int result = 17; |
151 | for (int i = 0; i < fTraces.length; i++) { | |
152 | result = 37 * result + fTraces[i].hashCode(); | |
153 | result = 37 * result + fContexts[i].hashCode(); | |
154 | } | |
155 | return result; | |
550d787e | 156 | } |
cbdacf03 | 157 | |
550d787e | 158 | @Override |
cbdacf03 | 159 | public boolean equals(final Object other) { |
6e85c58d FC |
160 | if (this == other) |
161 | return true; | |
162 | if (!super.equals(other)) | |
163 | return false; | |
cbdacf03 FC |
164 | if (!(other instanceof TmfExperimentContext)) |
165 | return false; | |
166 | final TmfExperimentContext o = (TmfExperimentContext) other; | |
167 | boolean isEqual = true; | |
168 | int i = 0; | |
169 | while (isEqual && i < fTraces.length) { | |
170 | isEqual &= fTraces[i].equals(o.fTraces[i]); | |
171 | isEqual &= fContexts[i].equals(o.fContexts[i]); | |
172 | i++; | |
173 | } | |
174 | return isEqual; | |
550d787e | 175 | } |
cbdacf03 | 176 | |
8c8bf09f | 177 | } |