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
9 * Contributors: Alvaro Sanchez-Leon - Initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.evProcessor
;
13 import java
.util
.List
;
14 import java
.util
.Vector
;
16 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ProcessStatus
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.IEventProcessing
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngProcessState
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
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
.TimeRangeEventProcess
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEvent
.Type
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.AbsTRangeUpdate
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.ParamsUpdater
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.model
.FlowModelFactory
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.model
.FlowProcessContainer
;
29 public abstract class AbsFlowTRangeUpdate
extends AbsTRangeUpdate
implements IEventProcessing
{
31 // ========================================================================
33 // =======================================================================
35 protected FlowProcessContainer procContainer
= FlowModelFactory
.getProcContainer();
36 protected ParamsUpdater params
= FlowModelFactory
.getParamsUpdater();
37 protected static final Long ANY_CPU
= 0L;
40 // ========================================================================
42 // =======================================================================
43 protected TimeRangeEventProcess
addLocalProcess(LttngProcessState stateProcess
, long traceStartTime
, long traceEndTime
, String traceId
) {
44 // TimeRangeEventProcess localProcess = new TimeRangeEventProcess(id, name, startTime, stopTime, groupName, className);
45 TimeRangeEventProcess localProcess
= new TimeRangeEventProcess(procContainer
.bookProcId(), stateProcess
.getName(),traceStartTime
,
46 traceEndTime
, "", stateProcess
.getType().getInName(), stateProcess
.getCpu()
48 localProcess
.setCreationTime(stateProcess
.getCreation_time().getValue());
49 localProcess
.setPid(stateProcess
.getPid());
50 localProcess
.setTgid(stateProcess
.getTgid());
51 localProcess
.setPpid(stateProcess
.getPpid());
52 localProcess
.setName(stateProcess
.getName());
53 localProcess
.setBrand(stateProcess
.getBrand());
54 localProcess
.setTraceID(traceId
);
55 localProcess
.setProcessType(stateProcess
.getType().getInName());
56 procContainer
.addProcesse(localProcess
);
61 * Used to check if the event is visible within the current visible time
66 protected boolean withinViewRange(long stime
, long etime
) {
67 long windowStartTime
= params
.getStartTime();
68 long windowEndTime
= params
.getEndTime();
70 // start time is within window
71 if (stime
>= windowStartTime
&& stime
<= windowEndTime
) {
72 // The event or part of it shall be displayed.
76 // end time is within window
77 if (etime
>= windowStartTime
&& etime
<= windowEndTime
) {
78 // The event or part of it shall be displayed.
82 // check that a portion is within the window
83 if (stime
< windowStartTime
&& etime
> windowEndTime
) {
84 // The time range is bigger than the selected time window and
93 * Find the process matching the given pid and cpu
95 * If cpu is 0, the cpu value is not matched and the selection is based on
103 protected LttngProcessState
lttv_state_find_process(LttngTraceState ts
,
104 Long cpu
, Long pid
) {
105 // Define the return value
106 LttngProcessState process
= null;
108 // Obtain the list of available processes
109 List
<LttngProcessState
> processList
= ts
.getProcesses();
111 // find the process matching pid and cpu,
112 // TODO: This may need to be improved since the pid may be re-used and
113 // the creation time may need to be considered
114 for (LttngProcessState dprocess
: processList
) {
115 if (dprocess
.getPid().equals(pid
)) {
116 if (dprocess
.getCpu().equals(cpu
) || cpu
.longValue() == 0L) {
129 * @param localProcess
134 protected boolean makeDraw(LttngTraceState traceSt
, long startTime
,
135 long endTime
, TimeRangeEventProcess localProcess
,
136 ParamsUpdater params
, String stateMode
) {
138 // Determine start and end times to establish duration
139 Long stime
= startTime
;
140 Long etime
= endTime
;
143 // Validate the sequential order of events
144 params
.incrementEventsDiscardedWrongOrder();
148 if (!withinViewRange(stime
, etime
)) {
149 // No use to process the event since it's outside
150 // the visible time range of the window
151 params
.incrementEventsDiscarded();
155 // Determine if the time range event will fit it the current
157 double duration
= etime
- stime
;
158 double k
= getPixelsPerNs(traceSt
, params
);
159 double pixels
= duration
* k
;
162 // Is all this equivalent to this call in C??
163 // if(ltt_time_compare(hashed_process_data->next_good_time,evtime) > 0)
166 // Display a "more information" indication by allowing non visible event
167 // as long as its previous event is visible.
168 boolean visible
= true;
170 boolean prevEventVisibility
= true;
171 // Get the visibility indication on previous event for
173 Vector
<TimeRangeComponent
> inMemEvents
= localProcess
175 if (inMemEvents
.size() != 0) {
176 TimeRangeComponent prevEvent
= inMemEvents
.get(inMemEvents
178 prevEventVisibility
= prevEvent
.isVisible();
181 // This replace all C Call like this one ?
182 // #ifdef EXTRA_CHECK if(ltt_time_compare(evtime,
183 // time_window.start_time) == -1 || ltt_time_compare(evtime,
184 // time_window.end_time) == 1)
186 // if previous event visibility is false and the time span
187 // between events less than two pixels, there is no need to
188 // load it in memory i.e. not visible and a more indicator is
189 // within two pixels.
190 // return i.e. event discarded to free up memory
191 Long eventSpan
= stime
- prevEvent
.getStartTime();
192 if (prevEventVisibility
== false
193 && ((double) eventSpan
* k
) < 2) {
196 params
.incrementEventsDiscarded();
202 // if previous event is visible, set this one to not
203 // visible and continue
207 // Create the time-range event
209 // This should replace this C call, right?
210 // TimeWindow time_window =
211 // lttvwindow_get_time_window(control_flow_data->tab);
212 TimeRangeEvent time_window
= new TimeRangeEvent(stime
, etime
,
213 localProcess
, Type
.PROCESS_MODE
, stateMode
);
216 // This is added to replace the multiple draw and gtk/glib command but
217 // I'm not sure about it
218 time_window
.setVisible(visible
);
219 localProcess
.getTraceEvents().add(time_window
);
220 localProcess
.setNext_good_time(etime
);
223 // Missing checks like this one?
224 // #ifdef EXTRA_CHECK if(ltt_time_compare(evtime,
225 // time_window.start_time) == -1 || ltt_time_compare(evtime,
226 // time_window.end_time) == 1)
235 * @param localProcess
239 protected boolean makeDraw(LttngTraceState traceSt
, long evTime
,
240 LttngProcessState process
, TimeRangeEventProcess localProcess
,
241 ParamsUpdater params
) {
243 // TmfTimestamp stime = process.getState().getChange_LttTime();
244 long stime
= localProcess
.getNext_good_time();
247 ProcessStatus procStatus
= process
.getState().getProc_status();
248 // Use Execution mode if process state is RUN otherwise use the actual
250 // this selection will determine the actual color selected for the event
251 if (procStatus
== ProcessStatus
.LTTV_STATE_RUN
) {
252 stateMode
= process
.getState().getExec_mode().getInName();
254 stateMode
= procStatus
.getInName();
257 return makeDraw(traceSt
, stime
, evTime
, localProcess
, params
, stateMode
);