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