Changed default behavior about parsing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / resources / evProcessor / AbsResourcesTRangeUpdate.java
CommitLineData
6e512b93
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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:
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.resources.evProcessor;
13
14import java.util.Vector;
15
16import org.eclipse.linuxtools.lttng.event.LttngEvent;
8035003b 17import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing;
6e512b93 18import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
6e512b93
ASL
19import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeComponent;
20import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent;
6e512b93 21import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource;
6e512b93 22import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeResourceFactory;
8035003b
ASL
23import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEvent.Type;
24import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes;
6e512b93
ASL
25import org.eclipse.linuxtools.lttng.ui.views.common.AbsTRangeUpdate;
26import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater;
27import org.eclipse.linuxtools.lttng.ui.views.resources.model.ResourceContainer;
28import org.eclipse.linuxtools.lttng.ui.views.resources.model.ResourceModelFactory;
29import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
30
31public abstract class AbsResourcesTRangeUpdate extends AbsTRangeUpdate
8035003b 32 implements IEventProcessing {
6e512b93
ASL
33
34 // ========================================================================
35 // Data
36 // =======================================================================
37 protected ResourceContainer resContainer = ResourceModelFactory
38 .getResourceContainer();
39 protected ParamsUpdater params = ResourceModelFactory.getParamsUpdater();
40 protected static final Long ANY_CPU = 0L;
41
42 // ========================================================================
43 // Methods
44 // =======================================================================
45 protected TimeRangeEventResource addLocalResource(long traceStartTime,
63eecb47
FC
46 long traceEndTime, String traceId, ResourceTypes type, Long resId,
47 long insertionTime) {
6e512b93
ASL
48
49 String resourceName = type.toString() + " " + resId.toString();
50 // Note : the "traceid" here is assigned to the "groupname" as we group
51 // by trace in the UI
52 TimeRangeEventResource localRessource = TimeRangeResourceFactory
63eecb47
FC
53 .getInstance().createResource(resContainer.getUniqueId(),
54 traceStartTime, traceEndTime, resourceName, traceId,
55 "", type, resId, insertionTime);
8035003b 56 resContainer.addResource(localRessource);
6e512b93
ASL
57 return localRessource;
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
8035003b
ASL
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;
6e512b93
ASL
74 }
75
8035003b
ASL
76 // end time is within window
77 if (etime >= windowStartTime && etime <= windowEndTime) {
78 // The event or part of it shall be displayed.
6e512b93
ASL
79 return true;
80 }
81
8035003b
ASL
82 // check that a portion is within the window
83 if (stime < windowStartTime && etime > windowEndTime) {
6e512b93
ASL
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 public TimeRangeEventResource resourcelist_obtain_bdev(
93 LttngTraceState traceState, Long resourceId) {
94 return resourcelist_obtain_generic(resourceId, ResourceTypes.BDEV,
95 traceState.getTraceId());
96 }
97
98 public TimeRangeEventResource resourcelist_obtain_trap(
99 LttngTraceState traceState, Long resourceId) {
100 return resourcelist_obtain_generic(resourceId, ResourceTypes.TRAP,
101 traceState.getTraceId());
102 }
103
104 public TimeRangeEventResource resourcelist_obtain_irq(
105 LttngTraceState traceState, Long resourceId) {
106 return resourcelist_obtain_generic(resourceId, ResourceTypes.IRQ,
107 traceState.getTraceId());
108 }
109
110 public TimeRangeEventResource resourcelist_obtain_soft_irq(
111 LttngTraceState traceState, Long resourceId) {
112 return resourcelist_obtain_generic(resourceId, ResourceTypes.SOFT_IRQ,
113 traceState.getTraceId());
114 }
115
116 public TimeRangeEventResource resourcelist_obtain_cpu(
117 LttngTraceState traceState, Long resourceId) {
118 return resourcelist_obtain_generic(resourceId, ResourceTypes.CPU,
119 traceState.getTraceId());
120 }
121
122 public TimeRangeEventResource resourcelist_obtain_machine(
123 LttngTraceState traceState, Long resourceId) {
124 // *** VERIFY ***
125 // Does "UNKNOWN" make sense for "obtain_machine" ?
126 // It seems to be the only choice, thought...
127 return resourcelist_obtain_generic(resourceId, ResourceTypes.UNKNOWN,
128 traceState.getTraceId());
129 }
130
131 public TimeRangeEventResource resourcelist_obtain_generic(Long resourceId,
132 ResourceTypes resourceType, String traceId) {
8035003b 133 return resContainer.findResource(resourceId, resourceType, traceId);
6e512b93
ASL
134 }
135
136 protected boolean globalProcessBeforeExecmode(LttngEvent trcEvent,
137 LttngTraceState traceSt) {
138
139 // TODO: Implement the tracking of current resource in order ot speed up
140 // searching for the relevant resource similar to current_hash_data in
141 // the C implementation
142 // e.g.
143 // hashed_process_data =
144 // process_list->current_hash_data[trace_num][cpu];
145
146 TimeRangeEventResource localResource = resourcelist_obtain_cpu(traceSt,
147 trcEvent.getCpuId());
148 Long cpu = trcEvent.getCpuId();
149 if (localResource == null) {
8035003b 150 TmfTimeRange timeRange = traceSt.getInputDataRef()
6e512b93
ASL
151 .getTraceTimeWindow();
152 localResource = addLocalResource(timeRange.getStartTime()
153 .getValue(), timeRange.getEndTime().getValue(), traceSt
63eecb47
FC
154 .getTraceId(), ResourceTypes.CPU, cpu, trcEvent
155 .getTimestamp().getValue());
6e512b93
ASL
156 }
157
158 // get the start time
159 long stime = localResource.getNext_good_time();
160 // Get the resource state mode
63eecb47 161 String cpuStateMode = localResource.getStateMode(traceSt);
6e512b93
ASL
162 // Call the makeDraw function
163 makeDraw(traceSt, stime, trcEvent.getTimestamp().getValue(),
164 localResource, params, cpuStateMode);
165
166 return false;
167 }
168
63eecb47
FC
169 /**
170 * @param traceSt
171 * @param startTime
172 * @param endTime
173 * @param localResource
174 * @param params
175 * @param stateMode
176 * @return
177 */
8035003b
ASL
178 protected boolean makeDraw(LttngTraceState traceSt, long startTime,
179 long endTime, TimeRangeEventResource localResource,
6e512b93
ASL
180 ParamsUpdater params, String stateMode) {
181
6e512b93 182 // Check if the time range is consistent.
8035003b 183 if (endTime < startTime) {
6e512b93
ASL
184 params.incrementEventsDiscardedWrongOrder();
185 return false;
186 }
187
8035003b
ASL
188 // Determine start and end times to establish duration
189 long stime = startTime;
190 long windowEndTime = params.getEndTime();
191 long etime = endTime < windowEndTime ? endTime : windowEndTime;
192
193 if (etime < stime || !withinViewRange(stime, etime)) {
194 // No use to process the event since it's outside
195 // the visible time range of the window
196 params.incrementEventsDiscarded();
197 return false;
198 }
6e512b93
ASL
199
200 // Determine if the time range event will fit it the current
201 // pixel map
202 double duration = etime - stime;
203 double k = getPixelsPerNs(traceSt, params);
204 double pixels = duration * k;
205
8035003b
ASL
206 // ***VERIFY***
207 // Is all this equivalent to this call in C??
208 // if(ltt_time_compare(hashed_process_data->next_good_time,evtime) > 0)
209 // ***
6e512b93
ASL
210 // Visibility check
211 // Display a "more information" indication by allowing non visible event
212 // as long as its previous event is visible.
213 boolean visible = true;
214 if (pixels < 1) {
215 boolean prevEventVisibility = true;
216 // Get the visibility indication on previous event for
217 // this process
218 Vector<TimeRangeComponent> inMemEvents = localResource
219 .getTraceEvents();
220 if (inMemEvents.size() != 0) {
221 TimeRangeComponent prevEvent = inMemEvents.get(inMemEvents
222 .size() - 1);
223 prevEventVisibility = prevEvent.isVisible();
224
8035003b
ASL
225 // ***VERIFY***
226 // This replace all C Call like this one ?
227 // #ifdef EXTRA_CHECK if(ltt_time_compare(evtime,
228 // time_window.start_time) == -1 || ltt_time_compare(evtime,
229 // time_window.end_time) == 1)
230
6e512b93
ASL
231 // if previous event visibility is false and the time span
232 // between events less than two pixels, there is no need to
233 // load it in memory i.e. not visible and a more indicator is
234 // within two pixels.
235 // return i.e. event discarded to free up memory
236 Long eventSpan = stime - prevEvent.getStartTime();
237 if (prevEventVisibility == false
238 && ((double) eventSpan * k) < 2) {
239 params.incrementEventsDiscarded();
240 return false;
241 }
242 }
243
244 // if previous event is visible, set this one to not
245 // visible and continue
246 visible = false;
247 }
248
249 Type eventType = getEventType(localResource);
250 if (eventType != null) {
251 TimeRangeEvent time_window = new TimeRangeEvent(stime, etime,
252 localResource, eventType, stateMode);
253
8035003b
ASL
254 // *** VERIFY ***
255 // This is added to replace the multiple draw and gtk/glib command
256 // but
257 // I'm not sure about it
6e512b93
ASL
258 time_window.setVisible(visible);
259 localResource.addChildren(time_window);
8035003b 260 // Store the next good time to start drawing the event.
6e512b93 261 localResource.setNext_good_time(etime);
8035003b
ASL
262 // *** VERIFY ***
263 // Missing checks like this one?
264 // #ifdef EXTRA_CHECK if(ltt_time_compare(evtime,
265 // time_window.start_time) == -1 || ltt_time_compare(evtime,
266 // time_window.end_time) == 1)
6e512b93
ASL
267 }
268
269 return false;
270 }
271
272 /**
273 * Convert between resource type and timeRange event type
274 *
275 * @param resource
276 * @return
277 */
278 private Type getEventType(TimeRangeEventResource resource) {
279 // TODO: Can we merge into one type
280 ResourceTypes resType = resource.getType();
281 Type eventType = null;
282
283 switch (resType) {
284 case CPU:
285 eventType = Type.CPU_MODE;
286 break;
287 case IRQ:
288 eventType = Type.IRQ_MODE;
289 break;
290 case SOFT_IRQ:
291 eventType = Type.SOFT_IRQ_MODE;
292 break;
293 case TRAP:
294 eventType = Type.TRAP_MODE;
295 break;
296 case BDEV:
297 eventType = Type.BDEV_MODE;
298 break;
299 default:
300 eventType = Type.PROCESS_MODE;
301 break;
302 }
303
304 return eventType;
305 }
306
307}
This page took 0.0385180000000001 seconds and 5 git commands to generate.