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