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