1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
;
15 import java
.util
.Vector
;
17 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEvent
;
18 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.evProcessor
.ILttngEventProcessor
;
19 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.model
.LttngTraceState
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeComponent
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEvent
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEvent
.Type
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventResource
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventResource
.ResourceTypes
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeResourceFactory
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.AbsTRangeUpdate
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.ParamsUpdater
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.model
.ResourceContainer
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.model
.ResourceModelFactory
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
33 public abstract class AbsResourcesTRangeUpdate
extends AbsTRangeUpdate
34 implements ILttngEventProcessor
{
36 // ========================================================================
38 // =======================================================================
39 protected ResourceContainer resContainer
= ResourceModelFactory
40 .getResourceContainer();
41 protected ParamsUpdater params
= ResourceModelFactory
.getParamsUpdater();
42 protected static final Long ANY_CPU
= 0L;
44 // ========================================================================
46 // =======================================================================
47 protected TimeRangeEventResource
addLocalResource(long traceStartTime
,
48 long traceEndTime
, String traceId
, ResourceTypes type
, Long resId
,
51 String resourceName
= type
.toString() + " " + resId
.toString(); //$NON-NLS-1$
52 // Note : the "traceid" here is assigned to the "groupname" as we group
54 TimeRangeEventResource localRessource
= TimeRangeResourceFactory
55 .getInstance().createResource(resContainer
.getUniqueId(),
56 traceStartTime
, traceEndTime
, resourceName
, traceId
,
57 "", type
, resId
, insertionTime
); //$NON-NLS-1$
58 resContainer
.addItem(localRessource
);
60 if (TraceDebug
.isRV()) {
61 TraceDebug
.traceRV("addLocalResource():" + localRessource
); //$NON-NLS-1$
64 return localRessource
;
68 * Used to check if the event is visible within the current visible time
73 protected boolean withinViewRange(long stime
, long etime
) {
74 long windowStartTime
= params
.getStartTime();
75 long windowEndTime
= params
.getEndTime();
77 // Start of event is already out of range
78 if (stime
> windowEndTime
) {
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
) {
88 // // start time is within window
89 // if (stime >= windowStartTime && stime <= windowEndTime) {
90 // // The event or part of it shall be displayed.
94 // // end time is within window
95 // if (etime >= windowStartTime && etime <= windowEndTime) {
96 // // The event or part of it shall be displayed.
100 // crosses the window
101 if (stime
<= windowStartTime
&& etime
>= windowEndTime
) {
102 // The time range is bigger than the selected time window and
110 public TimeRangeEventResource
resourcelist_obtain_bdev(
111 LttngTraceState traceState
, Long resourceId
) {
112 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.BDEV
,
113 traceState
.getTraceId());
116 public TimeRangeEventResource
resourcelist_obtain_trap(
117 LttngTraceState traceState
, Long resourceId
) {
118 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.TRAP
,
119 traceState
.getTraceId());
122 public TimeRangeEventResource
resourcelist_obtain_irq(
123 LttngTraceState traceState
, Long resourceId
) {
124 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.IRQ
,
125 traceState
.getTraceId());
128 public TimeRangeEventResource
resourcelist_obtain_soft_irq(
129 LttngTraceState traceState
, Long resourceId
) {
130 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.SOFT_IRQ
,
131 traceState
.getTraceId());
134 public TimeRangeEventResource
resourcelist_obtain_cpu(
135 LttngTraceState traceState
, Long resourceId
) {
136 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.CPU
,
137 traceState
.getTraceId());
140 public TimeRangeEventResource
resourcelist_obtain_machine(
141 LttngTraceState traceState
, Long resourceId
) {
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());
149 public TimeRangeEventResource
resourcelist_obtain_generic(Long resourceId
,
150 ResourceTypes resourceType
, String traceId
) {
151 return resContainer
.findItem(resourceId
, resourceType
, traceId
);
154 protected boolean globalProcessBeforeExecmode(LttngEvent trcEvent
,
155 LttngTraceState traceSt
) {
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
161 // hashed_process_data =
162 // process_list->current_hash_data[trace_num][cpu];
164 TimeRangeEventResource localResource
= resourcelist_obtain_cpu(traceSt
,
165 trcEvent
.getCpuId());
166 Long cpu
= trcEvent
.getCpuId();
167 if (localResource
== null) {
168 TmfTimeRange timeRange
= traceSt
.getContext().getTraceTimeWindow();
169 localResource
= addLocalResource(timeRange
.getStartTime()
170 .getValue(), timeRange
.getEndTime().getValue(),
171 traceSt
.getTraceId(), ResourceTypes
.CPU
, cpu
, trcEvent
172 .getTimestamp().getValue());
175 // get the start time
176 long stime
= localResource
.getNext_good_time();
177 // Get the resource state mode
178 String cpuStateMode
= localResource
.getStateMode(traceSt
);
179 // Call the makeDraw function
180 makeDraw(traceSt
, stime
, trcEvent
.getTimestamp().getValue(),
181 localResource
, params
, cpuStateMode
);
190 * @param localResource
195 @SuppressWarnings("deprecation")
196 protected boolean makeDraw(LttngTraceState traceSt
, long stime
, long etime
,
197 TimeRangeEventResource localResource
, ParamsUpdater params
,
200 if (TraceDebug
.isRV()) {
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$
204 // Check if the event is out of range
205 if (!withinViewRange(stime
, etime
)) {
206 params
.incrementEventsDiscarded(ParamsUpdater
.OUT_OF_VIEWRANGE
);
210 // Check if the time range is consistent.
212 params
.incrementEventsDiscardedWrongOrder();
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
219 // within the display window
220 // Moved at the end since it produces space gaps among events
221 // localResource.setNext_good_time(etime);
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
239 // Determine if the time range event will fit it the current
241 double duration
= etime
- stime
;
242 double k
= getPixelsPerNs(traceSt
, params
);
243 double pixels
= duration
* k
;
246 // Display a "more information" indication by allowing non visible event
247 // as long as its previous event is visible.
248 boolean visible
= true;
250 boolean prevEventVisibility
= true;
251 // Get the visibility indication on previous event for
253 Vector
<TimeRangeComponent
> inMemEvents
= localResource
255 if (inMemEvents
.size() != 0) {
256 TimeRangeComponent prevEvent
= inMemEvents
.get(inMemEvents
258 prevEventVisibility
= prevEvent
.isVisible();
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
267 && ((double) eventSpan
* k
) < 2.0) {
268 params
.incrementEventsDiscarded(ParamsUpdater
.NOT_VISIBLE
);
273 // if previous event is visible, set this one to not
274 // visible and continue
278 Type eventType
= getEventType(localResource
);
279 if (eventType
!= null) {
280 TimeRangeEvent time_window
= new TimeRangeEvent(stime
, etime
,
281 localResource
, eventType
, stateMode
);
283 time_window
.setVisible(visible
);
284 localResource
.addChildren(time_window
);
286 localResource
.setNext_good_time(etime
);
293 * Convert between resource type and timeRange event type
298 private Type
getEventType(TimeRangeEventResource resource
) {
299 // TODO: Can we merge into one type
300 ResourceTypes resType
= resource
.getType();
301 Type eventType
= null;
305 eventType
= Type
.CPU_MODE
;
308 eventType
= Type
.IRQ_MODE
;
311 eventType
= Type
.SOFT_IRQ_MODE
;
314 eventType
= Type
.TRAP_MODE
;
317 eventType
= Type
.BDEV_MODE
;
320 eventType
= Type
.PROCESS_MODE
;