Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / resources / evProcessor / ResourcesBeforeUpdateHandlers.java
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 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org.eclipse.linuxtools.lttng.ui.views.resources.evProcessor;
14
15 import org.eclipse.linuxtools.lttng.core.event.LttngEvent;
16 import org.eclipse.linuxtools.lttng.core.state.StateStrings.Channels;
17 import org.eclipse.linuxtools.lttng.core.state.StateStrings.Events;
18 import org.eclipse.linuxtools.lttng.core.state.StateStrings.Fields;
19 import org.eclipse.linuxtools.lttng.core.state.evProcessor.ILttngEventProcessor;
20 import org.eclipse.linuxtools.lttng.core.state.model.LttngTraceState;
21 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource;
22 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes;
23 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
24
25 /**
26 * Creates instances of specific before state update handlers, per corresponding
27 * event.
28 *
29 * @author alvaro
30 *
31 */
32 public class ResourcesBeforeUpdateHandlers {
33
34 /**
35 * <p>
36 * Handles: LTT_EVENT_SCHED_SCHEDULE
37 * </p>
38 * Replace C function named "before_schedchange_hook" in eventhooks.c
39 * <p>
40 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID(?), LTT_FIELD_PREV_STATE
41 * (?)
42 * </p>
43 *
44 * @return
45 */
46 final ILttngEventProcessor getBeforeSchedChangeHandler() {
47 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
48
49 // @Override
50 @Override
51 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
52 // Create a time range for the cpu.
53 globalProcessBeforeExecmode(trcEvent, traceSt);
54
55 return false;
56 }
57 };
58
59 return handler;
60 }
61
62 /**
63 * <p>
64 * Handles: LTT_EVENT_IRQ_ENTRY, LTT_EVENT_IRQ_EXIT
65 * </p>
66 * Replace C function named "before_execmode_hook_irq" in eventhooks.c
67 *
68 * @return
69 */
70 final ILttngEventProcessor getBeforeExecutionModeIrq() {
71 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
72
73 // @Override
74 @Override
75 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
76
77 Long irqId = null;
78
79 // According to Ltt, we should not draw anything if the channel
80 // is the kernel one
81 if (trcEvent.getChannelName().equals(
82 Channels.LTT_CHANNEL_KERNEL)) {
83 return false;
84 } else {
85
86 if (trcEvent.getMarkerName().equals(
87 Events.LTT_EVENT_IRQ_ENTRY.getInName())) {
88 irqId = getAFieldLong(trcEvent, traceSt,
89 Fields.LTT_FIELD_IRQ_ID);
90 } else if (trcEvent.getMarkerName().equals(
91 Events.LTT_EVENT_IRQ_EXIT.getInName())) {
92 long cpu = trcEvent.getCpuId();
93 irqId = traceSt.getCpu_states().get(cpu)
94 .peekFromIrqStack();
95 if (irqId.equals(-1L)) {
96 // nothing to update
97 return false;
98 }
99 }
100
101
102 // softIrqId is the resource id here
103 TimeRangeEventResource localResource = resourcelist_obtain_irq(
104 traceSt, irqId);
105
106 // If the resource is missing in the list, add it
107 if (localResource == null) {
108 TmfTimeRange timeRange = traceSt.getContext()
109 .getTraceTimeWindow();
110 localResource = addLocalResource(timeRange
111 .getStartTime().getValue(), timeRange
112 .getEndTime().getValue(), traceSt.getTraceId(),
113 ResourceTypes.IRQ, irqId, trcEvent
114 .getTimestamp().getValue());
115 }
116
117 // get the start time
118 long stime = localResource.getNext_good_time();
119
120 // Get the resource state mode
121 String irqStateMode = localResource.getStateMode(traceSt);
122
123 // Call the makeDraw function
124 makeDraw(traceSt, stime,
125 trcEvent.getTimestamp().getValue(), localResource,
126 params, irqStateMode);
127
128 // Call the globalProcessBeforeExecmode() after, as
129 // it is needed by all
130 // getBeforeExecmode*SOMETHING*()
131 globalProcessBeforeExecmode(trcEvent, traceSt);
132 }
133 return false;
134 }
135 };
136
137 return handler;
138 }
139
140 /**
141 * <p>
142 * Handles: LTT_EVENT_SOFT_IRQ_RAISE, LTT_EVENT_SOFT_IRQ_ENTRY,
143 * LTT_EVENT_SOFT_IRQ_EXIT,
144 * </p>
145 * Replace C function named "before_execmode_hook_soft_irq" in eventhooks.c
146 * <p>
147 * Fields: LTT_FIELD_SOFT_IRQ_ID
148 * </p>
149 *
150 * @return
151 */
152 final ILttngEventProcessor getBeforeExecutionModeSoftIrq() {
153 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
154
155 // @Override
156 @Override
157 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
158
159 Long softIrqId = null;
160
161 // According to Ltt, we should not draw anything if the channel
162 // is the kernel one
163 if (trcEvent.getChannelName().equals(
164 Channels.LTT_CHANNEL_KERNEL)) {
165 return false;
166 } else {
167
168 if ((trcEvent.getMarkerName()
169 .equals(Events.LTT_EVENT_SOFT_IRQ_RAISE.getInName()))
170 || (trcEvent.getMarkerName()
171 .equals(Events.LTT_EVENT_SOFT_IRQ_ENTRY
172 .getInName()))) {
173 softIrqId = getAFieldLong(trcEvent, traceSt,
174 Fields.LTT_FIELD_SOFT_IRQ_ID);
175 } else if (trcEvent.getMarkerName().equals(
176 Events.LTT_EVENT_SOFT_IRQ_EXIT.getInName())) {
177 long cpu = trcEvent.getCpuId();
178 softIrqId = traceSt.getCpu_states().get(cpu)
179 .peekFromSoftIrqStack();
180 if (softIrqId < 0) {
181 // nothing to update
182 return false;
183 }
184 }
185
186 // Add the resource to the resource list
187 // softIrqId is the resource id here
188 TimeRangeEventResource localResource = resourcelist_obtain_soft_irq(
189 traceSt, softIrqId);
190
191 // If the resource is missing in the list, add it
192 if (localResource == null) {
193 TmfTimeRange timeRange = traceSt.getContext()
194 .getTraceTimeWindow();
195 localResource = addLocalResource(timeRange
196 .getStartTime().getValue(), timeRange
197 .getEndTime().getValue(), traceSt.getTraceId(),
198 ResourceTypes.SOFT_IRQ, softIrqId, trcEvent
199 .getTimestamp().getValue());
200 }
201
202 // get the start time
203 long stime = localResource.getNext_good_time();
204
205 // Get the resource state mode
206 String softIrqStateMode = localResource
207 .getStateMode(traceSt);
208
209 // Call the makeDraw function
210 makeDraw(traceSt, stime,
211 trcEvent.getTimestamp().getValue(), localResource,
212 params, softIrqStateMode);
213
214 // Call the globalProcessBeforeExecmode() after, as
215 // it is needed by all
216 // getBeforeExecmode*SOMETHING*()
217 globalProcessBeforeExecmode(trcEvent, traceSt);
218
219 }
220
221 return false;
222 }
223 };
224
225 return handler;
226 }
227
228 /**
229 * <p>
230 * Handles: LTT_EVENT_TRAP_ENTRY, LTT_EVENT_TRAP_EXIT,
231 * LTT_EVENT_PAGE_FAULT_ENTRY, LTT_EVENT_PAGE_FAULT_EXIT,
232 * LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
233 * </p>
234 * Replace C function named "before_execmode_hook_trap" in eventhooks.c
235 * <p>
236 * Fields: LTT_FIELD_TRAP_ID
237 * </p>
238 *
239 * @return
240 */
241 final ILttngEventProcessor getBeforeExecutionModeTrap() {
242 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
243
244 // @Override
245 @Override
246 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
247
248 Long trapId = null;
249
250 // According to Ltt, we should not draw anything if the channel
251 // is the kernel one
252 if (trcEvent.getChannelName().equals(
253 Channels.LTT_CHANNEL_KERNEL)) {
254 return false;
255 } else {
256
257 if ((trcEvent.getMarkerName()
258 .equals(Events.LTT_EVENT_TRAP_ENTRY.getInName()))
259 || (trcEvent.getMarkerName()
260 .equals(Events.LTT_EVENT_PAGE_FAULT_ENTRY
261 .getInName()))
262 || (trcEvent.getMarkerName()
263 .equals(Events.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
264 .getInName()))) {
265 trapId = getAFieldLong(trcEvent, traceSt,
266 Fields.LTT_FIELD_TRAP_ID);
267 } else if ((trcEvent.getMarkerName()
268 .equals(Events.LTT_EVENT_TRAP_EXIT.getInName()))
269 || (trcEvent.getMarkerName()
270 .equals(Events.LTT_EVENT_PAGE_FAULT_EXIT
271 .getInName()))
272 || (trcEvent.getMarkerName()
273 .equals(Events.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
274 .getInName()))) {
275 long cpu = trcEvent.getCpuId();
276 trapId = traceSt.getCpu_states().get(cpu)
277 .peekFromTrapStack();
278
279 if (trapId.equals(-1L)) {
280 // Nothing to update
281 return false;
282 }
283 } else {
284 return false;
285 }
286
287 // Add the resource to the resource list
288 // trapId is the resource id here
289 TimeRangeEventResource localResource = resourcelist_obtain_trap(
290 traceSt, trapId);
291
292 // If the resource is missing in the list, add it
293 if (localResource == null) {
294 TmfTimeRange timeRange = traceSt.getContext()
295 .getTraceTimeWindow();
296 localResource = addLocalResource(timeRange
297 .getStartTime().getValue(), timeRange
298 .getEndTime().getValue(), traceSt.getTraceId(),
299 ResourceTypes.TRAP, trapId, trcEvent
300 .getTimestamp().getValue());
301 }
302
303 // Determine the trap state.
304 String trapStateMode = localResource.getStateMode(traceSt);
305
306 long stime = localResource.getNext_good_time();
307 makeDraw(traceSt, stime,
308 trcEvent.getTimestamp().getValue(), localResource,
309 params, trapStateMode);
310
311 // Call the globalProcessBeforeExecmode() after, as
312 // it is needed by all
313 // getBeforeExecmode*SOMETHING*()
314 globalProcessBeforeExecmode(trcEvent, traceSt);
315
316 }
317
318 return false;
319 }
320 };
321
322 return handler;
323 }
324
325 /**
326 * <p>
327 * Handles: LTT_EVENT_REQUEST_ISSUE, LTT_EVENT_REQUEST_COMPLETE
328 * </p>
329 * Replace C function named "before_bdev_event_hook" in eventhooks.c
330 * <p>
331 * Fields: LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION (?)
332 * </p>
333 *
334 * @return
335 */
336 final ILttngEventProcessor getBeforeBdevEvent() {
337 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
338
339 // @Override
340 @Override
341 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
342 Long major = getAFieldLong(trcEvent, traceSt,
343 Fields.LTT_FIELD_MAJOR);
344 Long minor = getAFieldLong(trcEvent, traceSt,
345 Fields.LTT_FIELD_MINOR);
346 // This is useless even in LTTv!
347 // Long oper = getAFieldLong(trcEvent, traceSt,
348 // Fields.LTT_FIELD_OPERATION);
349
350 Long bdevId = getMkdevId(major, minor);
351
352 // According to Lttv, bdevId (obtain from MKDEV macro) is
353 // the id here
354 TimeRangeEventResource localResource = resourcelist_obtain_bdev(
355 traceSt, bdevId);
356
357 if (localResource == null) {
358 TmfTimeRange timeRange = traceSt.getContext()
359 .getTraceTimeWindow();
360 localResource = addLocalResource(timeRange.getStartTime()
361 .getValue(), timeRange.getEndTime().getValue(),
362 traceSt.getTraceId(), ResourceTypes.BDEV, bdevId,
363 trcEvent.getTimestamp().getValue());
364 }
365
366 // get the start time
367 long stime = localResource.getNext_good_time();
368 // Get the resource state mode
369 String bdevStateMode = localResource.getStateMode(traceSt);
370 // Call the makeDraw function
371 makeDraw(traceSt, stime, trcEvent.getTimestamp().getValue(),
372 localResource, params, bdevStateMode);
373
374 return false;
375 }
376 };
377
378 return handler;
379 }
380 }
This page took 0.088206 seconds and 5 git commands to generate.