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