Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ |
13 | package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor; | |
14 | ||
15 | import java.util.Vector; | |
16 | ||
5945cec9 FC |
17 | import org.eclipse.linuxtools.internal.lttng.core.state.StateStrings.ProcessStatus; |
18 | import org.eclipse.linuxtools.internal.lttng.core.state.evProcessor.ILttngEventProcessor; | |
19 | import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngProcessState; | |
20 | import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngTraceState; | |
0c2a2e08 | 21 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; |
6e512b93 ASL |
22 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeComponent; |
23 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent; | |
6e512b93 | 24 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent.Type; |
a72a38d9 | 25 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess; |
6e512b93 ASL |
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 | ||
8827c197 | 31 | public 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 | */ | |
a79913eb | 112 | @SuppressWarnings("deprecation") |
41dc35d0 FC |
113 | protected boolean makeDraw(LttngTraceState traceSt, long startTime, |
114 | long endTime, TimeRangeEventProcess localProcess, | |
6e512b93 ASL |
115 | ParamsUpdater params, String stateMode) { |
116 | ||
0c2a2e08 | 117 | if (TraceDebug.isCFV()) { |
3b38ea61 FC |
118 | TraceDebug.traceCFV("makeDraw():[" + localProcess + //$NON-NLS-1$ |
119 | ",candidate=[stime=" + startTime + //$NON-NLS-1$ | |
120 | ",etime=" + endTime + //$NON-NLS-1$ | |
121 | ",state=" + stateMode + "]]"); //$NON-NLS-1$ //$NON-NLS-2$ | |
0c2a2e08 FC |
122 | } |
123 | ||
6e512b93 | 124 | // Determine start and end times to establish duration |
41dc35d0 FC |
125 | Long stime = startTime; |
126 | Long etime = endTime; | |
6e512b93 | 127 | |
a72a38d9 ASL |
128 | if (!withinViewRange(stime, etime)) { |
129 | // No use to process the event since it's outside | |
130 | // the visible time range of the window | |
131 | params.incrementEventsDiscarded(ParamsUpdater.OUT_OF_VIEWRANGE); | |
132 | return false; | |
133 | } | |
5dbe4d3b | 134 | |
6e512b93 ASL |
135 | if (etime < stime) { |
136 | // Validate the sequential order of events | |
137 | params.incrementEventsDiscardedWrongOrder(); | |
138 | return false; | |
139 | } | |
140 | ||
8827c197 FC |
141 | // Store the next good time to start drawing the next event |
142 | // this is done this early to display an accurate start time of the | |
143 | // first event | |
144 | // within the display window | |
145 | // ****** moved at the end since it produces gaps among the coloured rectangles | |
146 | // localProcess.setNext_good_time(etime); | |
a72a38d9 ASL |
147 | |
148 | // If First event of a process, initialise start time half page before to enable pagination to the left | |
149 | if (stime < params.getStartTime()) { | |
150 | // event start time is before the visible time window | |
151 | long insertion = localProcess.getInsertionTime(); | |
152 | if (stime.longValue() == insertion) { | |
153 | // if start time is equal to insertion this is the first event to be drawn for this process | |
154 | long halfPage = (params.getEndTime() - params.getStartTime()) / 2; | |
155 | long initTime = params.getStartTime() - halfPage; | |
156 | if (initTime > insertion) { | |
157 | // start time of this event is unknown, place it half page before visible window to allow left side | |
158 | // pagination when selecting previous event | |
159 | stime = initTime; | |
160 | } | |
161 | } | |
6e512b93 ASL |
162 | } |
163 | ||
164 | // Determine if the time range event will fit it the current | |
165 | // pixel map | |
166 | double duration = etime - stime; | |
167 | double k = getPixelsPerNs(traceSt, params); | |
168 | double pixels = duration * k; | |
169 | ||
170 | // Visibility check | |
171 | // Display a "more information" indication by allowing non visible event | |
172 | // as long as its previous event is visible. | |
173 | boolean visible = true; | |
0c2a2e08 | 174 | if (pixels < 1.0) { |
6e512b93 ASL |
175 | boolean prevEventVisibility = true; |
176 | // Get the visibility indication on previous event for | |
177 | // this process | |
178 | Vector<TimeRangeComponent> inMemEvents = localProcess | |
179 | .getTraceEvents(); | |
180 | if (inMemEvents.size() != 0) { | |
181 | TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents | |
182 | .size() - 1); | |
183 | prevEventVisibility = prevEvent.isVisible(); | |
184 | ||
185 | // if previous event visibility is false and the time span | |
186 | // between events less than two pixels, there is no need to | |
187 | // load it in memory i.e. not visible and a more indicator is | |
188 | // within two pixels. | |
189 | // return i.e. event discarded to free up memory | |
190 | Long eventSpan = stime - prevEvent.getStartTime(); | |
191 | if (prevEventVisibility == false | |
0c2a2e08 | 192 | && ((double) eventSpan * k) < 2.0) { |
6e512b93 ASL |
193 | |
194 | // discard the item | |
5dbe4d3b | 195 | params.incrementEventsDiscarded(ParamsUpdater.NOT_VISIBLE); |
6e512b93 ASL |
196 | return false; |
197 | ||
198 | } | |
199 | } | |
200 | ||
201 | // if previous event is visible, set this one to not | |
202 | // visible and continue | |
203 | visible = false; | |
204 | } | |
205 | ||
206 | // Create the time-range event | |
207 | TimeRangeEvent time_window = new TimeRangeEvent(stime, etime, | |
208 | localProcess, Type.PROCESS_MODE, stateMode); | |
209 | ||
210 | time_window.setVisible(visible); | |
211 | localProcess.getTraceEvents().add(time_window); | |
41dc35d0 | 212 | localProcess.setNext_good_time(etime); |
6e512b93 ASL |
213 | |
214 | return false; | |
215 | } | |
216 | ||
217 | /** | |
218 | * @param traceSt | |
219 | * @param evTime | |
220 | * @param process | |
221 | * @param localProcess | |
222 | * @param params | |
223 | * @return | |
224 | */ | |
41dc35d0 | 225 | protected boolean makeDraw(LttngTraceState traceSt, long evTime, |
6e512b93 ASL |
226 | LttngProcessState process, TimeRangeEventProcess localProcess, |
227 | ParamsUpdater params) { | |
228 | ||
41dc35d0 FC |
229 | // TmfTimestamp stime = process.getState().getChange_LttTime(); |
230 | long stime = localProcess.getNext_good_time(); | |
6e512b93 ASL |
231 | |
232 | String stateMode; | |
233 | ProcessStatus procStatus = process.getState().getProc_status(); | |
234 | // Use Execution mode if process state is RUN otherwise use the actual | |
235 | // process state, | |
236 | // this selection will determine the actual color selected for the event | |
237 | if (procStatus == ProcessStatus.LTTV_STATE_RUN) { | |
238 | stateMode = process.getState().getExec_mode().getInName(); | |
239 | } else { | |
240 | stateMode = procStatus.getInName(); | |
241 | } | |
242 | ||
243 | return makeDraw(traceSt, stime, evTime, localProcess, params, stateMode); | |
244 | ||
245 | } | |
246 | ||
247 | } |