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 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
;
14 import java
.util
.Vector
;
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
;
32 public abstract class AbsResourcesTRangeUpdate
extends AbsTRangeUpdate
33 implements ILttngEventProcessor
{
35 // ========================================================================
37 // =======================================================================
38 protected ResourceContainer resContainer
= ResourceModelFactory
39 .getResourceContainer();
40 protected ParamsUpdater params
= ResourceModelFactory
.getParamsUpdater();
41 protected static final Long ANY_CPU
= 0L;
43 // ========================================================================
45 // =======================================================================
46 protected TimeRangeEventResource
addLocalResource(long traceStartTime
,
47 long traceEndTime
, String traceId
, ResourceTypes type
, Long resId
,
50 String resourceName
= type
.toString() + " " + resId
.toString();
51 // Note : the "traceid" here is assigned to the "groupname" as we group
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
;
62 * Used to check if the event is visible within the current visible time
67 protected boolean withinViewRange(long stime
, long etime
) {
68 long windowStartTime
= params
.getStartTime();
69 long windowEndTime
= params
.getEndTime();
71 if (stime
== 13589765052286L) {
72 TraceDebug
.debug("Debug event catched");
75 // Start of event is already out of range
76 if (stime
> windowEndTime
) {
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
) {
86 // // start time is within window
87 // if (stime >= windowStartTime && stime <= windowEndTime) {
88 // // The event or part of it shall be displayed.
92 // // end time is within window
93 // if (etime >= windowStartTime && etime <= windowEndTime) {
94 // // The event or part of it shall be displayed.
99 if (stime
<= windowStartTime
&& etime
>= windowEndTime
) {
100 // The time range is bigger than the selected time window and
108 public TimeRangeEventResource
resourcelist_obtain_bdev(
109 LttngTraceState traceState
, Long resourceId
) {
110 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.BDEV
,
111 traceState
.getTraceId());
114 public TimeRangeEventResource
resourcelist_obtain_trap(
115 LttngTraceState traceState
, Long resourceId
) {
116 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.TRAP
,
117 traceState
.getTraceId());
120 public TimeRangeEventResource
resourcelist_obtain_irq(
121 LttngTraceState traceState
, Long resourceId
) {
122 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.IRQ
,
123 traceState
.getTraceId());
126 public TimeRangeEventResource
resourcelist_obtain_soft_irq(
127 LttngTraceState traceState
, Long resourceId
) {
128 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.SOFT_IRQ
,
129 traceState
.getTraceId());
132 public TimeRangeEventResource
resourcelist_obtain_cpu(
133 LttngTraceState traceState
, Long resourceId
) {
134 return resourcelist_obtain_generic(resourceId
, ResourceTypes
.CPU
,
135 traceState
.getTraceId());
138 public TimeRangeEventResource
resourcelist_obtain_machine(
139 LttngTraceState traceState
, Long resourceId
) {
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());
147 public TimeRangeEventResource
resourcelist_obtain_generic(Long resourceId
,
148 ResourceTypes resourceType
, String traceId
) {
149 return resContainer
.findItem(resourceId
, resourceType
, traceId
);
152 protected boolean globalProcessBeforeExecmode(LttngEvent trcEvent
,
153 LttngTraceState traceSt
) {
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
159 // hashed_process_data =
160 // process_list->current_hash_data[trace_num][cpu];
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());
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
);
189 * @param localResource
194 protected boolean makeDraw(LttngTraceState traceSt
, long stime
, long etime
,
195 TimeRangeEventResource localResource
,
196 ParamsUpdater params
, String stateMode
) {
198 // Check if the event is out of range
199 if (!withinViewRange(stime
, etime
)) {
200 params
.incrementEventsDiscarded();
204 // Check if the time range is consistent.
206 params
.incrementEventsDiscardedWrongOrder();
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
213 // within the display window
214 // Moved at the end since it produces space gaps among events
215 // localResource.setNext_good_time(etime);
217 // Determine if the time range event will fit it the current
219 double duration
= etime
- stime
;
220 double k
= getPixelsPerNs(traceSt
, params
);
221 double pixels
= duration
* k
;
224 // Display a "more information" indication by allowing non visible event
225 // as long as its previous event is visible.
226 boolean visible
= true;
228 boolean prevEventVisibility
= true;
229 // Get the visibility indication on previous event for
231 Vector
<TimeRangeComponent
> inMemEvents
= localResource
233 if (inMemEvents
.size() != 0) {
234 TimeRangeComponent prevEvent
= inMemEvents
.get(inMemEvents
236 prevEventVisibility
= prevEvent
.isVisible();
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();
251 // if previous event is visible, set this one to not
252 // visible and continue
256 Type eventType
= getEventType(localResource
);
257 if (eventType
!= null) {
258 TimeRangeEvent time_window
= new TimeRangeEvent(stime
, etime
,
259 localResource
, eventType
, stateMode
);
261 time_window
.setVisible(visible
);
262 localResource
.addChildren(time_window
);
264 localResource
.setNext_good_time(etime
);
271 * Convert between resource type and timeRange event type
276 private Type
getEventType(TimeRangeEventResource resource
) {
277 // TODO: Can we merge into one type
278 ResourceTypes resType
= resource
.getType();
279 Type eventType
= null;
283 eventType
= Type
.CPU_MODE
;
286 eventType
= Type
.IRQ_MODE
;
289 eventType
= Type
.SOFT_IRQ_MODE
;
292 eventType
= Type
.TRAP_MODE
;
295 eventType
= Type
.BDEV_MODE
;
298 eventType
= Type
.PROCESS_MODE
;