Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made 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 (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.resources.evProcessor; | |
13 | ||
14 | import java.util.Vector; | |
15 | ||
16 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
8827c197 | 17 | import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor; |
6e512b93 | 18 | import org.eclipse.linuxtools.lttng.state.model.LttngTraceState; |
8827c197 | 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; | |
8035003b | 22 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent.Type; |
8827c197 | 23 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource; |
8035003b | 24 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes; |
8827c197 | 25 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeResourceFactory; |
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.resources.model.ResourceContainer; | |
29 | import org.eclipse.linuxtools.lttng.ui.views.resources.model.ResourceModelFactory; | |
30 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
31 | ||
32 | public abstract class AbsResourcesTRangeUpdate extends AbsTRangeUpdate | |
8827c197 | 33 | implements ILttngEventProcessor { |
6e512b93 ASL |
34 | |
35 | // ======================================================================== | |
36 | // Data | |
37 | // ======================================================================= | |
38 | protected ResourceContainer resContainer = ResourceModelFactory | |
39 | .getResourceContainer(); | |
40 | protected ParamsUpdater params = ResourceModelFactory.getParamsUpdater(); | |
41 | protected static final Long ANY_CPU = 0L; | |
42 | ||
43 | // ======================================================================== | |
44 | // Methods | |
45 | // ======================================================================= | |
46 | protected TimeRangeEventResource addLocalResource(long traceStartTime, | |
63eecb47 FC |
47 | long traceEndTime, String traceId, ResourceTypes type, Long resId, |
48 | long insertionTime) { | |
6e512b93 ASL |
49 | |
50 | String resourceName = type.toString() + " " + resId.toString(); | |
51 | // Note : the "traceid" here is assigned to the "groupname" as we group | |
52 | // by trace in the UI | |
53 | TimeRangeEventResource localRessource = TimeRangeResourceFactory | |
63eecb47 FC |
54 | .getInstance().createResource(resContainer.getUniqueId(), |
55 | traceStartTime, traceEndTime, resourceName, traceId, | |
56 | "", type, resId, insertionTime); | |
8827c197 | 57 | resContainer.addItem(localRessource); |
6e512b93 ASL |
58 | return localRessource; |
59 | } | |
60 | ||
61 | /** | |
62 | * Used to check if the event is visible within the current visible time | |
63 | * window | |
64 | * | |
65 | * @return | |
66 | */ | |
67 | protected boolean withinViewRange(long stime, long etime) { | |
68 | long windowStartTime = params.getStartTime(); | |
69 | long windowEndTime = params.getEndTime(); | |
70 | ||
8827c197 FC |
71 | if (stime == 13589765052286L) { |
72 | TraceDebug.debug("Debug event catched"); | |
6e512b93 ASL |
73 | } |
74 | ||
8827c197 FC |
75 | // Start of event is already out of range |
76 | if (stime > windowEndTime) { | |
77 | return false; | |
78 | } | |
79 | ||
80 | // End time within or beyond start of window as long as the start time | |
81 | // is before the end of the window (condition above) | |
82 | if (etime >= windowStartTime) { | |
6e512b93 ASL |
83 | return true; |
84 | } | |
85 | ||
8827c197 FC |
86 | // // start time is within window |
87 | // if (stime >= windowStartTime && stime <= windowEndTime) { | |
88 | // // The event or part of it shall be displayed. | |
89 | // return true; | |
90 | // } | |
91 | // | |
92 | // // end time is within window | |
93 | // if (etime >= windowStartTime && etime <= windowEndTime) { | |
94 | // // The event or part of it shall be displayed. | |
95 | // return true; | |
96 | // } | |
97 | ||
98 | // crosses the window | |
99 | if (stime <= windowStartTime && etime >= windowEndTime) { | |
6e512b93 ASL |
100 | // The time range is bigger than the selected time window and |
101 | // crosses it | |
102 | return true; | |
103 | } | |
104 | ||
105 | return false; | |
106 | } | |
107 | ||
108 | public TimeRangeEventResource resourcelist_obtain_bdev( | |
109 | LttngTraceState traceState, Long resourceId) { | |
110 | return resourcelist_obtain_generic(resourceId, ResourceTypes.BDEV, | |
111 | traceState.getTraceId()); | |
112 | } | |
113 | ||
114 | public TimeRangeEventResource resourcelist_obtain_trap( | |
115 | LttngTraceState traceState, Long resourceId) { | |
116 | return resourcelist_obtain_generic(resourceId, ResourceTypes.TRAP, | |
117 | traceState.getTraceId()); | |
118 | } | |
119 | ||
120 | public TimeRangeEventResource resourcelist_obtain_irq( | |
121 | LttngTraceState traceState, Long resourceId) { | |
122 | return resourcelist_obtain_generic(resourceId, ResourceTypes.IRQ, | |
123 | traceState.getTraceId()); | |
124 | } | |
125 | ||
126 | public TimeRangeEventResource resourcelist_obtain_soft_irq( | |
127 | LttngTraceState traceState, Long resourceId) { | |
128 | return resourcelist_obtain_generic(resourceId, ResourceTypes.SOFT_IRQ, | |
129 | traceState.getTraceId()); | |
130 | } | |
131 | ||
132 | public TimeRangeEventResource resourcelist_obtain_cpu( | |
133 | LttngTraceState traceState, Long resourceId) { | |
134 | return resourcelist_obtain_generic(resourceId, ResourceTypes.CPU, | |
135 | traceState.getTraceId()); | |
136 | } | |
137 | ||
138 | public TimeRangeEventResource resourcelist_obtain_machine( | |
139 | LttngTraceState traceState, Long resourceId) { | |
140 | // *** VERIFY *** | |
141 | // Does "UNKNOWN" make sense for "obtain_machine" ? | |
142 | // It seems to be the only choice, thought... | |
143 | return resourcelist_obtain_generic(resourceId, ResourceTypes.UNKNOWN, | |
144 | traceState.getTraceId()); | |
145 | } | |
146 | ||
147 | public TimeRangeEventResource resourcelist_obtain_generic(Long resourceId, | |
148 | ResourceTypes resourceType, String traceId) { | |
8827c197 | 149 | return resContainer.findItem(resourceId, resourceType, traceId); |
6e512b93 ASL |
150 | } |
151 | ||
152 | protected boolean globalProcessBeforeExecmode(LttngEvent trcEvent, | |
153 | LttngTraceState traceSt) { | |
154 | ||
155 | // TODO: Implement the tracking of current resource in order ot speed up | |
156 | // searching for the relevant resource similar to current_hash_data in | |
157 | // the C implementation | |
158 | // e.g. | |
159 | // hashed_process_data = | |
160 | // process_list->current_hash_data[trace_num][cpu]; | |
161 | ||
162 | TimeRangeEventResource localResource = resourcelist_obtain_cpu(traceSt, | |
163 | trcEvent.getCpuId()); | |
164 | Long cpu = trcEvent.getCpuId(); | |
165 | if (localResource == null) { | |
8827c197 | 166 | TmfTimeRange timeRange = traceSt.getContext() |
6e512b93 ASL |
167 | .getTraceTimeWindow(); |
168 | localResource = addLocalResource(timeRange.getStartTime() | |
169 | .getValue(), timeRange.getEndTime().getValue(), traceSt | |
63eecb47 FC |
170 | .getTraceId(), ResourceTypes.CPU, cpu, trcEvent |
171 | .getTimestamp().getValue()); | |
6e512b93 ASL |
172 | } |
173 | ||
174 | // get the start time | |
175 | long stime = localResource.getNext_good_time(); | |
176 | // Get the resource state mode | |
63eecb47 | 177 | String cpuStateMode = localResource.getStateMode(traceSt); |
6e512b93 ASL |
178 | // Call the makeDraw function |
179 | makeDraw(traceSt, stime, trcEvent.getTimestamp().getValue(), | |
180 | localResource, params, cpuStateMode); | |
181 | ||
182 | return false; | |
183 | } | |
184 | ||
63eecb47 FC |
185 | /** |
186 | * @param traceSt | |
187 | * @param startTime | |
188 | * @param endTime | |
189 | * @param localResource | |
190 | * @param params | |
191 | * @param stateMode | |
192 | * @return | |
193 | */ | |
8827c197 FC |
194 | protected boolean makeDraw(LttngTraceState traceSt, long stime, long etime, |
195 | TimeRangeEventResource localResource, | |
6e512b93 ASL |
196 | ParamsUpdater params, String stateMode) { |
197 | ||
8827c197 FC |
198 | // Check if the event is out of range |
199 | if (!withinViewRange(stime, etime)) { | |
5dbe4d3b | 200 | params.incrementEventsDiscarded(ParamsUpdater.OUT_OF_VIEWRANGE); |
6e512b93 ASL |
201 | return false; |
202 | } | |
203 | ||
8827c197 FC |
204 | // Check if the time range is consistent. |
205 | if (etime < stime) { | |
206 | params.incrementEventsDiscardedWrongOrder(); | |
8035003b ASL |
207 | return false; |
208 | } | |
6e512b93 | 209 | |
8827c197 FC |
210 | // Store the next good time to start drawing the next event |
211 | // this is done this early to display an accurate start time of the | |
212 | // first event | |
213 | // within the display window | |
214 | // Moved at the end since it produces space gaps among events | |
215 | // localResource.setNext_good_time(etime); | |
216 | ||
a72a38d9 ASL |
217 | // If First event of a resource, initialise start time half page before to enable pagination to the left |
218 | if (stime < params.getStartTime()) { | |
219 | // event start time is before the visible time window | |
220 | long insertion = localResource.getInsertionTime(); | |
221 | if (stime == insertion) { | |
222 | // if start time is equal to insertion this is the first event to be drawn for this resource | |
223 | long halfPage = (params.getEndTime() - params.getStartTime()) / 2; | |
224 | long initTime = params.getStartTime() - halfPage; | |
225 | if (initTime > insertion) { | |
226 | // start time of this event is unknown, place it half page before visible window to allow left side | |
227 | // pagination when selecting previous event | |
228 | stime = initTime; | |
229 | } | |
230 | } | |
231 | } | |
232 | ||
6e512b93 ASL |
233 | // Determine if the time range event will fit it the current |
234 | // pixel map | |
235 | double duration = etime - stime; | |
236 | double k = getPixelsPerNs(traceSt, params); | |
237 | double pixels = duration * k; | |
238 | ||
239 | // Visibility check | |
240 | // Display a "more information" indication by allowing non visible event | |
241 | // as long as its previous event is visible. | |
242 | boolean visible = true; | |
243 | if (pixels < 1) { | |
244 | boolean prevEventVisibility = true; | |
245 | // Get the visibility indication on previous event for | |
246 | // this process | |
247 | Vector<TimeRangeComponent> inMemEvents = localResource | |
248 | .getTraceEvents(); | |
249 | if (inMemEvents.size() != 0) { | |
250 | TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents | |
251 | .size() - 1); | |
252 | prevEventVisibility = prevEvent.isVisible(); | |
253 | ||
254 | // if previous event visibility is false and the time span | |
255 | // between events less than two pixels, there is no need to | |
256 | // load it in memory i.e. not visible and a more indicator is | |
257 | // within two pixels. | |
258 | // return i.e. event discarded to free up memory | |
259 | Long eventSpan = stime - prevEvent.getStartTime(); | |
260 | if (prevEventVisibility == false | |
261 | && ((double) eventSpan * k) < 2) { | |
5dbe4d3b | 262 | params.incrementEventsDiscarded(ParamsUpdater.NOT_VISIBLE); |
6e512b93 ASL |
263 | return false; |
264 | } | |
265 | } | |
266 | ||
267 | // if previous event is visible, set this one to not | |
268 | // visible and continue | |
269 | visible = false; | |
270 | } | |
271 | ||
272 | Type eventType = getEventType(localResource); | |
273 | if (eventType != null) { | |
274 | TimeRangeEvent time_window = new TimeRangeEvent(stime, etime, | |
275 | localResource, eventType, stateMode); | |
276 | ||
277 | time_window.setVisible(visible); | |
278 | localResource.addChildren(time_window); | |
8827c197 | 279 | |
6e512b93 ASL |
280 | localResource.setNext_good_time(etime); |
281 | } | |
282 | ||
283 | return false; | |
284 | } | |
285 | ||
286 | /** | |
287 | * Convert between resource type and timeRange event type | |
288 | * | |
289 | * @param resource | |
290 | * @return | |
291 | */ | |
292 | private Type getEventType(TimeRangeEventResource resource) { | |
293 | // TODO: Can we merge into one type | |
294 | ResourceTypes resType = resource.getType(); | |
295 | Type eventType = null; | |
296 | ||
297 | switch (resType) { | |
298 | case CPU: | |
299 | eventType = Type.CPU_MODE; | |
300 | break; | |
301 | case IRQ: | |
302 | eventType = Type.IRQ_MODE; | |
303 | break; | |
304 | case SOFT_IRQ: | |
305 | eventType = Type.SOFT_IRQ_MODE; | |
306 | break; | |
307 | case TRAP: | |
308 | eventType = Type.TRAP_MODE; | |
309 | break; | |
310 | case BDEV: | |
311 | eventType = Type.BDEV_MODE; | |
312 | break; | |
313 | default: | |
314 | eventType = Type.PROCESS_MODE; | |
315 | break; | |
316 | } | |
317 | ||
318 | return eventType; | |
319 | } | |
320 | ||
321 | } |