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