Merge branch 'FixJUnits'
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / evProcessor / AbsFlowTRangeUpdate.java
CommitLineData
6e512b93
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 *
860cadcf
FC
9 * Contributors:
10 * Alvaro Sanchez-Leon - Initial implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
6e512b93
ASL
12 *******************************************************************************/
13package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor;
14
15import java.util.Vector;
16
17import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus;
8827c197 18import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor;
6e512b93
ASL
19import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
20import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
0c2a2e08 21import org.eclipse.linuxtools.lttng.ui.TraceDebug;
6e512b93
ASL
22import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeComponent;
23import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent;
6e512b93 24import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent.Type;
a72a38d9 25import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
6e512b93
ASL
26import org.eclipse.linuxtools.lttng.ui.views.common.AbsTRangeUpdate;
27import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater;
28import org.eclipse.linuxtools.lttng.ui.views.controlflow.model.FlowModelFactory;
29import org.eclipse.linuxtools.lttng.ui.views.controlflow.model.FlowProcessContainer;
30
8827c197 31public abstract class AbsFlowTRangeUpdate extends AbsTRangeUpdate implements ILttngEventProcessor {
6e512b93
ASL
32
33 // ========================================================================
34 // Data
35 // =======================================================================
36
37 protected FlowProcessContainer procContainer = FlowModelFactory.getProcContainer();
38 protected ParamsUpdater params = FlowModelFactory.getParamsUpdater();
39 protected static final Long ANY_CPU = 0L;
40
41
42 // ========================================================================
43 // Methods
44 // =======================================================================
45 protected TimeRangeEventProcess addLocalProcess(LttngProcessState stateProcess, long traceStartTime, long traceEndTime, String traceId) {
63eecb47
FC
46 // TimeRangeEventProcess localProcess = new TimeRangeEventProcess(id, name, startTime, stopTime, groupName, className)
47 TimeRangeEventProcess localProcess = new TimeRangeEventProcess(
b513223f 48 procContainer.getUniqueId(), stateProcess.getName(),
3b38ea61 49 traceStartTime, traceEndTime, "", stateProcess.getType() //$NON-NLS-1$
63eecb47 50 .getInName(), stateProcess.getCpu(), stateProcess
28b94d61
FC
51 .getInsertion_time());
52
53
54 localProcess.setCreationTime(stateProcess.getCreation_time());
6e512b93
ASL
55 localProcess.setPid(stateProcess.getPid());
56 localProcess.setTgid(stateProcess.getTgid());
57 localProcess.setPpid(stateProcess.getPpid());
58 localProcess.setName(stateProcess.getName());
59 localProcess.setBrand(stateProcess.getBrand());
60 localProcess.setTraceID(traceId);
61 localProcess.setProcessType(stateProcess.getType().getInName());
8827c197 62 procContainer.addItem(localProcess);
0c2a2e08
FC
63
64 if (TraceDebug.isCFV()) {
3b38ea61 65 TraceDebug.traceCFV("addLocalProcess():" + localProcess); //$NON-NLS-1$
0c2a2e08
FC
66 }
67
6e512b93
ASL
68 return localProcess;
69 }
70
71 /**
72 * Used to check if the event is visible within the current visible time
73 * window
74 *
75 * @return
76 */
77 protected boolean withinViewRange(long stime, long etime) {
78 long windowStartTime = params.getStartTime();
79 long windowEndTime = params.getEndTime();
80
81 // start time is within window
82 if (stime >= windowStartTime && stime <= windowEndTime) {
83 // The event or part of it shall be displayed.
84 return true;
85 }
86
87 // end time is within window
88 if (etime >= windowStartTime && etime <= windowEndTime) {
89 // The event or part of it shall be displayed.
90 return true;
91 }
92
93 // check that a portion is within the window
94 if (stime < windowStartTime && etime > windowEndTime) {
95 // The time range is bigger than the selected time window and
96 // crosses it
97 return true;
98 }
99
100 return false;
101 }
102
103 /**
104 * @param traceSt
105 * @param startTime
106 * @param endTime
107 * @param localProcess
108 * @param params
109 * @param stateMode
110 * @return
111 */
41dc35d0
FC
112 protected boolean makeDraw(LttngTraceState traceSt, long startTime,
113 long endTime, TimeRangeEventProcess localProcess,
6e512b93
ASL
114 ParamsUpdater params, String stateMode) {
115
0c2a2e08 116 if (TraceDebug.isCFV()) {
3b38ea61
FC
117 TraceDebug.traceCFV("makeDraw():[" + localProcess + //$NON-NLS-1$
118 ",candidate=[stime=" + startTime + //$NON-NLS-1$
119 ",etime=" + endTime + //$NON-NLS-1$
120 ",state=" + stateMode + "]]"); //$NON-NLS-1$ //$NON-NLS-2$
0c2a2e08
FC
121 }
122
6e512b93 123 // Determine start and end times to establish duration
41dc35d0
FC
124 Long stime = startTime;
125 Long etime = endTime;
6e512b93 126
a72a38d9
ASL
127 if (!withinViewRange(stime, etime)) {
128 // No use to process the event since it's outside
129 // the visible time range of the window
130 params.incrementEventsDiscarded(ParamsUpdater.OUT_OF_VIEWRANGE);
131 return false;
132 }
5dbe4d3b 133
6e512b93
ASL
134 if (etime < stime) {
135 // Validate the sequential order of events
136 params.incrementEventsDiscardedWrongOrder();
137 return false;
138 }
139
8827c197
FC
140 // Store the next good time to start drawing the next event
141 // this is done this early to display an accurate start time of the
142 // first event
143 // within the display window
144 // ****** moved at the end since it produces gaps among the coloured rectangles
145 // localProcess.setNext_good_time(etime);
a72a38d9
ASL
146
147 // If First event of a process, initialise start time half page before to enable pagination to the left
148 if (stime < params.getStartTime()) {
149 // event start time is before the visible time window
150 long insertion = localProcess.getInsertionTime();
151 if (stime.longValue() == insertion) {
152 // if start time is equal to insertion this is the first event to be drawn for this process
153 long halfPage = (params.getEndTime() - params.getStartTime()) / 2;
154 long initTime = params.getStartTime() - halfPage;
155 if (initTime > insertion) {
156 // start time of this event is unknown, place it half page before visible window to allow left side
157 // pagination when selecting previous event
158 stime = initTime;
159 }
160 }
6e512b93
ASL
161 }
162
163 // Determine if the time range event will fit it the current
164 // pixel map
165 double duration = etime - stime;
166 double k = getPixelsPerNs(traceSt, params);
167 double pixels = duration * k;
168
169 // Visibility check
170 // Display a "more information" indication by allowing non visible event
171 // as long as its previous event is visible.
172 boolean visible = true;
0c2a2e08 173 if (pixels < 1.0) {
6e512b93
ASL
174 boolean prevEventVisibility = true;
175 // Get the visibility indication on previous event for
176 // this process
177 Vector<TimeRangeComponent> inMemEvents = localProcess
178 .getTraceEvents();
179 if (inMemEvents.size() != 0) {
180 TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents
181 .size() - 1);
182 prevEventVisibility = prevEvent.isVisible();
183
184 // if previous event visibility is false and the time span
185 // between events less than two pixels, there is no need to
186 // load it in memory i.e. not visible and a more indicator is
187 // within two pixels.
188 // return i.e. event discarded to free up memory
189 Long eventSpan = stime - prevEvent.getStartTime();
190 if (prevEventVisibility == false
0c2a2e08 191 && ((double) eventSpan * k) < 2.0) {
6e512b93
ASL
192
193 // discard the item
5dbe4d3b 194 params.incrementEventsDiscarded(ParamsUpdater.NOT_VISIBLE);
6e512b93
ASL
195 return false;
196
197 }
198 }
199
200 // if previous event is visible, set this one to not
201 // visible and continue
202 visible = false;
203 }
204
205 // Create the time-range event
206 TimeRangeEvent time_window = new TimeRangeEvent(stime, etime,
207 localProcess, Type.PROCESS_MODE, stateMode);
208
209 time_window.setVisible(visible);
210 localProcess.getTraceEvents().add(time_window);
41dc35d0 211 localProcess.setNext_good_time(etime);
6e512b93
ASL
212
213 return false;
214 }
215
216 /**
217 * @param traceSt
218 * @param evTime
219 * @param process
220 * @param localProcess
221 * @param params
222 * @return
223 */
41dc35d0 224 protected boolean makeDraw(LttngTraceState traceSt, long evTime,
6e512b93
ASL
225 LttngProcessState process, TimeRangeEventProcess localProcess,
226 ParamsUpdater params) {
227
41dc35d0
FC
228 // TmfTimestamp stime = process.getState().getChange_LttTime();
229 long stime = localProcess.getNext_good_time();
6e512b93
ASL
230
231 String stateMode;
232 ProcessStatus procStatus = process.getState().getProc_status();
233 // Use Execution mode if process state is RUN otherwise use the actual
234 // process state,
235 // this selection will determine the actual color selected for the event
236 if (procStatus == ProcessStatus.LTTV_STATE_RUN) {
237 stateMode = process.getState().getExec_mode().getInName();
238 } else {
239 stateMode = procStatus.getInName();
240 }
241
242 return makeDraw(traceSt, stime, evTime, localProcess, params, stateMode);
243
244 }
245
246}
This page took 0.041354 seconds and 5 git commands to generate.