Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[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.Vector;
14
15 import org.eclipse.linuxtools.lttng.TraceDebug;
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(
46 procContainer.getUniqueId(), stateProcess.getName(),
47 traceStartTime, traceEndTime, "", stateProcess.getType()
48 .getInName(), stateProcess.getCpu(), stateProcess
49 .getInsertion_time());
50
51
52 localProcess.setCreationTime(stateProcess.getCreation_time());
53 localProcess.setPid(stateProcess.getPid());
54 localProcess.setTgid(stateProcess.getTgid());
55 localProcess.setPpid(stateProcess.getPpid());
56 localProcess.setName(stateProcess.getName());
57 localProcess.setBrand(stateProcess.getBrand());
58 localProcess.setTraceID(traceId);
59 localProcess.setProcessType(stateProcess.getType().getInName());
60 procContainer.addProcess(localProcess);
61 return localProcess;
62 }
63
64 /**
65 * Used to check if the event is visible within the current visible time
66 * window
67 *
68 * @return
69 */
70 protected boolean withinViewRange(long stime, long etime) {
71 long windowStartTime = params.getStartTime();
72 long windowEndTime = params.getEndTime();
73
74 // start time is within window
75 if (stime >= windowStartTime && stime <= windowEndTime) {
76 // The event or part of it shall be displayed.
77 return true;
78 }
79
80 // end time is within window
81 if (etime >= windowStartTime && etime <= windowEndTime) {
82 // The event or part of it shall be displayed.
83 return true;
84 }
85
86 // check that a portion is within the window
87 if (stime < windowStartTime && etime > windowEndTime) {
88 // The time range is bigger than the selected time window and
89 // crosses it
90 return true;
91 }
92
93 return false;
94 }
95
96 /**
97 * @param traceSt
98 * @param startTime
99 * @param endTime
100 * @param localProcess
101 * @param params
102 * @param stateMode
103 * @return
104 */
105 protected boolean makeDraw(LttngTraceState traceSt, long startTime,
106 long endTime, TimeRangeEventProcess localProcess,
107 ParamsUpdater params, String stateMode) {
108
109 // Determine start and end times to establish duration
110 Long stime = startTime;
111 Long etime = endTime;
112
113 if (etime < stime) {
114 // Validate the sequential order of events
115 params.incrementEventsDiscardedWrongOrder();
116 return false;
117 }
118
119 if (!withinViewRange(stime, etime)) {
120 // No use to process the event since it's outside
121 // the visible time range of the window
122 params.incrementEventsDiscarded();
123 return false;
124 }
125
126 // Determine if the time range event will fit it the current
127 // pixel map
128 double duration = etime - stime;
129 double k = getPixelsPerNs(traceSt, params);
130 double pixels = duration * k;
131
132 // ***VERIFY***
133 // Is all this equivalent to this call in C??
134 // if(ltt_time_compare(hashed_process_data->next_good_time,evtime) > 0)
135 // ***
136 // Visibility check
137 // Display a "more information" indication by allowing non visible event
138 // as long as its previous event is visible.
139 boolean visible = true;
140 if (pixels < 1) {
141 boolean prevEventVisibility = true;
142 // Get the visibility indication on previous event for
143 // this process
144 Vector<TimeRangeComponent> inMemEvents = localProcess
145 .getTraceEvents();
146 if (inMemEvents.size() != 0) {
147 TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents
148 .size() - 1);
149 prevEventVisibility = prevEvent.isVisible();
150
151 // ***VERIFY***
152 // This replace all C Call like this one ?
153 // #ifdef EXTRA_CHECK if(ltt_time_compare(evtime,
154 // time_window.start_time) == -1 || ltt_time_compare(evtime,
155 // time_window.end_time) == 1)
156
157 // if previous event visibility is false and the time span
158 // between events less than two pixels, there is no need to
159 // load it in memory i.e. not visible and a more indicator is
160 // within two pixels.
161 // return i.e. event discarded to free up memory
162 Long eventSpan = stime - prevEvent.getStartTime();
163 if (prevEventVisibility == false
164 && ((double) eventSpan * k) < 2) {
165
166 // discard the item
167 params.incrementEventsDiscarded();
168 return false;
169
170 }
171 }
172
173 // if previous event is visible, set this one to not
174 // visible and continue
175 visible = false;
176 }
177
178 // Create the time-range event
179 // *** VERIFY ***
180 // This should replace this C call, right?
181 // TimeWindow time_window =
182 // lttvwindow_get_time_window(control_flow_data->tab);
183 TimeRangeEvent time_window = new TimeRangeEvent(stime, etime,
184 localProcess, Type.PROCESS_MODE, stateMode);
185
186 // *** VERIFY ***
187 // This is added to replace the multiple draw and gtk/glib command but
188 // I'm not sure about it
189 time_window.setVisible(visible);
190 localProcess.getTraceEvents().add(time_window);
191 localProcess.setNext_good_time(etime);
192
193 // *** VERIFY ***
194 // Missing checks like this one?
195 // #ifdef EXTRA_CHECK if(ltt_time_compare(evtime,
196 // time_window.start_time) == -1 || ltt_time_compare(evtime,
197 // time_window.end_time) == 1)
198
199 return false;
200 }
201
202 /**
203 * @param traceSt
204 * @param evTime
205 * @param process
206 * @param localProcess
207 * @param params
208 * @return
209 */
210 protected boolean makeDraw(LttngTraceState traceSt, long evTime,
211 LttngProcessState process, TimeRangeEventProcess localProcess,
212 ParamsUpdater params) {
213
214 // TmfTimestamp stime = process.getState().getChange_LttTime();
215 long stime = localProcess.getNext_good_time();
216
217 String stateMode;
218 ProcessStatus procStatus = process.getState().getProc_status();
219 // Use Execution mode if process state is RUN otherwise use the actual
220 // process state,
221 // this selection will determine the actual color selected for the event
222 if (procStatus == ProcessStatus.LTTV_STATE_RUN) {
223 stateMode = process.getState().getExec_mode().getInName();
224 } else {
225 stateMode = procStatus.getInName();
226 }
227
228 return makeDraw(traceSt, stime, evTime, localProcess, params, stateMode);
229
230 }
231
232 }
This page took 0.03673 seconds and 6 git commands to generate.