[290968] Contribution
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / evProcessor / AbsFlowTRangeUpdate.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors: Alvaro Sanchez-Leon - Initial implementation
10 *******************************************************************************/
11 package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor;
12
13 import java.util.List;
14 import java.util.Vector;
15
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;
28
29 public abstract class AbsFlowTRangeUpdate extends AbsTRangeUpdate implements IEventProcessing {
30
31 // ========================================================================
32 // Data
33 // =======================================================================
34
35 protected FlowProcessContainer procContainer = FlowModelFactory.getProcContainer();
36 protected ParamsUpdater params = FlowModelFactory.getParamsUpdater();
37 protected static final Long ANY_CPU = 0L;
38
39
40 // ========================================================================
41 // Methods
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()
47 );
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);
57 return localProcess;
58 }
59
60 /**
61 * Used to check if the event is visible within the current visible time
62 * window
63 *
64 * @return
65 */
66 protected boolean withinViewRange(long stime, long etime) {
67 long windowStartTime = params.getStartTime();
68 long windowEndTime = params.getEndTime();
69
70 // start time is within window
71 if (stime >= windowStartTime && stime <= windowEndTime) {
72 // The event or part of it shall be displayed.
73 return true;
74 }
75
76 // end time is within window
77 if (etime >= windowStartTime && etime <= windowEndTime) {
78 // The event or part of it shall be displayed.
79 return true;
80 }
81
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
85 // crosses it
86 return true;
87 }
88
89 return false;
90 }
91
92 /**
93 * Find the process matching the given pid and cpu
94 *
95 * If cpu is 0, the cpu value is not matched and the selection is based on
96 * pid value only
97 *
98 * @param ts
99 * @param cpu
100 * @param pid
101 * @return
102 */
103 protected LttngProcessState lttv_state_find_process(LttngTraceState ts,
104 Long cpu, Long pid) {
105 // Define the return value
106 LttngProcessState process = null;
107
108 // Obtain the list of available processes
109 List<LttngProcessState> processList = ts.getProcesses();
110
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) {
117 return dprocess;
118 }
119 }
120 }
121
122 return process;
123 }
124
125 /**
126 * @param traceSt
127 * @param startTime
128 * @param endTime
129 * @param localProcess
130 * @param params
131 * @param stateMode
132 * @return
133 */
134 protected boolean makeDraw(LttngTraceState traceSt, long startTime,
135 long endTime, TimeRangeEventProcess localProcess,
136 ParamsUpdater params, String stateMode) {
137
138 // Determine start and end times to establish duration
139 Long stime = startTime;
140 Long etime = endTime;
141
142 if (etime < stime) {
143 // Validate the sequential order of events
144 params.incrementEventsDiscardedWrongOrder();
145 return false;
146 }
147
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();
152 return false;
153 }
154
155 // Determine if the time range event will fit it the current
156 // pixel map
157 double duration = etime - stime;
158 double k = getPixelsPerNs(traceSt, params);
159 double pixels = duration * k;
160
161 // ***VERIFY***
162 // Is all this equivalent to this call in C??
163 // if(ltt_time_compare(hashed_process_data->next_good_time,evtime) > 0)
164 // ***
165 // Visibility check
166 // Display a "more information" indication by allowing non visible event
167 // as long as its previous event is visible.
168 boolean visible = true;
169 if (pixels < 1) {
170 boolean prevEventVisibility = true;
171 // Get the visibility indication on previous event for
172 // this process
173 Vector<TimeRangeComponent> inMemEvents = localProcess
174 .getTraceEvents();
175 if (inMemEvents.size() != 0) {
176 TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents
177 .size() - 1);
178 prevEventVisibility = prevEvent.isVisible();
179
180 // ***VERIFY***
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)
185
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) {
194
195 // discard the item
196 params.incrementEventsDiscarded();
197 return false;
198
199 }
200 }
201
202 // if previous event is visible, set this one to not
203 // visible and continue
204 visible = false;
205 }
206
207 // Create the time-range event
208 // *** VERIFY ***
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);
214
215 // *** VERIFY ***
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);
221
222 // *** VERIFY ***
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)
227
228 return false;
229 }
230
231 /**
232 * @param traceSt
233 * @param evTime
234 * @param process
235 * @param localProcess
236 * @param params
237 * @return
238 */
239 protected boolean makeDraw(LttngTraceState traceSt, long evTime,
240 LttngProcessState process, TimeRangeEventProcess localProcess,
241 ParamsUpdater params) {
242
243 // TmfTimestamp stime = process.getState().getChange_LttTime();
244 long stime = localProcess.getNext_good_time();
245
246 String stateMode;
247 ProcessStatus procStatus = process.getState().getProc_status();
248 // Use Execution mode if process state is RUN otherwise use the actual
249 // process state,
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();
253 } else {
254 stateMode = procStatus.getInName();
255 }
256
257 return makeDraw(traceSt, stime, evTime, localProcess, params, stateMode);
258
259 }
260
261 }
This page took 0.036454 seconds and 5 git commands to generate.