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 | ||
13 | package org.eclipse.linuxtools.tmf.experiment; | |
14 | ||
15 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
16 | import org.eclipse.linuxtools.tmf.trace.ITmfLocation; | |
17 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; | |
18 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
19 | ||
20 | /** | |
21 | * <b><u>TmfExperimentContext</u></b> | |
22 | * <p> | |
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. | |
25 | * <p> | |
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 | |
29 | * this). | |
30 | * <p> | |
31 | * The last trace refers to the trace from which the last event was | |
32 | * "consumed" at the experiment level. | |
33 | */ | |
34 | public class TmfExperimentContext extends TmfContext { | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Constants | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | public static final int NO_TRACE = -1; | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Attributes | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
46 | private ITmfTrace[] fTraces = new ITmfTrace[0]; | |
47 | private TmfContext[] fContexts; | |
48 | private TmfEvent[] fEvents; | |
49 | private int lastTrace; | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Constructors | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
55 | public TmfExperimentContext(ITmfTrace[] traces, TmfContext[] contexts) { | |
56 | super(); | |
57 | fTraces = traces; | |
58 | fContexts = contexts; | |
59 | fEvents = new TmfEvent[fTraces.length]; | |
60 | ||
61 | ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length]; | |
62 | long[] ranks = new long[fTraces.length]; | |
63 | long rank = 0; | |
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(); | |
69 | } | |
70 | } | |
71 | ||
72 | setLocation(new TmfExperimentLocation(locations, ranks)); | |
73 | setRank(rank); | |
74 | lastTrace = NO_TRACE; | |
75 | } | |
76 | ||
77 | public TmfExperimentContext(ITmfTrace[] traces) { | |
78 | this(traces, new TmfContext[traces.length]); | |
79 | } | |
80 | ||
81 | public TmfExperimentContext(TmfExperimentContext other) { | |
82 | this(other.fTraces, other.cloneContexts()); | |
83 | fEvents = other.fEvents; | |
84 | setLocation(other.getLocation().clone()); | |
85 | setRank(other.getRank()); | |
86 | setLastTrace(other.lastTrace); | |
87 | } | |
88 | ||
89 | private TmfContext[] cloneContexts() { | |
90 | TmfContext[] contexts = new TmfContext[fContexts.length]; | |
91 | for (int i = 0; i < fContexts.length; i++) | |
92 | contexts[i] = fContexts[i].clone(); | |
93 | return contexts; | |
94 | } | |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // Accessors | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | public ITmfTrace[] getTraces() { | |
101 | return fTraces; | |
102 | } | |
103 | ||
104 | public TmfContext[] getContexts() { | |
105 | return fContexts; | |
106 | } | |
107 | ||
108 | public TmfEvent[] getEvents() { | |
109 | return fEvents; | |
110 | } | |
111 | ||
112 | public int getLastTrace() { | |
113 | return lastTrace; | |
114 | } | |
115 | ||
116 | public void setLastTrace(int newIndex) { | |
117 | lastTrace = newIndex; | |
118 | } | |
119 | ||
120 | } |