1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 - Initial implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.evProcessor
;
15 import java
.util
.Vector
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ProcessStatus
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ILttngEventProcessor
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngProcessState
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeComponent
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEvent
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEvent
.Type
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventProcess
;
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
.controlflow
.model
.FlowModelFactory
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.model
.FlowProcessContainer
;
31 public abstract class AbsFlowTRangeUpdate
extends AbsTRangeUpdate
implements ILttngEventProcessor
{
33 // ========================================================================
35 // =======================================================================
37 protected FlowProcessContainer procContainer
= FlowModelFactory
.getProcContainer();
38 protected ParamsUpdater params
= FlowModelFactory
.getParamsUpdater();
39 protected static final Long ANY_CPU
= 0L;
42 // ========================================================================
44 // =======================================================================
45 protected TimeRangeEventProcess
addLocalProcess(LttngProcessState stateProcess
, long traceStartTime
, long traceEndTime
, String traceId
) {
46 // TimeRangeEventProcess localProcess = new TimeRangeEventProcess(id, name, startTime, stopTime, groupName, className)
47 TimeRangeEventProcess localProcess
= new TimeRangeEventProcess(
48 procContainer
.getUniqueId(), stateProcess
.getName(),
49 traceStartTime
, traceEndTime
, "", stateProcess
.getType() //$NON-NLS-1$
50 .getInName(), stateProcess
.getCpu(), stateProcess
51 .getInsertion_time());
54 localProcess
.setCreationTime(stateProcess
.getCreation_time());
55 localProcess
.setPid(stateProcess
.getPid());
56 localProcess
.setTgid(stateProcess
.getTgid());
57 localProcess
.setPpid(stateProcess
.getPpid());
58 localProcess
.setName(stateProcess
.getName());
59 localProcess
.setBrand(stateProcess
.getBrand());
60 localProcess
.setTraceID(traceId
);
61 localProcess
.setProcessType(stateProcess
.getType().getInName());
62 procContainer
.addItem(localProcess
);
64 if (TraceDebug
.isCFV()) {
65 TraceDebug
.traceCFV("addLocalProcess():" + localProcess
); //$NON-NLS-1$
72 * Used to check if the event is visible within the current visible time
77 protected boolean withinViewRange(long stime
, long etime
) {
78 long windowStartTime
= params
.getStartTime();
79 long windowEndTime
= params
.getEndTime();
81 // start time is within window
82 if (stime
>= windowStartTime
&& stime
<= windowEndTime
) {
83 // The event or part of it shall be displayed.
87 // end time is within window
88 if (etime
>= windowStartTime
&& etime
<= windowEndTime
) {
89 // The event or part of it shall be displayed.
93 // check that a portion is within the window
94 if (stime
< windowStartTime
&& etime
> windowEndTime
) {
95 // The time range is bigger than the selected time window and
107 * @param localProcess
112 @SuppressWarnings("deprecation")
113 protected boolean makeDraw(LttngTraceState traceSt
, long startTime
,
114 long endTime
, TimeRangeEventProcess localProcess
,
115 ParamsUpdater params
, String stateMode
) {
117 if (TraceDebug
.isCFV()) {
118 TraceDebug
.traceCFV("makeDraw():[" + localProcess
+ //$NON-NLS-1$
119 ",candidate=[stime=" + startTime
+ //$NON-NLS-1$
120 ",etime=" + endTime
+ //$NON-NLS-1$
121 ",state=" + stateMode
+ "]]"); //$NON-NLS-1$ //$NON-NLS-2$
124 // Determine start and end times to establish duration
125 Long stime
= startTime
;
126 Long etime
= endTime
;
128 if (!withinViewRange(stime
, etime
)) {
129 // No use to process the event since it's outside
130 // the visible time range of the window
131 params
.incrementEventsDiscarded(ParamsUpdater
.OUT_OF_VIEWRANGE
);
136 // Validate the sequential order of events
137 params
.incrementEventsDiscardedWrongOrder();
141 // Store the next good time to start drawing the next event
142 // this is done this early to display an accurate start time of the
144 // within the display window
145 // ****** moved at the end since it produces gaps among the coloured rectangles
146 // localProcess.setNext_good_time(etime);
148 // If First event of a process, initialise start time half page before to enable pagination to the left
149 if (stime
< params
.getStartTime()) {
150 // event start time is before the visible time window
151 long insertion
= localProcess
.getInsertionTime();
152 if (stime
.longValue() == insertion
) {
153 // if start time is equal to insertion this is the first event to be drawn for this process
154 long halfPage
= (params
.getEndTime() - params
.getStartTime()) / 2;
155 long initTime
= params
.getStartTime() - halfPage
;
156 if (initTime
> insertion
) {
157 // start time of this event is unknown, place it half page before visible window to allow left side
158 // pagination when selecting previous event
164 // Determine if the time range event will fit it the current
166 double duration
= etime
- stime
;
167 double k
= getPixelsPerNs(traceSt
, params
);
168 double pixels
= duration
* k
;
171 // Display a "more information" indication by allowing non visible event
172 // as long as its previous event is visible.
173 boolean visible
= true;
175 boolean prevEventVisibility
= true;
176 // Get the visibility indication on previous event for
178 Vector
<TimeRangeComponent
> inMemEvents
= localProcess
180 if (inMemEvents
.size() != 0) {
181 TimeRangeComponent prevEvent
= inMemEvents
.get(inMemEvents
183 prevEventVisibility
= prevEvent
.isVisible();
185 // if previous event visibility is false and the time span
186 // between events less than two pixels, there is no need to
187 // load it in memory i.e. not visible and a more indicator is
188 // within two pixels.
189 // return i.e. event discarded to free up memory
190 Long eventSpan
= stime
- prevEvent
.getStartTime();
191 if (prevEventVisibility
== false
192 && ((double) eventSpan
* k
) < 2.0) {
195 params
.incrementEventsDiscarded(ParamsUpdater
.NOT_VISIBLE
);
201 // if previous event is visible, set this one to not
202 // visible and continue
206 // Create the time-range event
207 TimeRangeEvent time_window
= new TimeRangeEvent(stime
, etime
,
208 localProcess
, Type
.PROCESS_MODE
, stateMode
);
210 time_window
.setVisible(visible
);
211 localProcess
.getTraceEvents().add(time_window
);
212 localProcess
.setNext_good_time(etime
);
221 * @param localProcess
225 protected boolean makeDraw(LttngTraceState traceSt
, long evTime
,
226 LttngProcessState process
, TimeRangeEventProcess localProcess
,
227 ParamsUpdater params
) {
229 // TmfTimestamp stime = process.getState().getChange_LttTime();
230 long stime
= localProcess
.getNext_good_time();
233 ProcessStatus procStatus
= process
.getState().getProc_status();
234 // Use Execution mode if process state is RUN otherwise use the actual
236 // this selection will determine the actual color selected for the event
237 if (procStatus
== ProcessStatus
.LTTV_STATE_RUN
) {
238 stateMode
= process
.getState().getExec_mode().getInName();
240 stateMode
= procStatus
.getInName();
243 return makeDraw(traceSt
, stime
, evTime
, localProcess
, params
, stateMode
);