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