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; | |
17 | import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor; | |
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.TimeRangeEventResource; | |
24 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes; | |
25 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeResourceFactory; | |
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 | |
33 | implements ILttngEventProcessor { | |
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, | |
47 | long traceEndTime, String traceId, ResourceTypes type, Long resId, | |
48 | long insertionTime) { | |
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 | |
54 | .getInstance().createResource(resContainer.getUniqueId(), | |
55 | traceStartTime, traceEndTime, resourceName, traceId, | |
56 | "", type, resId, insertionTime); | |
57 | resContainer.addItem(localRessource); | |
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 | ||
71 | if (stime == 13589765052286L) { | |
72 | TraceDebug.debug("Debug event catched"); | |
73 | } | |
74 | ||
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) { | |
83 | return true; | |
84 | } | |
85 | ||
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) { | |
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) { | |
149 | return resContainer.findItem(resourceId, resourceType, traceId); | |
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) { | |
166 | TmfTimeRange timeRange = traceSt.getContext() | |
167 | .getTraceTimeWindow(); | |
168 | localResource = addLocalResource(timeRange.getStartTime() | |
169 | .getValue(), timeRange.getEndTime().getValue(), traceSt | |
170 | .getTraceId(), ResourceTypes.CPU, cpu, trcEvent | |
171 | .getTimestamp().getValue()); | |
172 | } | |
173 | ||
174 | // get the start time | |
175 | long stime = localResource.getNext_good_time(); | |
176 | // Get the resource state mode | |
177 | String cpuStateMode = localResource.getStateMode(traceSt); | |
178 | // Call the makeDraw function | |
179 | makeDraw(traceSt, stime, trcEvent.getTimestamp().getValue(), | |
180 | localResource, params, cpuStateMode); | |
181 | ||
182 | return false; | |
183 | } | |
184 | ||
185 | /** | |
186 | * @param traceSt | |
187 | * @param startTime | |
188 | * @param endTime | |
189 | * @param localResource | |
190 | * @param params | |
191 | * @param stateMode | |
192 | * @return | |
193 | */ | |
194 | protected boolean makeDraw(LttngTraceState traceSt, long stime, long etime, | |
195 | TimeRangeEventResource localResource, | |
196 | ParamsUpdater params, String stateMode) { | |
197 | ||
198 | // Check if the event is out of range | |
199 | if (!withinViewRange(stime, etime)) { | |
200 | params.incrementEventsDiscarded(); | |
201 | return false; | |
202 | } | |
203 | ||
204 | // Check if the time range is consistent. | |
205 | if (etime < stime) { | |
206 | params.incrementEventsDiscardedWrongOrder(); | |
207 | return false; | |
208 | } | |
209 | ||
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 | ||
217 | // Determine if the time range event will fit it the current | |
218 | // pixel map | |
219 | double duration = etime - stime; | |
220 | double k = getPixelsPerNs(traceSt, params); | |
221 | double pixels = duration * k; | |
222 | ||
223 | // Visibility check | |
224 | // Display a "more information" indication by allowing non visible event | |
225 | // as long as its previous event is visible. | |
226 | boolean visible = true; | |
227 | if (pixels < 1) { | |
228 | boolean prevEventVisibility = true; | |
229 | // Get the visibility indication on previous event for | |
230 | // this process | |
231 | Vector<TimeRangeComponent> inMemEvents = localResource | |
232 | .getTraceEvents(); | |
233 | if (inMemEvents.size() != 0) { | |
234 | TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents | |
235 | .size() - 1); | |
236 | prevEventVisibility = prevEvent.isVisible(); | |
237 | ||
238 | // if previous event visibility is false and the time span | |
239 | // between events less than two pixels, there is no need to | |
240 | // load it in memory i.e. not visible and a more indicator is | |
241 | // within two pixels. | |
242 | // return i.e. event discarded to free up memory | |
243 | Long eventSpan = stime - prevEvent.getStartTime(); | |
244 | if (prevEventVisibility == false | |
245 | && ((double) eventSpan * k) < 2) { | |
246 | params.incrementEventsDiscarded(); | |
247 | return false; | |
248 | } | |
249 | } | |
250 | ||
251 | // if previous event is visible, set this one to not | |
252 | // visible and continue | |
253 | visible = false; | |
254 | } | |
255 | ||
256 | Type eventType = getEventType(localResource); | |
257 | if (eventType != null) { | |
258 | TimeRangeEvent time_window = new TimeRangeEvent(stime, etime, | |
259 | localResource, eventType, stateMode); | |
260 | ||
261 | time_window.setVisible(visible); | |
262 | localResource.addChildren(time_window); | |
263 | ||
264 | localResource.setNext_good_time(etime); | |
265 | } | |
266 | ||
267 | return false; | |
268 | } | |
269 | ||
270 | /** | |
271 | * Convert between resource type and timeRange event type | |
272 | * | |
273 | * @param resource | |
274 | * @return | |
275 | */ | |
276 | private Type getEventType(TimeRangeEventResource resource) { | |
277 | // TODO: Can we merge into one type | |
278 | ResourceTypes resType = resource.getType(); | |
279 | Type eventType = null; | |
280 | ||
281 | switch (resType) { | |
282 | case CPU: | |
283 | eventType = Type.CPU_MODE; | |
284 | break; | |
285 | case IRQ: | |
286 | eventType = Type.IRQ_MODE; | |
287 | break; | |
288 | case SOFT_IRQ: | |
289 | eventType = Type.SOFT_IRQ_MODE; | |
290 | break; | |
291 | case TRAP: | |
292 | eventType = Type.TRAP_MODE; | |
293 | break; | |
294 | case BDEV: | |
295 | eventType = Type.BDEV_MODE; | |
296 | break; | |
297 | default: | |
298 | eventType = Type.PROCESS_MODE; | |
299 | break; | |
300 | } | |
301 | ||
302 | return eventType; | |
303 | } | |
304 | ||
305 | } |