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