Fix copyright notice
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / evProcessor / AbsFlowTRangeUpdate.java
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 *
9 * Contributors:
10 * Alvaro Sanchez-Leon - Initial implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor;
14
15 import java.util.Vector;
16
17 import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus;
18 import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor;
19 import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
20 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
21 import org.eclipse.linuxtools.lttng.ui.TraceDebug;
22 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeComponent;
23 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent;
24 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent.Type;
25 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
26 import org.eclipse.linuxtools.lttng.ui.views.common.AbsTRangeUpdate;
27 import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater;
28 import org.eclipse.linuxtools.lttng.ui.views.controlflow.model.FlowModelFactory;
29 import org.eclipse.linuxtools.lttng.ui.views.controlflow.model.FlowProcessContainer;
30
31 public abstract class AbsFlowTRangeUpdate extends AbsTRangeUpdate implements ILttngEventProcessor {
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) {
46 // TimeRangeEventProcess localProcess = new TimeRangeEventProcess(id, name, startTime, stopTime, groupName, className)
47 TimeRangeEventProcess localProcess = new TimeRangeEventProcess(
48 procContainer.getUniqueId(), stateProcess.getName(),
49 traceStartTime, traceEndTime, "", stateProcess.getType() //$NON-NLS-1$
50 .getInName(), stateProcess.getCpu(), stateProcess
51 .getInsertion_time());
52
53
54 localProcess.setCreationTime(stateProcess.getCreation_time());
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());
62 procContainer.addItem(localProcess);
63
64 if (TraceDebug.isCFV()) {
65 TraceDebug.traceCFV("addLocalProcess():" + localProcess); //$NON-NLS-1$
66 }
67
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 */
112 protected boolean makeDraw(LttngTraceState traceSt, long startTime,
113 long endTime, TimeRangeEventProcess localProcess,
114 ParamsUpdater params, String stateMode) {
115
116 if (TraceDebug.isCFV()) {
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$
121 }
122
123 // Determine start and end times to establish duration
124 Long stime = startTime;
125 Long etime = endTime;
126
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 }
133
134 if (etime < stime) {
135 // Validate the sequential order of events
136 params.incrementEventsDiscardedWrongOrder();
137 return false;
138 }
139
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);
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 }
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;
173 if (pixels < 1.0) {
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
191 && ((double) eventSpan * k) < 2.0) {
192
193 // discard the item
194 params.incrementEventsDiscarded(ParamsUpdater.NOT_VISIBLE);
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);
211 localProcess.setNext_good_time(etime);
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 */
224 protected boolean makeDraw(LttngTraceState traceSt, long evTime,
225 LttngProcessState process, TimeRangeEventProcess localProcess,
226 ParamsUpdater params) {
227
228 // TmfTimestamp stime = process.getState().getChange_LttTime();
229 long stime = localProcess.getNext_good_time();
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.039048 seconds and 6 git commands to generate.